Created
July 21, 2022 12:11
-
-
Save geralexgr/d5d7333abb08b741cc7d08207bedc91f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$folder_for_cleanup = "R:\files\incremental" | |
Get-ChildItem $folder_for_cleanup | Sort -Property FullName | ForEach-Object { | |
Write-Host restoring $_.FullName | |
sqlcmd -Q "RESTORE LOG [Database_Name] FROM DISK=N'$_' WITH NORECOVERY" -o R:\files\results\incrementalresult.txt; #writing a log output | |
[string]$result = Get-Content R:\files\results\incrementalresult.txt | |
if ($result.contains('terminates')) { | |
Write-Host backup is already present in the database, skipping ... | |
Remove-Item $_.FullName -Force -Confirm:$false | |
} | |
else { | |
Write-Host sucessfully restored $_.FullName | |
Remove-Item $_.FullName -Force -Confirm:$false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment