1. Prerequisites
To execute rsync Between the local system and a remote server you need:
Two devices: one local (your computer) and one Linux server (VPS or dedicated server)
rsyncInstalled on both systemsSSH access between two systems (so you can communicate without constantly entering passwords)
SSH public key on the destination server in the file
authorized_keysto be placed
2. The concept and function of rsync (specialized and understandable version for beginners and professionals)
rsync is a powerful command line tool in Linux that is used for Synchronization (Sync) and Data transfer It is used between two paths, whether these paths are on the same system or on two separate servers.
But why is rsync so popular?
Because of that Instead of transferring entire files, it transfers only the parts that have changed.
How exactly does rsync work? (Simple and precise understanding)
When you run rsync, the tool first:
Structure and content of the two tracks (e.g., destination folder and source folder) compares.
Checks Which files are new, which have changed, and which have been deleted or unchanged?.
Instead of sending the entire file, just Part of the data that has changed Transfers.
This technique is called:
Delta Transfer Algorithm
This rsync algorithm Very fast and efficient It does, because:
The bandwidth consumed is reduced.
The transfer time is much shorter.
CPU resources on the server are less involved
Simple example to better understand rsync functionality
Let's say you have a 1GB file and only 5MB of it has changed.
Common tools such as
SCP-1811They re-upload the entire 1GB.But rsync only sends the same 5MB that changed..
This means:
More speed
Less internet usage
Less pressure on the server
rsync and servers: Why it's the best tool for server management?
When on a Server Or VPS You work, you usually need:
Move backups between two servers
Move site files from the current server to the new server
Always keep important folders (like /var/www) synced.
Transfer large files without wasting bandwidth
In all these cases, rsync is the best choice because:
Secure transfer with SSH
rsync uses the SSH protocol for transfers, so:
Data is encrypted.
No need to open additional ports
Communication security is guaranteed.
Delete extra files at the destination
With flag --delete It can keep the destination exactly the same as the source.
Resume feature
If the internet connection drops during the transfer, rsync will transfer the rest of the file, not from scratch.
Suitable for Automation
It fits easily into cronjobs and creates automated backup processes.
Real example for better understanding:
If you want to sync the following path from server A to server B:
This command:
Folder changes only
/var/wwwTransfersUpdates it at the destination.
Ensures secure transmission via SSH
A simple summary for someone new to rsync:
| Feature | Explanation |
|---|---|
| Main application | Data transfer and folder synchronization |
| Main advantage | Only changes are transferred, not the entire file. |
| Security | Using SSH for secure transfers |
| High speed | Because of the delta transfer algorithm |
| Professional and server-friendly | The best tool for backup and migration between VPS |
3. Basic rsync syntax
General structure rsync Much like other file tools like SCP-1811 is:
Simple local example:
Create two test folders on the local system
Implementation:
In this case, only the content
dir1Todir2It is moved, not the folder itself.
Option -a (archive) is recommended because:
Recursively synchronizes the directory
Preserves file ownership, modification time, and permissions
Important: If you put a “/” at the end of the source path, only the contents of the directory will be synced; if you don’t, the original folder itself will be transferred.
4. Run a secure preview with --dry-run
Before performing sensitive operations (especially when using options such as --delete you use), it's best to do a dry run first:
Option
-nOr--dry-runSimulates operations without making changes-v(verbose) Provides detailed output of files being synced or deleted.
This preview helps you see exactly what's going to happen before you delete files and avoid risky mistakes.

5. Push and Pull files between the local system and the server
Send to server (Push)
To sync a local directory to the server:
-a: Preserve file attributes~/local-dir/: Local routeuser@remote-server: User and server address:/remote/path/: Path on the server
If "/" is at the end of the source, only the contents of the folder are sent; otherwise, the folder itself is also transferred.
Receive from the server (Pull)
Reverse operation: Synchronization from server to local system:
Again, it's important to note the slash in the source path (here the server path) because it determines the synchronization behavior.
6. Advanced options rsync
-z: Compress data when sending to reduce network usage-P: A combination of--progressand--partialWhich allows displaying the progress of the transfer and allowing incomplete transfers to be continued
Example:
--delete: Delete files that exist in the destination but no longer exist in the source (suitable for mirroring)--excludeand--include: Filter files/folders for more precise interaction--backupand--backup-dir: Create a backup of deleted files in a separate path
7. Schedule synchronization with Cron
To run a periodic sync, you can rsync in cron Schedule:
Edit crontab:
Example of a daily cronjob for synchronization:
This command runs every day at 3 AM and synchronizes the local directory with the server version.
Important recommendations for cron-job:
From absolute paths to
rsyncand use directoriesSetting up passwordless SSH key login
Save cron output to a log file or handle errors
8. Troubleshooting common problems and best practices
Some common problems when using rsync And its solutions:
Error in source/destination path: Use of
--dry-runFor detailed reviewUnwanted deletion of files: Only when we are absolutely sure of
--deleteLet's usePermissions errors: with
-aMaintain ownership and permissions.Automation problems: Use full paths and passwordless SSH authentication
Conclusion
rsync It is a very powerful and optimized tool for synchronizing data between the local machine and the server. Thanks to the delta-transfer algorithm, this tool is a low-power, secure and accurate option for backup, data transfer and creating mirror environments. Using advanced options, experiment with --dry-run and scheduling with cronYou can optimize, secure, and automate the synchronization process.









