Status: Open
Priority: Medium
Component: tools/wsl-manager/wsl-manager.ps1, lib/wsl/ops.ps1, lib/wsl/commands.ps1
Summary: As a WSL manager user, I want to export a distribution to a tar file and import a distribution from a tar file so that I can create backups, share environments with colleagues, and reuse pre-configured distributions across machines.
Description:
The existing clone command already uses wsl.exe --export and wsl.exe --import internally but treats the tar file as a transient artefact that is deleted after the clone completes. This item adds two new top-level commands - export and import - that let the user choose the file path explicitly.
- Backup: export a distro before a risky operation, re-import if something goes wrong
- Sharing: export a fully configured distro, share the tar file with a team member who imports it
- Reuse: maintain a library of golden images (e.g.
dev-base.tar) and import on demand
wsl-manager export <DistroName> [<FilePath>]
wsl-manager import <DistroName> <FilePath> [<InstallPath>]
| Parameter | Required | Description |
|---|---|---|
DistroName |
yes (prompt if missing) | Name of the distribution to export |
FilePath |
no | Destination tar file. Default: $HOME\wsl-exports\<DistroName>_<timestamp>.tar |
- The source distribution must be stopped before export (same guard as
clone) - If the target file already exists, prompt for overwrite confirmation
- Print the resulting file path and size on success
| Parameter | Required | Description |
|---|---|---|
DistroName |
yes (prompt if missing) | Name for the imported distribution (must not already exist) |
FilePath |
yes (prompt if missing) | Path to the tar file to import |
InstallPath |
no | Where to store the imported distro's vhdx. Default: same logic as clone ($env:LOCALAPPDATA\wsl\<DistroName> or $env:WSL_INSTALL_PATH\<DistroName>) |
- Validate that the tar file exists before calling
wsl.exe --import - Reject if a distribution with the same name already exists
- Set the imported distro to WSL 2 (
wsl.exe --set-version <name> 2) if it isn't already
- Reuse the existing termination guard from
clone(Stop-WslDistro/ running-state check) - Reuse the
$env:WSL_INSTALL_PATH/ default-path logic already inInvoke-CloneDistro - Add
exportandimporttoValidateSet,Invoke-WslCommanddispatcher, and interactive menu - Menu keys:
Efor export,Ifor import (verify no conflict with existing keys) - File format is always
.tar(the nativewsl.exe --exportformat) - No compression (gzip/zstd) in initial scope; can be added later as an enhancement
- No progress bar in initial scope;
wsl.exedoes not expose progress, so this would require polling file size
Invoke-ExportDistroandInvoke-ImportDistroshould be added toops.ps1alongsideInvoke-CloneDistro, following the same pattern- Register both commands in
Invoke-WslCommanddispatcher incommands.ps1 - Add menu entries in
Start-InteractiveModeinmanager.ps1 - Update the
.SYNOPSIS/.DESCRIPTIONhelp text inwsl-manager.ps1 - Update
ValidateSetfor$Commandparameter
Acceptance Criteria:
-
wsl-manager export <name>exports the named distro to a tar file and prints the path -
wsl-manager export <name> <path>exports to the specified file -
wsl-manager import <name> <path>imports a tar file as a new distribution -
wsl-manager import <name> <path> <installPath>respects custom install path - Export prompts for distro name when not provided (interactive selection)
- Import prompts for distro name and file path when not provided
- Export refuses to overwrite an existing file without confirmation
- Import rejects if a distribution with the given name already exists
- Source distribution is terminated before export if running
- Interactive menu includes both new commands
- Unit tests cover success, failure, and edge cases for both commands
- All existing tests continue to pass