Powershell scripts to run Restic backups on Windows
PowerShell
419
123 commits
updated Feb 21, 2025
Powershell scripts to run Restic backups on Windows. Simplifies the process of installation and running daily backups.
install.ps1 script downloads Restic, initializes the restic repository, and setups up a Windows Task Scheduler task to run the backup dailyupdate.ps1 script can be used to keep your scripts up to date with the latest release on GitHubbackup.ps1 script handles
C:\resticupdate.ps1 script.
cd c:\restic
update.ps1 script:
Invoke-Expression (Invoke-WebRequest -Uri "https://raw.githubusercontent.com/kmwoley/restic-windows-backup/main/update.ps1" -UseBasicParsing).Content
C:\resticC:\resticSet-ExecutionPolicy -ExecutionPolicy RemoteSigned
Unblock-File *.ps1secrets.ps1 file. The secrets file contains location and passwords for your restic repository.
secrets_sample.ps1 is an example of the secrets.ps1 file. Copy or rename this file to secrets.ps1 and edit.config.ps1 file. The config file contains the settings that control how the script runs backups, forgets snapshots, and prunes the restic repository. It's important that you configure this file to meet your needs since it will be backing up and maintaining your repository.
config_sample.ps1 contins an example configuration file. Copy or rename this file to config.ps1 and edit to suit your needs.$BackupSources to config.ps1
C:\ will be backed up. You can add multiple root drives to be backed up. And you can define only specific folders you would like backed up.$BackupSources["MY BOOK"]=@(). It is recommended to use the device serial number to identify external drives to backup, which you can find using the Powershell get-disk command. You may also want to set $IgnoreMissingBackupSources=$true to avoid seeing errors when the removable drive is not present.config.ps1.
$SnapshotRetentionPolicy settings to be sure this script does not intentionally destroy backup data in your repository.install.ps1 file
.\install.ps1local.exclude
local.excludeC:\restic\restic.exe to the Windows Defender / Virus & Threat Detection Exclude list
. .\config.ps1; . .\secrets.ps1 you can then easily invoke restic commands like
& $ResticExe find -i "*filename*"& $ResticExe restore ...Use update.ps1 to update the installed restic-windows-backup scripts to the latest release.
c:\restic)update.ps1update.ps1 DetailsRunning update.ps1 without any parameters will check for a new release from kmwoley/restic-windows-backup. If there is a newer release, the script will overwrite the local files in the script directory with the updated scripts.
config.ps1 or secrets.ps1).update.ps1 is run the first time, it will prompt before overwriting (since it may not know the current version of the fiels installed).update.ps1 Options-Mode <release | branch> (Default: release) - change if the script updates from the latest release or a branch of kmwoley/restic-windows-backup-Branch <branch> (Default: 'main') - When in branch mode, this parameter controls which branch to install from. Defaults to the main branch.-InstallPath <directory> - choose which directory to install the files into. Defaults to the directory that update.ps1 is in.You can use any restic repository type you like pretty easily. SFTP on Windows, however, can be particularly tricky given that these scripts execute as the SYSTEM user and need to have access to the .ssh keys. Here are some steps and tips to getting it working.
install.ps1 file is executed with your user, whereas the tasked backup will run as SYSTEM, which does not have any ssh config yet.config.ps1 and turn off the internet connection test: $InternetTestAttempts = 0 as the test does not recognize sftp addresses correctly%USERPROFILE%\.ssh to %WINDIR%\System32\config\systemprofile\.ssh (This is the ssh config the SYSTEM account uses)This should get you up and running. If not, download PsExec, start a powershell as admin user and run .\PsExec.exe -s -i powershell.exe. In this shell you will be the system user and you can try things out. See what ssh user@server says or try cd C:\restic\; . .\config.ps1; . .\secrets.ps1; & $ResticExe check (If you get lock errors, remember to check the Task Scheduler for any running restic instances in the background)
Feel free to open issues or create PRs!
PowerShell
100.0%
Powershell scripts to run Restic backups on Windows
PowerShell
419
123 commits
updated Feb 21, 2025
Powershell scripts to run Restic backups on Windows. Simplifies the process of installation and running daily backups.
install.ps1 script downloads Restic, initializes the restic repository, and setups up a Windows Task Scheduler task to run the backup dailyupdate.ps1 script can be used to keep your scripts up to date with the latest release on GitHubbackup.ps1 script handles
C:\resticupdate.ps1 script.
cd c:\restic
update.ps1 script:
Invoke-Expression (Invoke-WebRequest -Uri "https://raw.githubusercontent.com/kmwoley/restic-windows-backup/main/update.ps1" -UseBasicParsing).Content
C:\resticC:\resticSet-ExecutionPolicy -ExecutionPolicy RemoteSigned
Unblock-File *.ps1secrets.ps1 file. The secrets file contains location and passwords for your restic repository.
secrets_sample.ps1 is an example of the secrets.ps1 file. Copy or rename this file to secrets.ps1 and edit.config.ps1 file. The config file contains the settings that control how the script runs backups, forgets snapshots, and prunes the restic repository. It's important that you configure this file to meet your needs since it will be backing up and maintaining your repository.
config_sample.ps1 contins an example configuration file. Copy or rename this file to config.ps1 and edit to suit your needs.$BackupSources to config.ps1
C:\ will be backed up. You can add multiple root drives to be backed up. And you can define only specific folders you would like backed up.$BackupSources["MY BOOK"]=@(). It is recommended to use the device serial number to identify external drives to backup, which you can find using the Powershell get-disk command. You may also want to set $IgnoreMissingBackupSources=$true to avoid seeing errors when the removable drive is not present.config.ps1.
$SnapshotRetentionPolicy settings to be sure this script does not intentionally destroy backup data in your repository.install.ps1 file
.\install.ps1local.exclude
local.excludeC:\restic\restic.exe to the Windows Defender / Virus & Threat Detection Exclude list
. .\config.ps1; . .\secrets.ps1 you can then easily invoke restic commands like
& $ResticExe find -i "*filename*"& $ResticExe restore ...Use update.ps1 to update the installed restic-windows-backup scripts to the latest release.
c:\restic)update.ps1update.ps1 DetailsRunning update.ps1 without any parameters will check for a new release from kmwoley/restic-windows-backup. If there is a newer release, the script will overwrite the local files in the script directory with the updated scripts.
config.ps1 or secrets.ps1).update.ps1 is run the first time, it will prompt before overwriting (since it may not know the current version of the fiels installed).update.ps1 Options-Mode <release | branch> (Default: release) - change if the script updates from the latest release or a branch of kmwoley/restic-windows-backup-Branch <branch> (Default: 'main') - When in branch mode, this parameter controls which branch to install from. Defaults to the main branch.-InstallPath <directory> - choose which directory to install the files into. Defaults to the directory that update.ps1 is in.You can use any restic repository type you like pretty easily. SFTP on Windows, however, can be particularly tricky given that these scripts execute as the SYSTEM user and need to have access to the .ssh keys. Here are some steps and tips to getting it working.
install.ps1 file is executed with your user, whereas the tasked backup will run as SYSTEM, which does not have any ssh config yet.config.ps1 and turn off the internet connection test: $InternetTestAttempts = 0 as the test does not recognize sftp addresses correctly%USERPROFILE%\.ssh to %WINDIR%\System32\config\systemprofile\.ssh (This is the ssh config the SYSTEM account uses)This should get you up and running. If not, download PsExec, start a powershell as admin user and run .\PsExec.exe -s -i powershell.exe. In this shell you will be the system user and you can try things out. See what ssh user@server says or try cd C:\restic\; . .\config.ps1; . .\secrets.ps1; & $ResticExe check (If you get lock errors, remember to check the Task Scheduler for any running restic instances in the background)
Feel free to open issues or create PRs!
PowerShell
100.0%