Difference between revisions of "Rsync"
(Created page with "== rsync == '''rsync''' (''remote sync'') is a fast, versatile, and widely-used command-line utility for synchronizing and transferring files and directories between two loca...") |
|||
Line 16: | Line 16: | ||
=== Basic Syntax === | === Basic Syntax === | ||
− | + | ||
− | rsync [options] [source] [destination] | + | rsync [options] [source] [destination] |
− | + | ||
=== Common Examples === | === Common Examples === | ||
Line 24: | Line 24: | ||
'''Copy a local folder to another local directory:''' | '''Copy a local folder to another local directory:''' | ||
− | + | ||
− | rsync -av /source/ /destination/ | + | rsync -av /source/ /destination/ |
− | + | ||
'''Copy a folder to a remote server using SSH:''' | '''Copy a folder to a remote server using SSH:''' | ||
− | + | ||
− | rsync -avz /local/folder/ user@remote_host:/remote/folder/ | + | rsync -avz /local/folder/ user@remote_host:/remote/folder/ |
− | + | ||
'''Sync from a remote server to local:''' | '''Sync from a remote server to local:''' | ||
− | + | ||
− | rsync -avz user@remote_host:/remote/folder/ /local/folder/ | + | rsync -avz user@remote_host:/remote/folder/ /local/folder/ |
− | + | ||
'''Show progress during transfer:''' | '''Show progress during transfer:''' | ||
− | + | ||
− | rsync -avz --progress /source/ /destination/ | + | rsync -avz --progress /source/ /destination/ |
− | + | ||
'''Dry-run (test run without actual copying):''' | '''Dry-run (test run without actual copying):''' | ||
− | + | ||
− | rsync -avz --dry-run /source/ /destination/ | + | rsync -avz --dry-run /source/ /destination/ |
− | + | ||
=== Key Options === | === Key Options === | ||
Line 117: | Line 117: | ||
On Debian/Ubuntu: | On Debian/Ubuntu: | ||
− | + | ||
sudo apt update | sudo apt update | ||
sudo apt install rsync | sudo apt install rsync | ||
− | + | ||
=== Related Tools and Enhancements === | === Related Tools and Enhancements === |
Latest revision as of 07:41, 5 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
- Syncthing – Real-time file sync alternative with a GUI