- rsync server using Windows Subsystem for Linux
- 3 Answers 3
- Installation and initial configuration
- How to run it
- How to start it automatically in the background
- Backup with rsync on Windows (WSL)
- Windows Subsystem for Linux (WSL)
- Install rsync
- Mounting an external drive
- Starting the backup
- And now?
- How to use rsync from Windows PC to remote Linux server?
- 7 Answers 7
rsync server using Windows Subsystem for Linux
Is it possible using the Windows 10 Windows Subsystem for Linux (WSL) to have a rsync server running on a Windows box? We have a linux rsync system that polls Windows boxes currently running DeltaCopy, but we occasionally have odd problems. Hoping that the ‘built-in’ WSL rsync might improve things, but don’t know how to arrange to have it run as a server.
One of the reasons to build WSL into Windows was so that users would be able to download and run pre-built Docker containers off the Docker hub right away. So why not just try it, set up docker and load one of the rsync-servers off the hub?
I am a linux user, but naive when it comes to Windows. Haven’t heard of Docker, alas. Will investigate. And on the askubuntu answer, it appears that there must be some additional rsync under WSL config going on that isn’t mentioned to get the windows-side rsync to listen, yes?
3 Answers 3
I’ve managed to have it working on my system. It’s not exactly a daemon in the sense of a Windows service but more of a background task of the current user, but it works for me.
Installation and initial configuration
I installed WSL for my user and Debian as the linux application of choice. Anyway it should work with any distribution as it only uses rsync .
On my linux home directory I’ve created two files: rsyncd.conf and secrets .
auth users = nas secrets file = /home/peter/rsyncd/secrets hosts allow = 192.168.1.5,192.168.1.11 log file = /home/peter/rsyncd/rsyncd.log port = 8730 use chroot = false read only = false [N_Almacen] path = /mnt/n/Almacen/rsyncd [N_AlmacenNB] path = /mnt/n/AlmacenNB/rsyncd
I’m using port 8730 to avoid having to run the daemon as root. That’s also the reason I’ve disabled chroot.
The secrets file contains usernames and passwords as usual.
How to run it
Finally the tricky part. How to run it?
You can test it with this command:
rsync —daemon —config=/home/peter/rsyncd/rsyncd.conf —no-detach
When you are confident that the configuration is working you can remove the —no-detach option and the command will spawn a background task. Even if you close all bash terminals the task will remain in the background.
How to start it automatically in the background
So now how to run automatically on login?
Create a windows shortcut to C:\Windows\System32\wsl.exe and append your command after that. The full command will be:
C:\Windows\System32\wsl.exe rsync —daemon —config=/home/peter/rsyncd/rsyncd.conf
Now you can put this shortcut in the startup folder for your user.
Backup with rsync on Windows (WSL)
I can’t count how many times I’ve lost files because I was too lazy to set up a proper backup. And every time, I told myself that this would not happen ever again.
At some point, I found the solution for macs and Linux computers: rsync , a tool that can synchronize the contents of two directories.
If you’re here, it’s because you’re desperately looking for a solution to run rsync on windows, so you probably know already that rsync is:
- efficient : it uses the size and modification times of the files to decide which files need to be transferred.
- easy to use: one command is enough to synchronize a whole directory
- versatile : for example, you can make backups to a remote machine, logging in as a different user.
- safe : I never had any issue with it, and you can test what rsync will do with the dry run option before doing it.
The only drawback with this perfect backup tool is that it’s not available on windows. There were a few solutions, like running rsync with cygwin. But I got some issues, for example when dealing with filenames with weird characters like the French accents.
Still, I wanted to be able to back up my precious collection of Georges Brassens, Serge Gainsbourg, and Renaud.
Another solution is to install a full Linux virtual machine on the windows host, but that’s really using a sledgehammer to crack a nut, and a complete waste of time and resources, especially disk space.
But now is the future! it’s finally possible to run a Linux distribution on Windows 10 using Windows Subsystem for Linux (WSL). And in this distribution, to run rsync.
In this post, you’ll learn how to:
- Enable WSL and install a Linux distribution of your choice
- Use rsync to back up a folder on your windows PC to another folder on a different disk on the same PC
To do this, you must have Windows 10 installed on your PC.
Windows Subsystem for Linux (WSL)
The Windows Subsystem for Linux has been introduced in Windows 10. It lets developers run GNU/Linux environment — including most command-line tools, utilities, and applications — directly on Windows, unmodified, without the overhead of a virtual machine.
It’s really easy and the documentation is great! And there is no need for plagiarism, so I won’t repeat the installation instructions here. But I just want to give you a bit of help to get started.
At some point, you will be asked to enable WSL by opening a powershell.
You can open the powershell by hitting the windows key or the start button, and by typing:
A terminal window opens. To enable WSL, you need to run powershell as an administrator. So in your powershell terminal, type:
Start-Process powershell -Verb runAs
This opens yet another powershell window where you have administrator rights. Now you can follow the instructions from microsoft .
I chose to install a Debian Linux distribution. You can do the same or choose ubuntu if you prefer, it will work as well. If you take another distro, some of my instructions below probably won’t work, but you certainly know what you’re doing.
After the initialization of your debian system , we can get started with rsync.
Install rsync
sudo apt install rsync openssh-client
Then, we’re going to test it. Create two directories:
Now, create two empty files in srcdir, and list the contents of this directory:
touch srcdir/file1 srcdir/file2 ls srcdir
To synchronize the srcdir and backup directories, type:
sending incremental file list ./ file1 file2 sent 176 bytes received 57 bytes 466.00 bytes/sec total size is 0 speedup is 0.00
Finally, list the destination directory, it contains the two files. Let’s try to remove one of the files before running rsync again:
rm srcdir/file2 rsync -av srcdir/ backup/
We see that backup still contains file2. By default, rsync will not delete anything. If you want to delete, do:
rsync -av --delete srcdir/ backup/
sending incremental file list deleting file2 sent 82 bytes received 21 bytes 206.00 bytes/sec total size is 0 speedup is 0.00
You should now have enough faith in rsync to do a backup of your data. Let’s do it!
Mounting an external drive
DISCLAIMER: before attempting to run the commands below, I strongly advise to backup your data!
I assume that you want to backup to an external drive, so first connect the drive to your PC. You should be able to see the drive in Windows Explorer. In the Linux terminal, the mounted drives are in /mnt. List them by doing:
These are the letters assigned to the partitions of my drives by Windows. C: is my system partition.
Probably, you will not find your external drive partitions here. It’s mounted by windows, but not by the Linux machine. To mount it, do the following:
- in Windows Explorer, find out which letter Windows assigned to the partition on your external drive. Let’s say it’s J:
- then, create the mount point and mount the partition
sudo mkdir /mnt/j sudo mount -t drvfs J: /mnt/j
You can now see the contents of the partition with
and you can go the root of the partition with
You can use cd to change directory and ls to list the contents of a directory.
Starting the backup
Let’s assume you want to backup C:\data\ to J:\.
Just do the following. The -a option is always needed: it’s what most people use, you can check the rsync manual for more information. The -v option gives you a verbose output. And the -n option is for dry run: nothing will happen, this is just a test. Finally, I’m using sudo because I got permission errors without it.
sudo rsync -avn /mnt/c/data/ /mnt/j/
And observe the output. If it looks good to you, rerun without the -n option.
And now?
In this post, you’ve learnt how to:
- configure WSL, the Windows Subsystem for Linux, to run a debian machine
- use rsync to back up your files to an external drive
Every time you want to do a backup, you should launch the Debian machine and run the rsync command.
It would be nice to automatize this so that the back up is done every time your start the PC. I don’t know how to do this yet, but I’ll make an article as soon as I find out.
Please let me know what you think in the comments! I’ll try and answer all questions.
And if you liked this article, you can subscribe to my mailing list to be notified of new posts (no more than one mail per week I promise.)
Learn about Data Science and Machine Learning!
You can join my mailing list for new posts and exclusive content:
How to use rsync from Windows PC to remote Linux server?
How do I use the rsync command from a local Windows 7 machine to a remote Linux server? What software is needed on the Windows 7 machine to use rsync ? The remote Linux server is using Amazon’s Linux AMI. The command rsync is already enabled on the machine and I can edit any needed access to the machine. This is for the purposes of setting up a web server on the remote machine and the editing on my local machine and keeping the files in sync. I do not want two-way access between the machines, I am only going to be editing files on my local machine and keeping them updated on the remote machine. UPDATE: I installed cygwin on my Windows 7 machine and installed the rsync package. Can someone provide the steps to set up the connection from the Windows 7 machine to the Linux server remotely? Say I want to have a folder called C:\www on my Windows machine and keep it updating \var\www on my remote machine, how do I do that? It’s not a backup per se, it updates the files that I edit with my local computer.
7 Answers 7
I have MinGW (also known as ‘Git Bash’) on Windows 7, and a batch file that runs rsync to back up files on an external drive on a remote linux computer. Here’s the batch file ( my_rsync_file.bat )
REM Changing directory. (assuming we are in G:/My Documents/My Various Things) cd ../ REM starting rsync. bash -c "rsync -avzh -P --stats --timeout=60 --exclude Downloads . 'my_remote_linux_computer@128.95.170.200:/media/my_remote_linux_computer/LaCie/My\ Documents'"
Here’s a bit of line-by-line explanation:
REM Changing directory. (assuming we are in G:/My Documents/My Various Things)
This just emits a message to remind me what’s going on.
This changes directory one level up from where the batch file is (to ‘My Documents’). The batch file is in an external drive on my Windows computer. I want to sync all of the ‘My Documents’ folder on this external drive with a folder of the same name on an external drive on my remote linux computer.
Just prints another message.
bash -c «rsync -avz -P —stats —timeout=60 —exclude Downloads . my_remote_linux_computer@128.95.155.200:/media/my_remote_linux_computer/LaCie/My\\ Documents»
bash : starts MinGW which has a built-in rsync library
-c : not sure what this does
rsync : library to sync files, comes with MinGW
-avzh : a-Archive, v-Verbose, z-Compress, h-Human-readable, these are the common options (more: http://linux.die.net/man/1/rsync)
-P : show progress for big files so I know if it’s frozen or not
—stats : show summary of how many files and bytes transferred at the end
—timeout=60 : kill it after 60 seconds if it gets stuck
—exclude omit files/directories from sync, in this case I exclude a directory called ‘Downloads’
. : indicates to sync all the contents of ‘My Documents’ (expect the specified thing to exclude in the line above)
my_remote_linux_computer : name of my remote linux computer (not it’s actual name 😉
@128.95.155.200 : the IP addres of my remote linux computer, from https://www.whatismyip.com/ (not my actual IP address 🙂
/media/my_remote_linux_computer/LaCie/My\\ Documents : the path to the directory on my remote linux computer that I want to receive the files. It’s an external drive.
Note that the space in «My Documents» is escaped with two backslashes, and the full name and directory of the remote destination is surrounded by double quote marks.
When I start double-click on the bat file I’m prompted for the password for my remote linux computer. When it completes I get some summary output and am prompted to press any key to close.