A simple PowerShell script that automates backup tasks using Windows Shadow Copy and Robocopy, with support for rotation and progress tracking.
- Creates a Shadow Copy of a selected volume
- Uses
Robocopy
to copy only selected file types from specific directories - Supports multiple source directories
- Displays a native Windows progress bar
- Allows cancellation mid-process
- Supports backup rotation (keeps
N
previous versions) - Cleans up shadow copy and symlink after execution
- Windows OS (with Volume Shadow Copy enabled)
- PowerShell 5.1+
- Admin rights required (to use
vssadmin
andmklink
) - Robocopy (included in Windows)
Inside the script, you can modify:
$VSV = "D:" # Volume to snapshot
$DIRSOURCE = @("\data\") # Directories to back up (relative to root of volume)
$DIRDEST = "\\backup-nas\" # Destination for backups (network path or local)
$EXT = "*.db" # File types to copy (use *.* for all)
$Shortc = "shadowcopy" # Symlink name
$DELBCK = $true # Whether to delete shadow copy after run
$NBRBACKUP = 3 # How many backup folders to retain
$MTNB = 8 # Robocopy thread count
- Open PowerShell as Administrator
- Run the script:
.\shadowcopy_backup.ps1
- Backups are saved in numbered folders (
1
,2
,3
, ...) inside the target directory. - A log file is created automatically:
backup_YYYY-MM-DD_HH-MM-SS.log
If $DELBCK = $true
, the script will:
- Remove the created symlink
- Delete the shadow copy
If not, you’ll need to delete them manually using:
vssadmin delete shadows /for=D: /all /quiet
rmdir D:\shadowcopy
This script is provided under the MIT License.
Feel free to modify and adapt it for personal or professional use.
Created by orugari
Inspired by early backup batch techniques and modernized in PowerShell.