Wondering how to perform Rsync from Linux to Windows share? We can help you.
We help some of our customers with Rsync to copy files from one location to another. In the course it was found that it is fast and can also be used for mirroring data and incremental backups.
As part of our Server Management Services, we assist our customers with several Rsync queries.
Today, let us see how to transfer Rsync from Linux to Windows share.
What is Rsync?
A fast and versatile command-line utility, Rsync (Remote Sync) helps to synchronize files and directories between two locations over a remote shell, or from/to a remote Rsync daemon.
In addition, it provides fast incremental file transfer by transferring only the differences between the source and the destination.
We can use Rsync for mirroring data, incremental backups, copying files between systems. It acts as a replacement for scp, sftp, and cp commands.
Advantages and features of the Rsync command include:
- Rsync efficiently copies and sync files to or from a remote system.
- Supports copying links, devices, owners, groups, and permissions.
- It’s faster than SCP (Secure Copy) since it allows the transfer of just the differences between two sets of files.
- It consumes less bandwidth using the compression and decompression method while sending and receiving data.
Transfer Rsync from Linux to Windows share
Initially, we make a mount point:
mkdir /mnt/share
Then, we mount the smb share:
mount -t cifs -o username=domainusername //ip_add/ShareFolder /mnt/share
It will prompt for a password. It is always a good practice not to provide password within commands.
In addition, if we run the following command we can verify if it has mount:
mount //ip_add/ShareFolder on /mnt/share type cifs (rw)
Similarly, we can mount it after every boot.
In order to do that we need to add it to /etc/fstab:
//ip_add/ShareFolder /mnt/share smbfs username=domainusername,password=P@S5W0rd 0 0
Now we can Rsync data to it.
For example, to rsync bob’s home directory into a dir called ‘homedir’ we run:
rsync -avz /home/bob/ /mnt/share/homedir/
[Stuck with the transfer? We are here to help you]
Conclusion
To conclude, the transfer of Rsync from Linux to Windows share can be done in a few steps. Today, we saw the best fit suggested by our Support Engineers.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
GET STARTED
var google_conversion_label = «owonCMyG5nEQ0aD71QM»;
Synchronizing files between Linux and Windows can seem challenging, especially if you’re not familiar with the tools available. However, with the Windows Subsystem for Linux (WSL), this process becomes much simpler.
WSL allows you to run a Linux environment directly on Windows, enabling you to use powerful Linux tools like Rsync to sync files between the two operating systems.
In this article, we’ll walk you through the entire process of using Rsync to sync files between Linux and Windows using WSL. We’ll cover everything from setting up WSL to writing scripts for automated syncing.
By the end, you’ll have a clear understanding of how to efficiently manage file synchronization across these two platforms.
What is Rsync?
Rsync (short for “remote synchronization“) is a command-line tool used to synchronize files and directories between two locations, which is highly efficient because it only transfers the changes made to files, rather than copying everything every time, which makes it ideal for syncing large files or large numbers of files.
Why Use Rsync with WSL?
- WSL allows you to run Linux commands and tools directly on Windows, making it easier to use Rsync.
- Rsync only transfers the differences between files, saving time and bandwidth.
- You can sync files between a Linux machine and a Windows machine effortlessly.
- Rsync can be automated using scripts, making it perfect for regular backups or syncing tasks.
Prerequisites
Before we begin, ensure you have the following:
- WSL is supported on versions of Windows 10 and 11.
- You need to have WSL installed and set up on your Windows machine.
- Install a Linux distribution (e.g., Ubuntu) from the Microsoft Store.
- Rsync is usually pre-installed on Linux distributions, but we’ll cover how to install it if it’s not.
- Rsync uses SSH to securely transfer files between systems.
Step 1: Install and Set Up WSL
If you haven’t already installed WSL, then open PowerShell as administrator by pressing Win + X
and selecting “Windows PowerShell (Admin)” or “Command Prompt (Admin)” and run the following command to install WSL.
wsl --install
This command installs WSL and the default Linux distribution (usually Ubuntu). After installation, restart your computer to complete the setup.
Once your computer restarts, open the installed Linux distribution (e.g., Ubuntu) from the Start menu. Follow the on-screen instructions to create a user account and set a password.
Step 2: Install Rsync on WSL
Rsync is usually pre-installed on most Linux distributions. However, if it’s not installed, you can install it using the following commands.
sudo apt update sudo apt install rsync rsync --version
This should display the installed version of Rsync.
Step 3: Set Up SSH on WSL
To enable SSH on WSL, you need to install the OpenSSH server.
sudo apt install openssh-server
Next, start and enable the SSH service to start automatically every time you launch WSL.
sudo service ssh start sudo systemctl enable ssh
Verify that the SSH service is running.
sudo service ssh status
Step 4: Sync Files from Linux (WSL) to Windows
Now that Rsync and SSH are set up, you can start syncing files. Let’s say you want to sync files from your WSL environment to a directory on your Windows machine.
Launch your Linux distribution (e.g., Ubuntu) and identify the Windows directory, which typically mounted under /mnt/
. For example, your C:
drive is located at /mnt/c/
.
Now run the following command to sync files from your WSL directory to a Windows directory:
rsync -avz /path/to/source/ /mnt/c/path/to/destination/
Explanation of the command:
-a
: Archive mode (preserves permissions, timestamps, and symbolic links).-v
: Verbose mode (provides detailed output).-z
: Compresses data during transfer./path/to/source/
: The directory in your WSL environment that you want to sync./mnt/c/path/to/destination/
: The directory on your Windows machine where you want to sync the files.
Step 5: Sync Files from Windows to Linux (WSL)
If you want to sync files from a Windows directory to your WSL environment, you can use a similar command:
rsync -avz /mnt/c/path/to/source/ /path/to/destination/
Explanation of the command:
/mnt/c/path/to/source/
: The directory on your Windows machine that you want to sync.- /
path/to/destination/
: The directory in your WSL environment where you want to sync the files.
Step 6: Automate Syncing with a Script
To make syncing easier, you can create a bash script to automate the process.
nano sync.sh
Add the following lines to the script:
#!/bin/bash rsync -avz /path/to/source/ /mnt/c/path/to/destination/
Save the file and make the script executable:
chmod +x sync.sh
Execute the script to sync files.
./sync.sh
You can use cron to schedule the script to run at specific intervals. For example, to run the script every day at 2 AM, add the following line to your crontab:
0 2 * * * /path/to/sync.sh
Conclusion
Using Rsync with WSL is a powerful and efficient way to sync files between Linux and Windows. By following the steps outlined in this article, you can easily set up Rsync, configure SSH, and automate file synchronization.
Are you trying to perform Rsync from Linux to Windows share?
This guide is for you.
Rsync is a command-line utility that helps us to copy files from one location to another. We did experiments and found that it is fast. It can also be used for mirroring data and incremental backups.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform Rsync related queries.
In this context, you shall learn how to transfer Rsync from Linux to Windows share.
More information about Rsync ?
A fast and versatile command-line utility, Rsync (Remote Sync) helps to synchronize files and directories between two locations over a remote shell, or from/to a remote Rsync daemon.
In addition, it provides fast incremental file transfer by transferring only the differences between the source and the destination.
We can use Rsync for mirroring data, incremental backups, copying files between systems. It acts as a replacement for scp, sftp, and cp commands.
Benefits and features of the Rsync command include:
i. Rsync efficiently copies and sync files to or from a remote system.
ii. Supports copying links, devices, owners, groups, and permissions.
iii. It’s faster than SCP (Secure Copy) since it allows the transfer of just the differences between two sets of files.
iv. It consumes less bandwidth using the compression and decompression method while sending and receiving data.
How to transfer Rsync from Linux to Windows share ?
To get started, we make a mount point:
mkdir /mnt/share
Then, we mount the smb share:
mount -t cifs -o username=domainusername //ip_add/ShareFolder /mnt/share
It will prompt for a password. It is always a good practice not to provide password within commands.
In addition, if we run the following command we can verify if it has mount:
mount
//ip_add/ShareFolder on /mnt/share type cifs (rw)
Similarly, we can mount it after every boot.
In order to do that we need to add it to /etc/fstab:
//ip_add/ShareFolder /mnt/share smbfs username=domainusername,password=P@S5W0rd 0 0
Now we can Rsync data to it.
For example, to rsync ibmimedia’s home directory into a dir called ‘homedir’ we run:
rsync -avz /home/ibmimedia/ /mnt/share/homedir/
[Stuck with the transfer with rsync? We are here to help you. ]
This procedure may be helpful for backups of Linux VMs on the cloud. Some (most) service providers make it notoriously difficult to export VM images or snapshots out of the cloud.
While it is still possible to perform an image backup using Clonezilla, again, not all service providers allow boot on an ISO for a given VM. In these cases, a helper volume should be added to the VM and have Clonezilla installed on it, and selected as the boot device. The original boot volume would then be backed-up to an image locally on the helper volume and exported out of the cloud after the process completes. Although that is the theory, I have not tested this specific process myself. Keep in mind that some providers VM instances only support one volume attached. Also, this process is a one-shot operation, and is hardly automated, and creates downtime.
There are other block level device time consistent backup strategies you can try though if you use LVM and have space on the LVM group, it is possible to snapshot your volume, mount the snapshot, and have rsync transfer it over the network. Keep in mind that if the rsync process is initiated on the backup system rather than on the backed-up system, you’ll better have to use ssh or other remote command tools to perform snapshot creation and mount and then rsync, have a way to check for errors returned by these commands and then only initate rsync on the backup system. Then perform a post-backup remote execution to unmount the snapshot and destroy the snapshot. This whole process is a bit similar to the Windows VSS snapshot operation.
For more information about this process, check :
LVM snapshot Backup and restore on linux
If you don’t use LVM then you’ll have to resort to backups that are not time consistent (not frozen in time), but it is better than nothing. That is the object of this tutorial.
Setting up cygwin on Windows.
Download cygsetup and perform a full or a minimal install. For a minimal install, you’ll need SSH and Rsync as well as it’s dependencies.
Now you’ll have to choose between using rsync through a SSH encrypted channel, or through a rsync daemon running on the remote host to be backed up.
Using rsync through SSH for a full system backup requires a root login through SSH, and automating rsync with SSH will require a way to supply credentials automatically, unless using a public/private key non interactive (passphrase less) authentication scheme.
In the case of SSH plain password authentication, supplying it to rsync can be done through sshpass, which exists as a Cygwin package, but I have not tested it myself in conjunction with rsync
http://www.cygwin.com/packages/summary/sshpass.html
https://stackoverflow.com/questions/3299951/how-to-pass-password-automatically-for-rsync-ssh-command
However, allowing SSH password root authentication plus storing its password as cleartext in a file for sshpass to use it is a huge security risk.
At least, with a passphrase less public/private key pair, the problem amounts to securing the private key well on the filesystem. It will still be acessible (read only) in the user account context that runs the rsync/ssh script on Windows.
For all these reasons, I find it preferable to use the rsync daemon on the remote system. Which allows to use a backup account instead of root.
The downsides however are that you need to open the rsync TCP port on the remote system and configure your firewalls in the connection path accordingly; and also rsync daemon does not encrypt traffic. If it is an issue, then use a VPN or an IpSec tunnel.
Setting up the rsync daemon on linux Debian
apt-get install rsync
Edit the rsync daemon configuration file.
vi /etc/rsyncd.conf
Here is a sample of the rsyncd.conf
uid=root
gid=root
[share_system_backup]
path = /
comment = system root
read only = true
auth users = backup
secrets file = /etc/rsyncd.secrets
hosts allow = <ip_of_backup_system>
As per the rsync manpage, rsyncd runs as root, and uid and gid parameters, which can be global to all rsync shares or share specific, specify the impersonated context of the rsync access to the filesystem.
Since we’ll perform a system wide backup, we’ll use root.
auth users specify the rsync users authorized to access the share. These users are rsync specific, not system users.
read only is used since no writes will be performed on the backed up system, unless you want rsync to upload some state file on the remote system after backup, as we won’t be using SSH, that is a trick way to signal something to the backed up system, without any remote execution.
hosts_allow is useful for a cloud VM that does not have firewalling options provided by the service provider.
The user login password pair is specified in /etc/rsyncd.secrets.
vi /etc/rsyncd.secrets
backup:346qsfsgSAzet
Use a strong password.
Next start the rsync daemon, check it runs and check its socket is listening on TCP port 873.
rsync --daemon
ps-auwx | grep rsync && netstat -nlp | grep rsync
Then we’ll make rsync launch at system boot.
vi /etc/default/rsync
Change RSYNC_ENABLE to true to start the daemon at system startup through init.d
Rsync configuration on Windows
We’ll start by setting up the windows batch files that will prepare the cygwin environment and run rsync. Change <IP> with your remote system to be backed up IP or DNS name. This script assumes standard port 873
The default file is named CWRSYNC.CMD and should reside at the root of the cygwin64 base folder.
@ECHO OFF
REM *****************************************************************
REM
REM CWRSYNC.CMD - Batch file template to start your rsync command (s).
REM
REM *****************************************************************
REM Make environment variable changes local to this batch file
SETLOCAL
REM Specify where to find rsync and related files
REM Default value is the directory of this batch file
SET CWRSYNCHOME=%~dp0
REM Create a home directory for .ssh
IF NOT EXIST %CWRSYNCHOME%\home\%USERNAME%\.ssh MKDIR %CWRSYNCHOME%\home\%USERNAME%\.ssh
REM Make cwRsync home as a part of system PATH to find required DLLs
SET CWOLDPATH=%PATH%
SET PATH=%CWRSYNCHOME%\bin;%PATH%
REM Windows paths may contain a colon (:) as a part of drive designation and
REM backslashes (example c:\, g:\). However, in rsync syntax, a colon in a
REM path means searching for a remote host. Solution: use absolute path 'a la unix',
REM replace backslashes (\) with slashes (/) and put -/cygdrive/- in front of the
REM drive letter:
REM
REM Example : C:\WORK\* --> /cygdrive/c/work/*
REM
REM Example 1 - rsync recursively to a unix server with an openssh server :
REM
REM rsync -r /cygdrive/c/work/ remotehost:/home/user/work/
REM
REM Example 2 - Local rsync recursively
REM
REM rsync -r /cygdrive/c/work/ /cygdrive/d/work/doc/
REM
REM Example 3 - rsync to an rsync server recursively :
REM (Double colons?? YES!!)
REM
REM rsync -r /cygdrive/c/doc/ remotehost::module/doc
REM
REM Rsync is a very powerful tool. Please look at documentation for other options.
REM
REM ** CUSTOMIZE ** Enter your rsync command(s) here
echo "start" >> c:\scripts\rsync_sys.log
date /t >> c:\scripts\rsync_sys.log
time /t >> c:\scripts\rsync_sys.log
rsync --no-perms --itemize-changes --password-file=rsync_p -lrvcD --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/root/*"} backup@<IP>::share_system_backup/ /cygdrive/d/BACKUPS_FROM_CLOUD/SYSTEM >> c:\scripts\rsync_sys.log
date /t >> c:\scripts\rsync_sys.log
time /t >> c:\scripts\rsync_sys.log
echo "stop" >> c:\scripts\rsync_sys.log
You’ll need to add a file named rsync_p in my example that contains the password specified for the backup user, matching the password defined on the rsync daemon host. This allows non interactive execution of rsync.
Place this file at the cygwin64 base folder level.
Secure that file well at the NTFS level.
itemize-changes will log in the rsync_sys.log the file operations performed on the system. It is useful for troubleshooting.
http://www.staroceans.org/e-book/understanding-the-output-of-rsync-itemize-changes.html
The -lrvc flags tells rsync to copy symbolic link information (absolute and relative). You can test that is the case by using ls -ltra through a cygwin shell, recurse directories, be verbose, and check for changes based on checksum instead of file timestamps, which could be useful if there are timestamp discrepancies because of the cygwin environment. It is worth testing it’s effect with a test run.
Also, I excluded the standard list of directories recommended to be excluded from a system backup for Debian systems using the –exclude option.
Permissions / ACL issues
Note that I use –no-perms for rsync. That is one caveat with rsync running on cygwin, since it uses POSIX to Windows ACL translation, copying perms COULD render the files unreadable by other processes on the Windows system if permissions from the source system are preserved, On the other hand, preserving source permissions could make baremetal recovery possible. It is worth experimenting with this option.
A way to circumvent this problem when using –no-perms is to back up permissions separately on the linux system using getfacl and setfacl for restore operations. keep in mind that getfacl ouput is substantial in terms of size and getfacl does not support directory exclusions. It may involve a bit of scripting.
Example of getfacl script (backupacl.sh)
cd /home/backup
getfacl -RL /bin > filesystem_acls_bin.dat
getfacl -RL /boot > filesystem_acls_boot.dat
getfacl -RL /etc > filesystem_acls_etc.dat
getfacl -RL /home > filesystem_acls_home.dat
getfacl -RL /lib > filesystem_acls_lib.dat
getfacl -RL /lib64 > filesystem_acls_lib64.dat
getfacl -RL /media > filesystem_acls_media.dat
getfacl -RL /mnt > filesystem_acls_mnt.dat
getfacl -RL /opt > filesystem_acls_opt.dat
getfacl -L /root > filesystem_acls_root.dat
getfacl -RL /sbin > filesystem_acls_sbin.dat
getfacl -RL /snap > filesystem_acls_snap.dat
getfacl -RL /srv > filesystem_acls_srv.dat
getfacl -RL /tmp > filesystem_acls_tmp.dat
getfacl -RL /usr > filesystem_acls_usr.dat
getfacl -RL /var > filesystem_acls_var.dat
tar -czvf backup_acls.tar.gz filesystem_acls_*
rm -f filesystem_acls_*
You can use xargs and a $ placeholder plus a list of folders to backup permissions from to make this script a one-liner.
the backup_acls.tar.gz will be backed up by rsync when it runs.
In this example, ACL backups and the backup script are stored in /home/backup. As said before, backup is not necessarily a linux user since rsync maintains its own authentication database, but I use this directory for convenience.
In this script backup of /root ACLs is not recursive as a dirty way to remove the .wine directory that contains symbolic links to the whole file system, and thus would make getfacl to follow them and spend a huge useless time (and filespace) for directories such as /dev, /proc /sys. So it’s possible for you to add the recurse flag if this problem does not affect your system.
Run the batch for tests and schedule it by adding it to /etc/cron.daily/ for instance. It should run in the root context.
A note about restores and symbolic links
the rsync -l options copies symbolic links, which means thar you have to use rsync too for restore operations, Don’t expect symbolic links to magically reappear if you use WinSCP or another tool to restore a folder.
More on this subject :
https://www.baeldung.com/linux/rsync-copy-symlinks
Testing the backup.
Edit the cwrsync.cmd to add the dry-run option, run the cwrsync.cmd through a cmd shell and examine the rsync_sys.log file, If everything seems OK, then you can remove the dry-run option, and run it again. The first run will take a long time, use the start and stop markers in the logfile to check how long it takes once finished. rsync will tell you the speedup due to the delta algorithm, it should increase on subsequent runs.
Scheduling the backup.
Use Windows task scheduler to run the cwrsync.cmd script. In my case, I use a privileged account. It is advised to test with the least amount of privileges for cygwin to be happy and for filesystem operations to succeed.
It is advised the turn on scheduled tasks history. And very important, make sure that the “start in” directory for the cwrsync.cmd action is set to the base cygwin64 folder.
Test the backup run using a “run once” trigger at t+1 minute in addition to the recurrent trigger.
A final note.
This backup strategy will ensure that you have an updated state of your remote system on the Windows system. It is similar to an incremental backup that patches the destination directory. It does not store any history of files besides the last backup operation.
I don’t use the –delete option that propagates deletions of files and folders from the source to the destination, has it can be very impactful for a disaster recovery use where there is no file versioning history. Note however, that this will bloat the backed up structure on the destination and make recovery efforts more complicated in the long term.
The best option for a backup if you use LVM, albeit using more space on the destination is to use cygwin + rsync to backup a tar gz file of a LVM snapshot directory structure instead of the directory tree of “/”. If you go this way though, it is advised, as already stated above, to perform the snapshot operations synchronously from the backup system through the cwrsync.cmd using SSH, before the rsync operations. That probably means using a passphrase less public/private key pair for ssh to run these commands interactively. Don’t forget to unmount and remove the snapshot after rsync is done.
Rsync (Remote Synchronization) is a command-line utility designed for synchronizing files and directories across different storage systems. Unlike regular copying, Rsync transfers only the modified data, saving both time and bandwidth.
→ Transfers only modified files, reducing data transfer volume.
→ Synchronizes data between operating systems.
→ Supports automation via scripts and CRON jobs, eliminating the need for manual execution.
To get started, you need a computer running Windows 10 or 11 with WSL support. Note that for WSL to work, hardware virtualization must be enabled in your PC’s BIOS. Without this, you won’t be able to install WSL.
Run the following command in PowerShell with administrator privileges:
wsl --install
To install Rsync, run the following commands:
sudo apt update
sudo apt install rsync
For Rsync to work over the network, SSH is required. Install and activate the OpenSSH Server with the following commands:
sudo apt install openssh-server
sudo service ssh start
sudo systemctl enable ssh
In WSL, Windows drives are mounted under /mnt/. For example, the C: drive is accessible at /mnt/c/.
To synchronize files from the /home/user/project/ directory to the Windows folder C:\backup, use the command:
rsync -avz /home/user/project/ /mnt/c/backup/
To synchronize in the opposite direction (from C:\backup to /home/user/project/), use:
rsync -avz /mnt/c/backup/ /home/user/project/
If you need regular synchronization, you can create a simple Bash script:
1. Create a new file:
nano sync.sh
2. Copy the following code into the file:
#!/bin/bash
rsync -avz /home/user/project/ /mnt/c/backup/
3. Save the file (Ctrl + X → Y → Enter).
4. Make it executable:
chmod +x sync.sh
5. Run it manually when needed:
./sync.sh
To schedule the script to run automatically (e.g., every day at 2:00 AM), execute:
crontab -e
Then add the following line:
0 2 * * * /home/user/sync.sh
This ensures the script runs daily without user intervention.
With this setup, you can quickly transfer files between systems, automate backups and synchronization, and save time by transferring only modified data.
Now that you’ve mastered installing WSL, configuring Rsync and SSH, and automating the process, you can significantly simplify file management and reduce manual effort.