Backing Up WSL Images
Microsoft’s WSL is interesting. I’d go as far as to say that I like it. The mistake here would be to forget that your Linux image is running under Windows, with everything this entails. Making a reliable backup of this thing proved harder than I expected.
I have Acronis True Image running on my Windows 10 laptop, doing a daily backup to a NAS share. This would’ve been perfectly sufficient for restoring any Unix or Linux system. Windows is another story, however.
Simply restoring the rootfs
folder of a damaged WSL Linux image doesn’t do the trick. When you launch the image following such a restore, it will tell you that it is performing an upgrade and will exit shortly thereafter without giving you any clues as to the cause of the problem.
So here’s what I ended up doing…
Install Chocolatey
Run cmd.exe
as admin and copy the appropriate command string from here. It should be something like this:
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
Install LXRunOffline:
choco install lxrunoffline
List registered images:
cd C:\tools\lxrunoffline LxRunOffline.exe l
Export image to file:
cd C:\tools\lxrunoffline LxRunOffline.exe e -n Ubuntu -f C:\zip\Ubuntu.tar.gz
Import image from file:
cd C:\tools\lxrunoffline LxRunOffline.exe i -n UbuntuNew -f C:\zip\Ubuntu.tar.gz -d C:\Users\username\AppData\Local\Packages\UbuntuNew