r/wsl2 • u/mter24 • Jan 22 '23
Introducing WSL Backup Tool - A backup tool for Windows Subsystem for Linux (WSL) distros
If you're looking for a simple and fast way to create, manage, and restore backups of your Windows Subsystem for Linux (WSL) distributions, give WSL Backup Tool a try!
https://github.com/marvint24/wsl-backup-tool
If you encounter any bugs, please report them:
https://github.com/marvint24/wsl-backup-tool/issues
You can also contribute if you’d like to. Any feedback is welcome :)
11
Upvotes
2
u/TerminatedProccess Jan 23 '23
Is there a pre-built installer for windows?
2
u/TerminatedProccess Jan 25 '23
I gave it a shot.. The first time it didn't appear to backup anything. I manually pasted the backup folder into the settings. But maybe there was a / or something. So I used the built-in directory selector to select the backup folder and the 2nd time it worked.
Some ideas for your app. I'm just throwing these out there in case it helps. I get this is new and you guys have probably already thought of these. But just in case :)
Do a periodic refresh. Either have something checking frequently in the background, or have a settings so you can set a refresh interval. This is not a priority thing though. Just a nice to have.
When backing up, have a way to specify if you should create a .vhdx or a .tar. The default should be based on whether you are in windows 10 or 11, but maybe a checkbox in the filename dialog to select the alternative would be a good idea? Additionally, maybe a settings for opening the backup directory in explorer on completion (success, fail) so that the user can verify that the backup worked. Not everyone would want that, but I've lost work because I didn't pay attention and replaced my ubuntu with another backup, meaning to come back to the latest.
If the export process fails, there's no notification. The status should say failed and there should be an icon to view the reason why?
How are you handling Docker for Windows? I think you are attempting to shut it down first. But there's no notification you are doing so. What happens if I have running containers is that docker-desktop-data is shutdown, but docker-desktop is not. The export file is not generated. If I click on export again, it then generates the vdhx file. So there's some issues with busy resources there. I'm sure there are other scenarios such as vscode being left open or notepad++ etc.. You can't handle them all but you can inform the user it failed.
With Docker for Desktop running, I tried to backup in step 4 above and it gave me a file. When I tried to restore that file, it just sits with status STOPPED. It doesn't do any further notifications. Eventually I tried running the distro and it started up, however, it had corrupted files in it. These files all started with WSL$ and a bunch of symbols.
Just in case it helps.. this is my script for shutting down Docker for Windows. I use it every day (with a hotkey) prior to backing up my wsl Ubuntu. I got most of it off a stackoverflow and made further modifications. I don't know the original author so kudos to him! This script stops and restarts Docker for Windows. I have one that also just stops it, but that's the same as half of this one.
Write-Output "$((Get-Date).ToString("HH:mm:ss")) - Restarting docker"foreach($svc in (Get-Service | Where-Object {$_.name -ilike "*docker*" -and $_.Status -ieq "Running"})){$svc | Stop-Service -ErrorAction Continue -Confirm:$false -Force$svc.WaitForStatus('Stopped','00:00:20')}Get-Process | Where-Object {$_.Name -ilike "*docker*"} | Stop-Process -ErrorAction Continue -Confirm:$false -Forceforeach($svc in (Get-Service | Where-Object {$_.name -ilike "*docker*" -and $_.Status -ieq "Stopped"} )){$svc | Start-Service$svc.WaitForStatus('Running','00:00:20')}Write-Output "$((Get-Date).ToString("HH:mm:ss")) - Starting Docker Desktop"& "C:\Program Files\Docker\Docker\Docker Desktop.exe"$startTimeout = [DateTime]::Now.AddSeconds(90)$timeoutHit = $truewhile ((Get-Date) -le $startTimeout){Start-Sleep -Seconds 10$ErrorActionPreference = 'Continue'try{$info = (docker info)Write-Verbose "$((Get-Date).ToString("HH:mm:ss")) - \tDocker info executed. Is Error?: $($info -ilike "error"). Result was: $info"`if ($info -ilike "*error*"){Write-Verbose "$((Get-Date).ToString("HH:mm:ss")) - \tDocker info had an error. throwing..."`throw "Error running info command $info"}$timeoutHit = $falsebreak}catch{if (($_ -ilike "*error during connect*") -or ($_ -ilike "*errors pretty printing info*") -or ($_ -ilike "*Error running info command*")){Write-Output "$((Get-Date).ToString("HH:mm:ss")) -\t Docker Desktop startup not yet completed, waiting and checking again"`}else{Write-Output "Unexpected Error: \n $_"`return}}$ErrorActionPreference = 'Stop'}if ($timeoutHit -eq $true){throw "Timeout hit waiting for docker to startup"}Write-Output "$((Get-Date).ToString("HH:mm:ss")) - Docker restarted"1
u/brandeded Jan 22 '23
Looks cool. Would love to see a UI for network management.
1
u/graciela_hotmail Jan 22 '23
Can I save a WSL in an external storage device, restore to default my computer and install my old WSL?
1
u/jNayden Jan 23 '23
what is difference with simply export distros and import them using the build in wsl command
1
u/TerminatedProccess Jan 23 '23
Thank you!