HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

Ola Hallengren maintenance script - how can I tell a backup file is still being written to?

Submitted by: @import:stackexchange-dba··
0
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 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:\TestOut

Code Snippets

powershell.exe "$ErrorActionPreference = 'SilentlyContinue';Copy-Item 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Backup\*.bak' c:\TestOut

Context

StackExchange Database Administrators Q#210929, answer score: 2

Revisions (0)

No revisions yet.