Skip to content

Instantly share code, notes, and snippets.

@AleksandrHovhannisyan
Last active October 25, 2024 15:42
Show Gist options
  • Save AleksandrHovhannisyan/5a32aedaf7e71e7af6d401b9af308fa1 to your computer and use it in GitHub Desktop.
Save AleksandrHovhannisyan/5a32aedaf7e71e7af6d401b9af308fa1 to your computer and use it in GitHub Desktop.
Batch script to back up WSL distributions (Windows)
@echo off
setlocal
REM List WSL distributions and prompt user to pick one
wsl.exe --list
set /p distribution="Your WSL distributions are listed above. Enter the name of the distribution to back up: "
REM Prompt the user for backup file name
set /p outputFile="Enter the path and name of your WSL export file (e.g., E:\wsl-backups\backup.tar): "
REM Confirm the action
set /p confirmation="Run command 'wsl.exe --export %distribution% %outputFile%'? (y/N): "
REM Confirm before running
if /i "%confirmation%"=="y" (
wsl.exe --export %distribution% %outputFile%
) else (
echo Operation cancelled.
)
endlocal
pause
@AleksandrHovhannisyan
Copy link
Author

To import it, I just follow this guide: https://murrahjm.github.io/Exporting-WSL-data/

Could probably add it as an option to the script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment