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/10/04 14:35] – [MSSQL. SQL administration] admin | db:mssql [2021/11/03 09:53] (current) – admin | ||
---|---|---|---|
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 126: | Line 137: | ||
</ | </ | ||
++++ | ++++ | ||
+ | |||
+ | |||
+ | ++++ --- 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 ===== | ||
<code SQL> | <code SQL> |