Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| db:mssql [2021/09/17 22:19] – [MSSQL. syncronize tables] admin | db:mssql [2021/11/03 09:53] (current) – admin | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| ===== MSSQL. Info ===== | ===== MSSQL. Info ===== | ||
| + | * https:// | ||
| + | * mssql video traning http:// | ||
| + | * https:// | ||
| * https:// | * https:// | ||
| * https:// | * https:// | ||
| - | * https:// | ||
| * https:// | * https:// | ||
| * [[https:// | * [[https:// | ||
| * mssql update pack https:// | * mssql update pack https:// | ||
| - | * mssql video traning http:// | ||
| * sp_command help https:// | * sp_command help https:// | ||
| Line 17: | Line 17: | ||
| sudo docker run -e " | sudo docker run -e " | ||
| -p 1434:1433 --name sql1 -h sql1 -v / | -p 1434:1433 --name sql1 -h sql1 -v / | ||
| + | -v / | ||
| -d mcr.microsoft.com/ | -d mcr.microsoft.com/ | ||
| </ | </ | ||
| Line 60: | Line 61: | ||
| <code SQL> | <code SQL> | ||
| -- # Backup Restore/ | -- # Backup Restore/ | ||
| + | |||
| + | -- get backup set | ||
| + | SELECT TOP 100 | ||
| + | name, | ||
| + | type, * | ||
| + | FROM | ||
| + | msdb..backupset | ||
| + | WHERE 1=1 | ||
| + | -- and database_name like ' | ||
| + | ORDER BY | ||
| + | backup_set_id DESC | ||
| -- delete database | -- delete database | ||
| Line 74: | Line 86: | ||
| # backup full | # backup full | ||
| - | /* | + | /* */ |
| USE WAdmIsk; | USE WAdmIsk; | ||
| BACKUP DATABASE WAdmIsk TO DISK = ' | BACKUP DATABASE WAdmIsk TO DISK = ' | ||
| Line 110: | Line 122: | ||
| </ | </ | ||
| ++++ | ++++ | ||
| + | |||
| + | |||
| + | ++++ --- MSSQL. turn on agent| | ||
| + | <code SQL> | ||
| + | -- Get data for mssql | ||
| + | sp_configure 'show advanced options', | ||
| + | GO | ||
| + | RECONFIGURE; | ||
| + | GO | ||
| + | sp_configure 'Agent XPs', 1; | ||
| + | GO | ||
| + | RECONFIGURE | ||
| + | GO | ||
| + | </ | ||
| + | ++++ | ||
| + | |||
| + | |||
| + | ++++ --- SCRIPT - for archive all files except ZIP| | ||
| + | <code BASH> | ||
| + | Function Zip | ||
| + | { | ||
| + | Param | ||
| + | ( | ||
| + | [string[]]$toBeZipped | ||
| + | ) | ||
| + | if ($null -eq $toBeZipped) {return} | ||
| + | $CurDir = Get-Location | ||
| + | Set-Location " | ||
| + | foreach ( $f in $toBeZipped) | ||
| + | { | ||
| + | echo " | ||
| + | | ||
| + | } | ||
| + | Set-Location $CurDir | ||
| + | } | ||
| + | |||
| + | |||
| + | Function ZipFiles | ||
| + | { | ||
| + | Param | ||
| + | ( | ||
| + | [string]$zipFile | ||
| + | , | ||
| + | [string[]]$toBeZipped | ||
| + | ) | ||
| + | $CurDir = Get-Location | ||
| + | Set-Location " | ||
| + | .\7z.exe A -tzip $zipFile $toBeZipped | Out-Null | ||
| + | Set-Location $CurDir | ||
| + | } | ||
| + | |||
| + | |||
| + | |||
| + | # Code | ||
| + | # get-childitem $path -recurse -exclude *.cs, | ||
| + | $bckpdir=$args[0] | ||
| + | if ($null -eq $bckpdir){ | ||
| + | echo " | ||
| + | exit 1 | ||
| + | } | ||
| + | |||
| + | $CheckFile = Test-Path -Path $bckpdir | ||
| + | |||
| + | |||
| + | if (!($CheckFile)) | ||
| + | echo " | ||
| + | exit 1 | ||
| + | } | ||
| + | echo " | ||
| + | |||
| + | |||
| + | |||
| + | $files = Get-ChildItem $bckpdir\*.* -exclude *.zip | Where-Object {$_.CreationTime -lt ((Get-date).adddays(+1))} | ||
| + | Zip $files | ||
| + | foreach ( $f in $files) | ||
| + | { | ||
| + | | ||
| + | { | ||
| + | | ||
| + | echo " | ||
| + | } | ||
| + | } | ||
| + | |||
| + | echo " | ||
| + | </ | ||
| + | ++++ | ||
| + | |||
| + | |||
| + | ++++ --- SCRIPT - for archive ZIP all files except last one for sort in time| | ||
| + | <code BASH> | ||
| + | Function Zip | ||
| + | { | ||
| + | Param | ||
| + | ( | ||
| + | [string[]]$toBeZipped | ||
| + | ) | ||
| + | if ($null -eq $toBeZipped) {return} | ||
| + | $CurDir = Get-Location | ||
| + | Set-Location " | ||
| + | foreach ( $f in $toBeZipped) | ||
| + | { | ||
| + | echo " | ||
| + | | ||
| + | } | ||
| + | Set-Location $CurDir | ||
| + | } | ||
| + | |||
| + | |||
| + | Function ZipFiles | ||
| + | { | ||
| + | Param | ||
| + | ( | ||
| + | [string]$zipFile | ||
| + | , | ||
| + | [string[]]$toBeZipped | ||
| + | ) | ||
| + | $CurDir = Get-Location | ||
| + | Set-Location " | ||
| + | .\7z.exe A -tzip $zipFile $toBeZipped | Out-Null | ||
| + | Set-Location $CurDir | ||
| + | } | ||
| + | |||
| + | |||
| + | |||
| + | # Code | ||
| + | # get-childitem $path -recurse -exclude *.cs, | ||
| + | $bckpdir=$args[0] | ||
| + | if ($null -eq $bckpdir){ | ||
| + | echo " | ||
| + | exit 1 | ||
| + | } | ||
| + | |||
| + | $CheckFile = Test-Path -Path $bckpdir | ||
| + | |||
| + | |||
| + | if (!($CheckFile)) | ||
| + | echo " | ||
| + | exit 1 | ||
| + | } | ||
| + | echo " | ||
| + | |||
| + | |||
| + | |||
| + | $files = Get-ChildItem $bckpdir\*.* -exclude *.zip | sort -Property CreationTime | ||
| + | |||
| + | if ($files -is [array]) | ||
| + | { | ||
| + | $files = $files[0..($files.Count - 2)] | ||
| + | Zip $files | ||
| + | foreach ( $f in $files) | ||
| + | { | ||
| + | | ||
| + | { | ||
| + | | ||
| + | echo " | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | | ||
| + | } | ||
| + | echo " | ||
| + | </ | ||
| + | ++++ | ||
| + | |||
| + | |||
| + | ++++ --- SCRIPT - clear age files in directory | | ||
| + | <code BASH> | ||
| + | $bckpdir=$args[0] | ||
| + | if ($null -eq $bckpdir){ | ||
| + | echo " | ||
| + | exit 1 | ||
| + | } | ||
| + | |||
| + | $numdays=$args[1] | ||
| + | if ($null -eq $numdays -or -not $numdays -match ' | ||
| + | echo " | ||
| + | exit 1 | ||
| + | } | ||
| + | |||
| + | |||
| + | $CheckFile = Test-Path -Path $bckpdir | ||
| + | |||
| + | |||
| + | if (!($CheckFile)) | ||
| + | echo " | ||
| + | exit 1 | ||
| + | } | ||
| + | echo " | ||
| + | |||
| + | $files = Get-ChildItem –Path $bckpdir | Where-Object {($_.CreationTime -lt (Get-Date).AddDays(-$numdays))} | ||
| + | if ($null -eq $files){ | ||
| + | echo " | ||
| + | exit 0 | ||
| + | } | ||
| + | echo $($files| Format-Table | ||
| + | $files | Remove-Item | ||
| + | </ | ||
| + | ++++ | ||
| + | |||
| + | |||
| ===== MSSQL.bulk copy to file ===== | ===== MSSQL.bulk copy to file ===== | ||
| Line 205: | Line 419: | ||
| ===== MSSQL. syncronize tables ===== | ===== MSSQL. syncronize tables ===== | ||
| + | |||
| + | ++++Check syncrhonize| | ||
| + | <code SQL> | ||
| + | |||
| + | -- Sector | ||
| + | select ' | ||
| + | year(case when c.date is null then co.date else c.date end) as year, | ||
| + | count(*) as cnt, | ||
| + | sum(case when co.id is null then 1 else 0 end) as cntForLoad | ||
| + | from ISOJ2018.dbo.cAppeal c | ||
| + | full outer join isoj.dbo.cAppeal co on co.id=c.id | ||
| + | -- where co.id is null | ||
| + | group by rollup(year(case when c.date is null then co.date else c.date end) | ||
| + | ); | ||
| + | </ | ||
| + | ++++ | ||
| + | |||
| ++++ Syncronize tables| | ++++ Syncronize tables| | ||
| <code SQL> | <code SQL> | ||