H
10Corp Premium Hosting

The rsync Command for File Synchronization

Last Updated: 2025-01-01 3 min read

Overview

rsync is a fast, versatile file synchronization tool that copies only the differences between source and destination. Unlike scp, which transfers entire files every time, rsync performs incremental transfers — making it ideal for backups, deployments, and keeping directories in sync.

Basic Syntax

rsync [options] source destination

For remote transfers:

rsync [options] source user@host:/path
rsync [options] user@host:/path destination

The Essential Flags: -avz

The most common rsync invocation uses three flags together:

rsync -avz /local/folder/ user@server.example.com:/remote/folder/
FlagMeaning
-aArchive mode — preserves permissions, timestamps, symlinks, and directory structure
-vVerbose — shows files being transferred
-zCompress data during transfer

Common Operations

Sync a local directory to a remote server

rsync -avz /home/user/my-site/ user@server.example.com:/home/user/public_html/

Important: The trailing slash on the source (my-site/) means “copy the contents of this directory.” Without it, rsync copies the directory itself into the destination.

Pull files from a remote server to local

rsync -avz user@server.example.com:/home/user/public_html/ ./local-backup/

Specify a custom SSH port

rsync -avz -e "ssh -p 2222" /local/folder/ user@server.example.com:/remote/folder/

Excluding Files and Directories

Exclude specific files or patterns

rsync -avz --exclude="*.log" --exclude=".git" /source/ /destination/

Exclude from a file

Create an exclude list:

# exclude-list.txt
*.log
.git/
node_modules/
.env
rsync -avz --exclude-from="exclude-list.txt" /source/ /destination/

Dry Run — Preview Before Syncing

Always test with --dry-run first to see what will change without actually modifying anything:

rsync -avz --dry-run /source/ user@server.example.com:/destination/

Useful Flags Reference

FlagDescription
-aArchive mode (preserves permissions, timestamps, etc.)
-vVerbose output
-zCompress data during transfer
-PShow progress and allow partial/resumed transfers
--deleteDelete files in destination that don’t exist in source
--dry-runSimulate the transfer without making changes
--exclude=PATTERNExclude files matching the pattern
--exclude-from=FILERead exclude patterns from a file
-e "ssh -p PORT"Specify SSH command with custom port
--bwlimit=KBPSLimit bandwidth in KB/s
-nSame as --dry-run
--statsShow detailed transfer statistics

Practical Hosting Examples

Create an incremental backup

rsync -avz /home/user/public_html/ /home/user/backups/site-backup/

Only changed files are copied on subsequent runs — fast and efficient.

Mirror a directory (delete extra files at destination)

rsync -avz --delete /source/ /destination/

Caution: --delete removes files from the destination that no longer exist in the source. Always run with --dry-run first.

Deploy a website with progress

rsync -avzP --exclude=".git" --exclude="node_modules" \
  ./build/ user@server.example.com:/home/user/public_html/

Bandwidth-limited transfer

rsync -avz --bwlimit=1000 /large-backup/ user@server.example.com:/backups/

Limits the transfer to 1000 KB/s.

Tips

  • Always use --dry-run before any rsync with --delete to avoid accidental data loss.
  • The trailing slash on paths matters — test with a small directory first if you’re unsure.
  • For automated backups, combine rsync with cron to run on a schedule.
  • Use -P for large transfers — it shows progress and allows resuming interrupted transfers.
Tags: ssh linux rsync file-transfer backup

Still need help?

Our support team is available 24/7 to assist you.