Skip to content

Instantly share code, notes, and snippets.

@revans-premier-education
revans-premier-education / Backup-WSL.ps1
Created February 17, 2026 12:22
WSL2 Ubuntu Backup & Restore - PowerShell backup script, bash cleanup script, and guide
#Requires -Version 5.1
<#
.SYNOPSIS
Backs up the Ubuntu WSL2 instance to a compressed .tar.gz archive.
.DESCRIPTION
1. Checks available disk space (warns if insufficient)
2. Flushes bash history from open sessions
3. Terminates the Ubuntu WSL2 instance for filesystem consistency
4. Exports the full filesystem to a .tar file