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/18 10:43] – 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 61: | 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 75: | Line 86: | ||
# backup full | # backup full | ||
- | /* | + | /* */ |
USE WAdmIsk; | USE WAdmIsk; | ||
BACKUP DATABASE WAdmIsk TO DISK = ' | BACKUP DATABASE WAdmIsk TO DISK = ' | ||
Line 111: | 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 ===== |