I recently switched my primary computer from a Macbook Pro to a Surface Laptop. My WordPress development environment is now primarily contained within WSL which is the Linux portion of Windows. WSL’s filesystem isn’t exposed to Windows which means my development environment is not automatically picked up by Backblaze, my personal backup solution. Here is how I fixed that.
A few projects are required to run within WSL.
Most of my development files are stored safely on the Windows side which are safely backed up via Backblaze. That said, certain files there are required to run inside of WSL for file permission sake like SSH keys and bash scripts. In order to make sure these files are covered by Backblaze they need to be synced back to windows.
Automating WSL backups to Windows with scripting.
backup-wsl.sh file and store it within your
C:\Users\<username>\Scripts\. This script using rclone to push a copy of WSL’s home directory over to
C:\tools\wsl-backup\. This can be expanded for other directories if needed. For my setup I want to grab my rclone config file, SSH keys and a bash project which are all stored within the home directory of WSL.
mkdir -p /mnt/c/tools/wsl-backup/home/ rclone sync ~/ /mnt/c/tools/wsl-backup/home/ --progress
Next add this as a daily cron job. Run
crontab -e and add the following to the bottom. This will run at 9:05am each day which is common time for my laptop to be running. See https://crontab.guru for other scheduling options.
5 9 * * * /mnt/c/Users/<username>/Scripts/backup-wsl.sh