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.
Benefits of Using Rsync in WSL
→ 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.
Prerequisites
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.
Installing and Configuring WSL
Run the following command in PowerShell with administrator privileges:
wsl --install
Installing Rsync in WSL
To install Rsync, run the following commands:
sudo apt update
sudo apt install rsync
Configuring SSH in WSL
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
Synchronizing Data Between Operating Systems
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/
Automating the Synchronization Process
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
Setting Up Automatic Execution with CRON
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.
Conclusion
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.