Backing up my Windows workstation using restic
After I successfully configured restic backup for my Linux home lab server, I wanted to do the same for my Windows workstation.
I was going to use the existing restic repository on my Synology NAS which I created for backing up my Linux home lab server, so that the backed up data would also be included in my Synology backup. For that to work, I had to make its shared folder available over SMB protocol:
- First, I globally enabled the SMB service in Synology by navigating to the File Services page of the Control Panel. On the SMB tab, I checked Enable SMB service and clicked Apply to save the changes.
- Then I navigated to the Shared Folder page of the Control Panel, selected the restic repository shared folder and clicked Edit. On the Permissions tab of the dialog that opened, I made sure that the user I was going to use had the Read/Write permissions for the shared folder.
On my Windows computer, I then mapped the restic repository shared folder from Synology to a drive letter:
I chose the letter
R:
(it seemed appropriate for restic), selected the path to the folder on Synology and entered the credentials for my Synology user. I made sure to keep Reconnect at sign-in checked.
I installed rest using Chocolatey:
choco install restic
With the repository already being created, I set the RESTIC_REPOSITORY
and RESTIC_PASSWORD
environment variables for my user, to make restic more convenient to use.
Now, I was ready to prepare the backup script. In PowerShell, of course:
$configDir = "C:\Users\Damir\.restic"
$backupDir = "C:\Users\Damir\Temp\Backup"
$includesFile = Join-Path $configDir "includes.txt"
restic backup --tag auto --files-from $includesFile
The $includesFile
contains the folders to back up, one per line. I didn't include any forget and prune commands in the script. Since the repository is shared with my Linux home server backup, its script takes care of removing old snapshots.
To run the script daily, I'm using the Windows Task Scheduler. I created a new task with the following settings:
- Run only when user is logged on is checked on the General tab so that the mapped network drive with repository will be available.
- A daily trigger is configured on the Triggers tab.
- A Start a program action is added to the Actions tab
pwsh.exe
as the Program/script ensures that the script is run using PowerShell Core.-WindowStyle Hidden -File C:\Users\damir\.restic\backup.ps1
as the arguments, specify the script and hide the PowerShell window while it runs.
- On the Settings tab, I checked Run task as soon as possible after a scheduled start is missed. This is important because I'm not logged into my workstation the whole time, so I want the task to trigger when I log on the next time.
Restoring the files from the backup works the same as on Linux. Of course, I had to test it on Windows as well:
restic snapshots
restic ls 7d24e60f
restic restore "7d24e60f:/C/Users/damir/Obsidian/Vault/- Inbox" --target ./temp/restore
With the previous experience from Linux, I got the restic backup on Windows working even faster. The main challenge was configuring the scheduled task correctly so that it worked and also handled even the case when my computer isn't running at backup time, which happens quite often. I tend not to have it on during the night.