Skip to content

Instantly share code, notes, and snippets.

@Bandit
Last active December 27, 2024 04:41
Show Gist options
  • Save Bandit/342402dbd5f8307bc8d9c93f67d060c3 to your computer and use it in GitHub Desktop.
Save Bandit/342402dbd5f8307bc8d9c93f67d060c3 to your computer and use it in GitHub Desktop.
Scheduled WSL Backup Batch Script for Windows
REM Requires 7zip or NanaZip to be installed
@echo off
set datestamp=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%
cd C:\WSL-Backup
echo "Exporting WSL image..."
wsl --export Ubuntu-20.04 .\Ubuntu-20.04.tar
echo "Zipping WSL export..."
7z a -mx6 .\Ubuntu-20.04-%datestamp%.7z .\Ubuntu-20.04.tar
echo "Deleting WSL export..."
del /q .\Ubuntu-20.04.tar
echo "Deleting older exports..."
forfiles /m *.7z /d -1 /c "cmd /c del @path"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment