🔄 Command: rsync (Remote Sync)
The rsync command is a highly efficient utility for copying and synchronizing files and directories either locally or across a network. It is widely considered the "gold standard" for backups because it only copies the differences (deltas) between the source and destination, rather than re-copying everything.
1. The "Why"
For a developer and Arch Linux user, rsync is more than just a copy command:
- Incremental Backups: Sync your source code or your drafts to an external drive. If you change only one page,
rsynconly updates that one page. - Resume Capability: If a large transfer (like a 10GB dataset) is interrupted,
rsynccan pick up exactly where it left off. - Remote Deployment: Easily push your website files or documentation to a remote server over SSH.
- Preservation: Unlike
cp,rsyncis excellent at keeping file permissions, ownership, and timestamps intact.
2. The Logic: How it Works
rsync uses a "quick check" algorithm. It looks at file sizes and modification times. If they match, it skips the file. If they don't, it breaks the file into chunks and only sends the parts that changed.
3. Basic Syntax
rsync [OPTIONS] SOURCE DESTINATION
🚨 THE TRAILING SLASH RULE:
rsync -a folder /backup→ Copies the folder itself into/backup(Result:/backup/folder).rsync -a folder/ /backup→ Copies the contents of the folder into/backup(Result:/backup/file1,/backup/file2).
4. Practical Examples for Your Workflow
A. Local Backup of Your Projects
To backup your development folder to an external drive:
rsync -avh --progress ~/Documents/Projects /run/media/user/BackupDrive/
-a(archive): Preserves everything (permissions, symlinks, etc.).-v(verbose): Shows you what is happening.-h(human-readable): Makes numbers easier to read (e.g., 10MB instead of bytes).--progress: Shows a real-time progress bar.
B. The "Mirror" Sync (--delete)
If you want the destination to be an exact copy of the source (deleting files in the backup that you've deleted in the source):
rsync -av --delete ~/Documents/E-book_Drafts /backup/E-book_Drafts
Warning: This will permanently delete files in the destination that are not in the source!
C. Syncing Over the Network (SSH)
Pushing your code to a remote server:
rsync -avz -e ssh ./my_project user@remote-server:/var/www/html
-z: Compresses data during the transfer (saves bandwidth).-e ssh: Tellsrsyncto use SSH for secure transport.
5. rsync vs. cp vs. scp
| Feature | cp |
scp |
rsync |
|---|---|---|---|
| Local Copy | Yes | No | Yes |
| Remote Copy | No | Yes | Yes |
| Incremental Updates | No | No | Yes |
| Compression | No | No | Yes |
| Resume Support | No | Limited | Yes |
6. Pro-Tips
- Dry Run (
-n): Before running a command with--delete, always add-nto see what would happen without actually making changes.rsync -av --delete -n source/ dest/ - Excluding Files: Avoid backing up heavy, unnecessary folders like
node_modulesor.git:rsync -av --exclude 'node_modules' --exclude '.git' ./project /backup/ - Arch Linux Context: You can use
rsyncto clone your entire Arch installation to a new drive. It’s often preferred overddbecause it allows you to change the filesystem or resize partitions during the process. - Tutorial Tip: If you're teaching others how to monetize their skills, show them how to use
rsyncto automate the delivery of their digital products—it makes the workflow look professional and reliable.
7. Summary Reference
| Goal | Command |
|---|---|
| Simple Archive Sync | rsync -a source/ dest/ |
| Sync with Progress Bar | rsync -ah --progress source/ dest/ |
| Remote Sync (SSH) | rsync -avz -e ssh source/ user@host:dest/ |
| Mirror (Delete extras) | rsync -a --delete source/ dest/ |