rsync: The Most Powerful File Sync and Backup Tool for Linux

rsync explained with the options you’ll actually use: local and remote syncs over SSH, mirroring, exclusions, incremental backups, cron jobs and deploys.

Dhananjay AggarwalDhananjay Aggarwal, · 6 min read
Share
Summarize with AI
The word rsync beside the Linux penguin and a padlock, over faded terminal output. From a post by Dhananjay Aggarwal.

In my previous article, I covered Robocopy, one of the most reliable file copy and directory mirroring tools for Windows users. Robocopy is excellent in Windows environments, but it is not available on Linux. Linux has its own native tool that offers even more flexibility, speed and control. That tool is rsync.

rsync is the standard tool for file synchronization and backup automation on Linux, across servers, cloud instances and local machines. It transfers only the changed blocks of a file, preserves permissions, ownership and timestamps, and works locally or over SSH, which is why system administrators and DevOps engineers use it for backups and deploys.

This article explains rsync in detail, gives practical examples, and shows why it is the preferred option on Linux.

What is rsync?#

rsync is a command line utility that synchronizes files and directories between two locations. It can work locally or over a remote connection using SSH.

Key capabilities include:

  • Delta-based file transfer
  • Fast, bandwidth-efficient syncing
  • Preserved metadata: permissions, ownership, timestamps and symlinks
  • Secure remote transfer over SSH
  • Directory mirroring
  • Exclusions and pattern-based filtering
  • A natural fit for cron-based backups and automation

rsync is popular because it transfers only changed blocks, handles interruptions, encrypts transfers over SSH, fits into cron jobs and scripts, and runs on Linux, Unix, macOS and WSL.

1. Efficient#

Only the changed blocks of a file are transferred, which saves time and reduces network usage.

2. Reliable#

rsync handles interruptions and preserves all metadata accurately.

3. Secure#

It uses SSH for encrypted file transfer.

4. Automation friendly#

Perfect for cron jobs, scripts, deployment pipelines and server maintenance tasks.

5. Cross platform#

Available on Linux, Unix, macOS and WSL.

What is the basic rsync syntax?#

The basic rsync syntax is options, then the source, then the destination.

Bash
rsync [options] source destination

Example:

Bash
rsync -av /home/user/docs /backup/docs

This copies all files from docs to backup/docs with their original permissions preserved.

A source folder syncing through rsync over SSH into a destination folder. From a post by Dhananjay Aggarwal.

What do the common rsync options do?#

OptionWhat it does
-aArchive mode, which preserves metadata
-vVerbose output
-zCompression during transfer
-hHuman-readable numbers
--deleteRemove files at the destination that are not in the source
--excludeExclude patterns or folders
--progressShow detailed progress
-e sshForce rsync to use SSH

Practical rsync Examples#

Most everyday rsync commands are -av plus one or two options: -e ssh for remote servers, --delete for mirrors, --exclude for filters, --progress for progress and --link-dest for incremental backups.

1. Copy files locally#

Bash
rsync -av /source/folder/ /destination/folder/

2. Sync files to a remote server via SSH#

Bash
rsync -av -e ssh /var/www/ user@192.168.1.10:/backup/www/

3. Download files from a remote server#

Bash
rsync -av -e ssh user@192.168.1.10:/data/ /local/data/

4. Mirror a directory#

Bash
rsync -av --delete /source/ /mirror/

Note: --delete removes files from the destination that do not exist in the source.

5. Exclude files or directories#

Bash
rsync -av --exclude="*.log" --exclude="cache/" /var/app/ /backup/app/

6. Show transfer progress#

Bash
rsync -avh --progress /data /backup

7. Incremental backup using rsync#

Bash
rsync -av --link-dest=/backup/daily.1 /data/ /backup/daily.2

Advanced rsync Techniques#

Advanced rsync use covers daily backups with cron, resumable syncs over slow networks with --partial, and deployments that exclude folders like node_modules.

1. Automating daily backups with cron#

Bash
crontab -e

Add:

Bash
0 2 * * * rsync -av /data/ /backup/data/

This runs every day at 2 AM.

2. Syncing data over slow or unstable networks#

Bash
rsync -avz --partial --progress /data user@server:/backup

--partial keeps partially transferred files so the sync can resume later.

3. Using rsync for deployments#

Bash
rsync -avz --exclude="node_modules" ./app user@server:/var/www/app

Frequently asked questions#

What does rsync --delete do?

--delete removes files from the destination that do not exist in the source. Combined with -av, it turns the destination into a mirror of the source.

What does rsync -a mean?

-a is archive mode, which preserves metadata such as permissions, ownership, timestamps and symlinks. It is usually paired with -v for verbose output.

How do I use rsync over SSH?

Add -e ssh and give the remote side as user@host:/path, for example rsync -av -e ssh /var/www/ user@192.168.1.10:/backup/www/. Swap the source and destination to download from the server instead.

Can rsync resume an interrupted transfer?

Yes. --partial keeps partially transferred files so the sync can resume later, which helps on slow or unstable networks.

How do I make incremental backups with rsync?

Use --link-dest pointing at the previous backup, for example rsync -av --link-dest=/backup/daily.1 /data/ /backup/daily.2.

Conclusion#

Robocopy is the ideal solution for file synchronization on Windows, but rsync is the real powerhouse on Linux. It delivers excellent performance, secure transfers through SSH, and precise control over every part of file replication. Whether you are managing servers, running backups or automating deployments, rsync is the tool you will rely on.

Found it useful? Clap for it.
Share
Summarize with AI
Prefer IntervueClub on GoogleShow our posts more often in Top Stories
Dhananjay Aggarwal

Written by Dhananjay Aggarwal

All posts