How to backup, restore, move, install or rename your WSL installation?

J4c0b1
3 min readOct 9, 2019

--

Now that we have the WSL installed and we already started to create some Machine Learning projects, or whatever else kind of projects in my Jupyter Lab or notebook, how about the backup of this environment ? and maybe a restore to another computer ?

If you have the windows 10 version above 1903 you can use the embedded tool wsl.exe — export and — import to do the job.

If you are bellow this versions or have any restriction from your company there are some free tools that can do the job for you.

In this article we will use lxRunOffline from the Chinese citizen code name DDoSolitary on his Github project LxRunOffline.

This is a tool that runs on Windows and we should download and expand in an appropriate directory like c:\wsl.

You can download directly from the project page https://github.com/DDoSolitary/LxRunOffline/releases

we will use the powershell to run our commands. So just open it clicking with the right button on the windows start icon.

Just move to the installed directory and run

C:\wsl> .\LxRunOffline.exe list
Ubuntu
Debian
myubuntu
ubuntu1
PS C:\wsl>

To get all installed WSL instances.

Now we are ready to run the backup process.

The WSL must be stopped so no open shells for that specific WSL that we will backup.

PS C:\wsl> .\LxRunOffline.exe export -n Ubuntu -f c:/tmp/Ubuntu.tar.gz

You should inform the WSL name and the tar file name for the backup.

When the backup is finished you can copy, move or do whatever you want with your backup file.

Lets imagine that we will use this in another machine. So we should copy to a usb drive, or the cloud (google drive, onedrive, Amazon, or any other cloud service).

In the new machine or even the same one we can restore the full WSL using this simple command.

PS C:\wsl> .\LxRunOffline.exe install -n ubuntu1 -d C:\wsl\ubuntu1 -f d:\bkp\Ubuntu.tar.gz

You should choose the install directory do you want to use.

You can check if the WSL was installed using the list command.

C:\wsl> .\LxRunOffline.exe listUbuntu
Debian
myubuntu
ubuntu1
PS C:\wsl>

Then to run your new WSL just start with this command

PS C:\wsl> .\LxRunOffline.exe run -n ubuntu1 -w$

Now we can test if our Jupyter environment is working.

$ pwd
/home/j4c0b1
$ ls
Anaconda3-5.2.0-Linux-x86_64.sh Downloads anaconda3 test
$ source activate myenv
(myenv):~$ jupyter lab
[I 13:11:31.907 LabApp] JupyterLab extension loaded from /home/j4c0b1/anaconda3/envs/myenv/lib/python3.7/site-packages/jupyterlab
[I 13:11:31.909 LabApp] JupyterLab application directory is /home/j4c0b1/anaconda3/envs/myenv/share/jupyter/lab
[I 13:11:32.307 LabApp] Serving notebooks from local directory: /home/j4c0b1
[I 13:11:32.307 LabApp] The Jupyter Notebook is running at:
[I 13:11:32.308 LabApp] http://localhost:8888/?token=c596dc99fddeb2eb96c8fe54508e409fcba9924df6dd5816
[I 13:11:32.309 LabApp] or http://127.0.0.1:8888/?token=c596dc99fddeb2eb96c8fe54508e409fcba9924df6dd5816
[I 13:11:32.309 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 13:11:32.330 LabApp] No web browser found: could not locate runnable browser.
[C 13:11:32.330 LabApp]
To access the notebook, open this file in a browser:
file:///home/j4c0b1/.local/share/jupyter/runtime/nbserver-27-open.html
Or copy and paste one of these URLs:
http://localhost:8888/?token=c596dc99fddeb2eb96c8fe54508e409fcba9924df6dd5816
or http://127.0.0.1:8888
/?token=c596dc99fddeb2eb96c8fe54508e409fcba9924df6dd5816

Don’t forget to activate the virtual environment.

And open the link in your browser.

This article is a continuation of the article Anaconda, Jupyter, Python, Windows and linux….

--

--

J4c0b1

BlockChain & Bitcoin evangelist + Business Analytics & Data Integration + Data Quality + Big Data