Rsync

From Pulsed Media Wiki

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

<syntaxhighlight lang="bash"> rsync [options] [source] [destination] </syntaxhighlight>

Common Examples

Copy a local folder to another local directory:

<syntaxhighlight lang="bash"> rsync -av /source/ /destination/ </syntaxhighlight>

Copy a folder to a remote server using SSH:

<syntaxhighlight lang="bash"> rsync -avz /local/folder/ user@remote_host:/remote/folder/ </syntaxhighlight>

Sync from a remote server to local:

<syntaxhighlight lang="bash"> rsync -avz user@remote_host:/remote/folder/ /local/folder/ </syntaxhighlight>

Show progress during transfer:

<syntaxhighlight lang="bash"> rsync -avz --progress /source/ /destination/ </syntaxhighlight>

Dry-run (test run without actual copying):

<syntaxhighlight lang="bash"> rsync -avz --dry-run /source/ /destination/ </syntaxhighlight>

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:

<syntaxhighlight lang="bash"> sudo apt update sudo apt install rsync </syntaxhighlight>

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

See Also