Backup live data using PowerShell, DiskShadow, and RoboCopy
Robocopy is my go-to tool for quick file-level backups. Unfortunately it doesn't deal well with locked files (live databases, pst files, etc.). In those instances I deploy another great tool - DiskShadow that allows to tap into functionality of Volume Shadow Copy Service (VSS).
This is the way it works:
- diskshadow creates a shadow copy of a volume and then mounts it as a normal physical drive.
- robocopy then does its job by copying data from that mounted virtual drive without having to worry about locked files.
- Once copying is done dishshadow deletes the shadow copy and dismounts the drive.
- PoweShell sends notification and logs to your email.
- We'll need to create 4 files:
- diskshadow_backup.conf - Main diskshadow backup file.
- diskshadow_delete_x.conf - Used only to delete abandoned X: drive.
- robocopy_backup.cmd - robocopy backup script.
- run_backup.ps1 - PowerShell script to combine everything and then send logs via email. Executed manually or via scheduled task.