Hello to all my dear friends!
In this post How to Backup Windows from Linux?, I have discussed the use of Windows Subsystem for Linux to backup files from Windows machine to a Linux machine. But it had a weird permission problem. And therefore, to tackle that, I came up with a different solution.
In this post, I will discuss the second way to backup files and folders of a Windows machine from Linux using rsync tool.
Prepare Windows Machine for Backup
- See and add OpenSSH server capability. This is an optional feature which is not enabled by default. So this has to be manually added.
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
Add-WindowsCapability -Online -Name OpenSSH.Server
By default this runs OpenSSH server on port 22. Enable firewall if it does not allow the 22 port.
Run Powershell as Administrator and run:
netsh advfirewall firewall add rule name=”Open Port 22 for SSH” dir=in action=allow protocol=TCP localport=22
2. Start the service
Start-Service sshd
# Optionally, set it to turn on automatically every time:
Set-Service -Name sshd -StartupType 'Automatic'
3. Find the username of Windows machine
[System.Security.Principal.WindowsIdentity]::GetCurrent().Name
Rsync to Backup Windows from Linux
Now from your linux workstation, run the rsync command to take the backup:
rsync -auv --progress --rsync-path="wsl rsync" Lenovo@192.168.1.6:/mnt/f/ /run/media/hg/Expansion/Misc2/
WSL mounts the Windows drive under /mnt
folder.