Backing up WSL files in Windows

Hi!

I’m using Duplicati to automatically back up my Win10 files. I’m also using WSL2 , and I would like to include my Linux files into the backup, preferably without running a separate Duplicati server or another tool.

What would be the best way to do it?
I tried adding the whole WSL’s virtual disk file ext4.vhdx to the backup but WSL wouldn’t start (I guess due to the file being used by Duplicati process).
Windows provides the access to the WSL files via \wsl$\ network share, I’ll try using this. But maybe there are better options?

Thanks!
Alex

One workaround for the locked file issue is to utilize snapshot-policy. Note that it requires running Duplicati as an elevated process.

Not sure if that’s the best approach. If you can add the wsl$ “share” as a source directory it might be more efficient. I haven’t experimented with it myself as I don’t run WSL.

I was able to backup specific folders/files using the wsl$ share, but I had to enable the skip-metadata option to avoid warnings about being unable to access metadata. There were also warnings given for symlinks.

Thanks for your input! Good to know this option may work for the OP.

Hi @drwtsn32, @kaliatech! Thanks for the tips!
Using the wsl$ share seems to work, but performance is horrible (on the WSL side I think; Task Manager is showing 99% memory consumption, most of it is used by WSL’s VM).
I’ll exclude node_modules, .cache and the like from the backup and see how it goes next time.

I’d like to back up WSL in Duplicati also. How I’ve actually done it is to use the windows command line as wsl has an export capability (which is mostly relevant for WSL2 (maybe not even present for WSL1)):

wsl -l -v to list WSL instances and then from that
wsl --export Ubuntu-18.04 exportedfile.tar

Then used Duplicati to backup the exported tar file.

This process was cumbersome though.

Features that would be nice are:

  1. Ability to automatically perform similar commands so that I can select from a GUI the WSL version I want to back up while defining the backup. WSL would generate the export, back it up and then remove the temporary tar ball.
  2. I’m unsure how diffs work at the moment in Duplicati, but it would seem desirable for Duplicati to be able to do reasonably smart diffs on the tar files so that a small change in the file structure for WSL didn’t result in a completely new version of the tar ball being saved. Perhaps it could ingest the tar ball and treat it like a file system and then export likewise.
  3. The landscape may have changed since this question was first raised, but it would be nice to be able to backup and restore files/directories with POSIX permissions captured in WSL2 (so not just the whole file system). Perhaps there is a way that this can be done?

Thanks
Alastair