snippetsqlMinor
Ola Hallengren maintenance script - how can I tell a backup file is still being written to?
Viewed 0 times
scriptcanfilewrittenhallengrentellbeingmaintenancehowstill
Problem
My question is whether there is a way to identify a backup file that is still being written to. I want to copy the completed backup files to another place. By reading the backup extension, I can't differentiate completed backup files from backup files that are still being written to. Any suggestions?
Solution
You could use
It will skip over files that are currently in use.
POWERSHELL and the COPY-ITEM cmdlet. It will skip over files that are currently in use.
$ErrorActionPreference = 'SilentlyContinue' prevents errors from being displayed due to locked files.powershell.exe "$ErrorActionPreference = 'SilentlyContinue';Copy-Item 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Backup\*.bak' c:\TestOutCode Snippets
powershell.exe "$ErrorActionPreference = 'SilentlyContinue';Copy-Item 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Backup\*.bak' c:\TestOutContext
StackExchange Database Administrators Q#210929, answer score: 2
Revisions (0)
No revisions yet.