Last active
January 13, 2023 21:55
-
-
Save rstanleyhum/c4b5e561cef0cc8824e2e21b4cfc4329 to your computer and use it in GitHub Desktop.
Restic Backup Windows Volume Shadow Copy Service script taken from https://github.com/restic/restic/issues/340
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
# Windows PowerShell Script to use restic to backup files using the Volume Shadow Copy Service, allowing | |
# that are in use to be backed up. The script must be run with elevated privileges. | |
# The Volume Shadow Copy Service must be enabled for the disk volume that contains the files to be backed up. | |
# | |
# Parameters | |
$resticExe = 'C:\Users\Username\go\bin\restic.exe' | |
$resticRepository = '\\SYNOLOGY212J\backups\restic-workstation' | |
$rootVolume = "C:\" | |
# List of folders to backup, separated by commas | |
$foldersToBackup = @( | |
'Users\Username\AppData\Local\Microsoft\Outlook', | |
'Users\Username\AppData\Local\Microsoft\Microsoft SQL Server Local DB' | |
) | |
# Your Restic password should be available in the RESTIC_PASSWORD environment variable. | |
# If not uncomment the following line with the actual password | |
#$env:RESTIC_PASSWORD = "secret_password" | |
###### No need to modify anything below this line ###### | |
$ShadowPath = $rootVolume + 'shadowcopy\' | |
# Create a volume shadow copy and make it accessible | |
$s1 = (Get-WmiObject -List Win32_ShadowCopy).Create($rootVolume, "ClientAccessible") | |
$s2 = Get-WmiObject Win32_ShadowCopy | Where-Object { $_.ID -eq $s1.ShadowID } | |
$device = $s2.DeviceObject + "\" | |
# Create a symbolic link to the shadow copy | |
cmd /c mklink /d $ShadowPath "$device" | |
# Run Restic on the data files in the shadowcopy | |
ForEach ($folderToBackup in $foldersToBackup) { | |
cmd /c $resticExe backup -r $resticRepository ($ShadowPath + $folderToBackup) | |
} | |
# Delete the shadow copy and remove the symbolic link | |
$s2.Delete() | |
cmd /c rmdir $ShadowPath | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment