rsync copies files and folders, locally or between computers over SSH. Its strength is that it only sends what has changed, so the second run of a big copy takes seconds. It is the standard tool for server backups and for moving sites to a new host.
The command you will use most is rsync -avz --progress source/ user@server:/destination/. -a keeps permissions and dates, -v lists files, -z compresses in transit. Always test with –dry-run first, and remember the trailing slash: source/ copies the folder’s contents, source copies the folder itself.
Install it
rsync is installed on most Linux servers and on macOS. If not:
sudo apt install rsync
sudo dnf install rsync
The first line is for Ubuntu and Debian, the second for AlmaLinux and Rocky. It must be installed on both ends of a remote copy.
The basic command
rsync -avz --progress /var/www/example.com/ exampleco@203.0.113.10:/var/www/example.com/
| Option | Meaning |
|---|---|
-a | Archive: copy folders recursively and keep permissions, owners, dates and links |
-v | Verbose: list each file |
-z | Compress data on the way, useful over the internet |
--progress | Show progress for each file |
-n or --dry-run | Show what would happen without changing anything |
--delete | Remove files at the destination that no longer exist at the source |
--exclude | Skip matching files or folders |
-e "ssh -p 2222" | Use SSH on a non-standard port |
The trailing slash rule
This is the mistake everyone makes once:
| Command | Result |
|---|---|
rsync -a site/ backup/ | Contents of site go into backup |
rsync -a site backup/ | Creates backup/site/ |
The destination’s slash does not matter; the source’s does. When in doubt, run with --dry-run and read the list.
Pull from a server, or push to one
Push from the machine you are on:
rsync -avz ~/site/ exampleco@203.0.113.10:/var/www/example.com/
Pull from a server to the machine you are on:
rsync -avz exampleco@203.0.113.10:/var/www/example.com/ ~/site-copy/
Both use your normal SSHSSH A secure way to type commands on a server from your own computer, as if you were sitting at it. More about SSH → login, so SSH keys make it run without a password prompt.
Mirror exactly with –delete
--delete makes the destination an exact mirror, removing files that were deleted at the source. It is powerful and dangerous: with the paths the wrong way round, it deletes your real files. Always dry-run it first:
rsync -avz --delete --dry-run ~/site/ exampleco@203.0.113.10:/var/www/example.com/
Lines starting deleting show what would go. Run again without --dry-run only when the list is what you expect.
Exclude what you do not need
rsync -avz --exclude 'wp-content/cache/' --exclude '*.log' --exclude 'node_modules/' ~/site/ backup:/srv/site/
Exclude paths are relative to the source folder. For many rules, list them in a file and use --exclude-from=excludes.txt.
Use it for backups
A nightly copy of your sites to a second server, run by a cron job:
0 3 * * * rsync -az --delete /var/www/ backup@198.51.100.20:/backups/web/ >> /var/log/rsync-backup.log 2>&1
A mirror on its own is not a full backup: if a file is deleted or encrypted by ransomware, the next run copies the damage. Keep dated versions too, with --link-dest or a tool built for versioned backups. See how to back up a Linux server.
Use it for migrations
rsync is the best way to move large sites. Copy once in advance, then again just before the switch to pick up changes; the second run is fast. The full process is in how to move a WordPress site to a new host.
Common problems
| Message | Cause | Fix |
|---|---|---|
rsync: command not found on the remote side | rsync missing on the server | Install it there |
Permission denied | Wrong user, or no write access to the destination | Check the folder owner, or use the right user |
connection refused | SSH on another port or blocked | Add -e "ssh -p PORT" and check the firewall |
| Files owned by the wrong user afterwards | Copied as a different user | Run chown on the destination, or copy as the site’s user |
| Every file copied again each run | Dates not preserved | Make sure -a is used |
Official documentation
- rsync manual page, rsync project.
Related
- How to back up a Linux server.
- SFTP, for single uploads in a graphical client.
- How to connect to a server with SSH.
Something out of date? Software changes. If a step no longer works, tell us and we will check it and update the page.

