Restoring files using restic on Windows
After suffering a drive failure I had to restore important files from my backups. Here are some of the problems I ran into and how I fixed them.
The backup strategy
I'm currently using both, Backblaze and restic to backup my PC. Normally you should follow the 3-2-1 backup strategy where you aim for three copies of your data, on two different types of media, one of them offsite. By using the aforementioned services, I have two offsite copies, allowing me to recover in case my home and one of the external services burn down.
Recovering from drive failure
Recently I suffered a drive failure, leaving me unable to boot back into Windows. Using a live-boot USB I was able to verify that I could still access the files on the hard drive, however, the drive would appear and disappear randomly, so reformatting and using the drive was not an option for me.
After purchasing a new M.2 drive, I began restoring my files, which is when I noticed my first problem:
Missing files on Backblaze
I attempted to restore my .ssh folder to gain access to some remote servers again, when I noticed that the folder was missing in my Backblaze backup. Moreover, all of the dot-directories were missing. No I haven't investigated whether that is on me due to a configuration error, or whether Backblaze simply doesn't backup those "more technical" directories, however this left me a bit disappointed in the service. I know that there is a configuration file one can use to include and exclude certain paths and I made heavy use of it to exclude file paths I deemed unnecessary to back up. So it's entirely possible I made a configuration error, I just haven't checked.
Restoring the files out of a restic snapshot
After finding out that I wouldn't be getting my .ssh directory back from my Backblaze backup, I turned to my restic backup in an attempt to restore the files from there. This is where I ran into my second problem: the restic backup configuration I published over a year ago did no longer match my actual setup, because I switched from the SFTP to the rclone backend. However, I was able to piece a restic configuration back together from the blog post. Unfortunately, the post uses a SSH configuration file and an IdentityFile I no longer had access to. Fortunately for me, creating a simple working configuration file was easy as I just had to replace some of the published placeholder values with the ones stored in my password manager, and I just removed the IdentityFile falling back to username-password authentication. After downloading restic I was able to list my snapshots using the following command: restic.exe -r sftp:restic-backup-host:/home/Backups/ snapshots --password-file="C:\Programs\restic\password.txt"
.
After picking the most recent snapshot I attempted to list the files in a specific path, which didn't work at first but after playing with the path syntax a bit, I got it working. Turns out that on windows even though the snapshot lists the directories Windows-style (C:\Programs\restic) you actually have to list the file contents unix-style (/C/Programs/restic). Armed with this knowledge, I set out to finally restore my .ssh directory with the following command: restic.exe -r sftp:restic-backup-host:/home/Backups/ restore snapshot-id-here:"/C/Users/Alex/.ssh" --password-file="C:\Programs\restic\password.txt" --target "C:\Programs\restic\backup"
.
Because I was not using the IdentityFile to authenticate, I got prompted over and over again for the host's password; a problem I thought would be fixed once I copy the restored files to my .ssh folder. But as it turns out, that wasn't the case, as the files I had recently restored didn't belong to me. I could only access the files contents when in administrator mode. After searching through forums and the internet for a bit, I finally found the solution: takeown /R /F backup
and icacls backup /T /Q /C /RESET
. The "backup" in the previous two commands references the directory I restored the files into using the restore command. Finally, after executing the commands the files belonged to my current user and I was able to open them without administrator mode again. While a bit tedious, I am glad I found a working solution.
Considerations
I learned about the importance of testing your backup strategies before you actually need them. Testing the backups would have alerted me to the missing dot-directories, the .ssh directory dependency for restic, and the permission problems beforehand. I'm probably going to review the Backblaze configuration file to see if I missconfigured something or if dot-directories are simply not being backed up by Backblaze.
Furthermore, I am also probably going to write an article (or update the existing restic one) to include my current setup. Without my post, restoring the files definitely would have taken longer. Overall I'm just glad I got my files back. At some point I'm going to check the old NVMe drive to delete the Windows boot and recovery partitions to maybe be able to use the drive for non-important temporary files.