Difference between revisions of "Rsync"
Line 118: | Line 118: | ||
− | sudo apt update | + | sudo apt update |
− | sudo apt install rsync | + | sudo apt install rsync |
Line 127: | Line 127: | ||
* [[Rclone]] – Cloud-oriented alternative with rsync-like syntax | * [[Rclone]] – Cloud-oriented alternative with rsync-like syntax | ||
* [[Duplicity]] – Backup tool using rsync concepts with encryption | * [[Duplicity]] – Backup tool using rsync concepts with encryption | ||
− | + | ||
=== See Also === | === See Also === | ||
Line 137: | Line 137: | ||
* [[Rclone]] | * [[Rclone]] | ||
* [[Cron]] | * [[Cron]] | ||
− | + | ||
+ | [[Category:Linux]] | ||
+ | [[Category:Guides]] |
Latest revision as of 07:39, 29 May 2025
Contents
rsync
rsync (remote sync) is a fast, versatile, and widely-used command-line utility for synchronizing and transferring files and directories between two locations, either on the same system or across a network. It minimizes data transfer by only copying the differences (deltas) between source and destination files using an efficient algorithm.
Originally developed by Andrew Tridgell and Paul Mackerras, `rsync` is included by default on most Unix-like operating systems, including Linux, macOS, and BSD.
Key Features
- **Delta transfer algorithm** – Only changes within files are sent
- **Compression and encryption** – Optional `--compress` and SSH support
- **Preserves metadata** – File permissions, timestamps, ownership, symbolic links, and more
- **Supports local and remote sync** – Works on the same machine or across SSH
- **Progress and dry-run support** – Track transfers and test without making changes
- **Efficient backups** – Ideal for incremental or automated backups
Basic Syntax
rsync [options] [source] [destination]
Common Examples
Copy a local folder to another local directory:
rsync -av /source/ /destination/
Copy a folder to a remote server using SSH:
rsync -avz /local/folder/ user@remote_host:/remote/folder/
Sync from a remote server to local:
rsync -avz user@remote_host:/remote/folder/ /local/folder/
Show progress during transfer:
rsync -avz --progress /source/ /destination/
Dry-run (test run without actual copying):
rsync -avz --dry-run /source/ /destination/
Key Options
Option | Description |
---|---|
`-a` | Archive mode (recursive, preserve permissions, timestamps, etc.) |
`-v` | Verbose output |
`-z` | Compress file data during transfer |
`-e ssh` | Use SSH for remote shell |
`--progress` | Show progress of each file |
`--delete` | Delete files in destination that no longer exist in source |
`--dry-run` | Show what would be done without making changes |
Use Cases
- Syncing files to a seedbox or VPS
- Backing up local or remote directories
- Deploying web content to a server
- Cloning directories with minimal data usage
- Scheduling automated backups via `cron`
rsync vs Other Tools
Feature | rsync | scp | sftp |
---|---|---|---|
Delta transfers | Yes | No | No |
Directory sync | Yes | Partial | Partial |
Compression | Yes | Yes | Yes |
Metadata preservation | Full | Basic | Moderate |
Interactive interface | No | No | Yes |
Use over SSH | Yes | Yes | Yes |
Integration with Automation
`rsync` is commonly used in automated scripts and backup systems:
- Cron jobs (`crontab -e`)
- Systemd timers
- Remote mirroring
- Snapshot backups (e.g., with hard links)
Security
- Uses SSH for encrypted transfers when specified (`-e ssh`)
- Supports public key authentication
- Minimizes attack surface by requiring only basic SSH setup
Installation
On Debian/Ubuntu:
sudo apt update sudo apt install rsync
Related Tools and Enhancements
- Grsync – GUI frontend for rsync
- Rclone – Cloud-oriented alternative with rsync-like syntax
- Duplicity – Backup tool using rsync concepts with encryption