Backing up WSL

I love using WSL – most of my daily work is done there. Almost all the rest done with cloud based tools, so the only thing I need to backup is WSL.

The problem is, my company’s backup software of choice will only handle “real” windows files. It gets quite unhappy if you ask it to backup the WSL virtual drive.

My solution: bup. While not the “latest hotness”, it was trivial to install and run. I ended up writing a wrapper script to add a “--backup” option, and default my destination.

My approach:

  1. Install bup
  2. Designate a Windows directory as a destination. I chose “%HOMEPATH%\bup
  3. Write a wrapper script, to avoid having to remember the bup options and command sequence. The important parts are:
#!/usr/bin/env bash
# wrap bup with my default location
# support my default usage

# use the WSL location of the Windows directory
export BUP_DIR="${BUP_DIR:-/c/Users/hwine/bup}"
real_bup=$(type -ap bup | tail -n +2 | head -1)

if $do_backup; then
    time "${real_bup}" index "${HOME}"
    time "${real_bup}" save -n "${HOME##*/}" "${HOME}"
    "${real_bup}" "$@"

Note that the “bup index” operation is the long pole on any backup. After a typical day’s work, the index takes about 5 minutes, and the actual backup is less than 10 seconds.