Since WSL is not Linux running on bare metal, we don’t need to do that within the distribution itself Perform any action to initiate a backup. Instead, the action is run entirely from PowerShell.
First, run the command wsl -l -v in PowerShell to print a list of all currently installed Linux distributions. It is important to know the exact name of the where the backup was created. For example, you might have "Ubuntu-22.04" instead of just "Ubuntu".
Once you have this information, the following command will export a full backup of the selected distribution. Before entering, cd into the directory where you want to save the backup. Any directory you put on the command line is the directory your backups will be saved to by default.
wsl --export (distribution) (filename.tar)
For example, a backup of Debian would look like this:
wsl --export Debian debianbackup.tar
Alternatively, you can specify the file location and filename during the export process instead of using cd into the correct directory. For example:
wsl --export Ubuntu c:\users\richard\desktop\ubuntumay27.tar
This is the backup process. The file you create now can be used on the same PC or another PC to set up an exact copy of your Linux distribution. You can do this using the import command in Powershell.
If you are exporting, there is a good chance that you will want to be able to use that backup distribution at some point . This is done in WSL using the import command.
It's a little longer than the export command because you need to specify where you want to install it and what files you want to use. The import command follows this template:
wsl --import (distribution) (install location) (file location and filename)
So using one of the example exports above, you'll end up with something like this:
wsl --import Ubuntu c:\wsl c:\users\richard\desktop\ubuntumay27.tar
After a few moments, your distribution will be installed and ready to go . The beauty of using export and import is that you can set up the same environment on multiple machines in a short period of time. Your user and password will be retained, as will anything you installed via your package manager.
If you want to confirm that it is installed correctly before closing the PowerShell window, just run wsl -l -v again and you should see the newly imported distribution.
The above is the detailed content of How to back up and restore Windows Subsystem for Linux (WSL) distributions. For more information, please follow other related articles on the PHP Chinese website!