Backup Procedure Using WSL

Using Microsoft Windows Subsystem for Linux (WSL) to gain access to Linux command line tools within Microsoft Windows 10, I was able to create a consistent backup procedure that can be performed in Windows and Linux environments. I used SyncToy and File Checksum Integrity Verifier (FCIV) to perform backups before adopting this standard approach.

Except where noted, the following procedure can be performed in both Windows and Linux environments.

  1. Navigate to Desired Folder’s Parent.
    $ cd /mnt/c/myfolderparent
  2. Generate SHA1 Digest File.
    $ find ./myfolder -type f -exec sha1sum -b "{}" + > ~/myfolder.sha1
  3. Verify SHA1 Digest File (optional).
    $ sha1sum -c ~/myfolder.sha1


    $ sha1sum -c --quiet ~/myfolder.sha1

    Note: myfolder.sha1 contains relative paths. The above command requires execution from a directory where relative paths lead to the files desired for integrity checks.

  4. Mount Destination (optional)
    1. Create Mount Point
      $ mkdir /mnt/usbdrive
    2. Review Mount Options of Mounted Fixed Drives
      $ mount

    3. Mount Drive
      $ sudo mount -t drvfs f: /mnt/usbdrive \
      -o noatime,uid=1000,gid=1000

      This command is specific to Microsoft Windows; a similar command is available in the Linux environment. “f:” is the drive letter that Microsoft Windows assigned to the inserted USB drive in this example. Options are specified to match those highlighted above for the already mounted fixed drives.

  5. Perform Copy
    1. Dry Run
      $ rsync -n -av --delete --force --progress \
      --human-readable ./myfolder/ /mnt/usbdrive/myfolder
    2. Live Run
      $ rsync -av --delete --force --progress \
      --human-readable ./myfolder/ /mnt/usbdrive/myfolder

      The trailing ‘/’ of the source folder is important to the command’s correctness.

  6. Move Checksum File
    $ cp ~/myfolder.sha1 /mnt/usbdrive/.
  7. Verify File Integrity
    $ cd /mnt/usbdrive
    $ sha1sum -c myfolder.sha1
Questions, comments, and responses are welcomed and appreciated.

Leave a Reply