Skip to main content
To back up files with rsync to a remote server, run rsync -aAXH --delete /var/www/ backup@198.51.100.20:/backups/www/. rsync connects over SSH, copies only files that changed and keeps permissions, ACLs and hard links. Test first with --dry-run, use an SSH key so it runs unattended, and schedule it with cron.

Before you start

  • You need two machines: the source (your server) and the backup host, for example a second VPS or your own Linux machine. Both need rsync installed.
  • Commands use sudo. Root users can leave it out.
  • rsync is often installed already. If not:

What do the rsync backup options mean?

A trailing slash on the source matters: /var/www/ copies the contents of www, while /var/www creates a www folder inside the destination.

How to set up an rsync backup over SSH

1

Create an SSH key on the source server

Backups run as root, so create the key for root:
2

Allow the key on the backup host

Then test it: sudo ssh -i /root/.ssh/backup_ed25519 backup@198.51.100.20 hostname. See SSH keys.
3

Create the folder on the backup host

4

Do a dry run

-i lists each change. Lines starting *deleting are files rsync would remove from the backup.
5

Run the backup

Remove n and -i:
--delete removes files from the backup when they disappear from the source. If you delete something by mistake, the next run deletes it from the backup too. Swapping source and destination by mistake deletes your live data. Always do a dry run after changing the command, and keep dated snapshots (below) so one bad run cannot wipe everything.
File owners are only kept when rsync runs as root on the receiving side. If you back up as a normal user such as backup, the files on the backup host belong to that user. The data is safe, but restore permissions carefully, or use restic, which stores ownership inside its repository.
--link-dest makes each day’s backup look like a full copy, but unchanged files are hard links to the previous day, so they take no extra space.
The --link-dest path is relative to the destination folder, so ../2026-11-03 points to the day before. On the first run, when yesterday’s folder does not exist, rsync prints --link-dest arg does not exist and makes a full copy. That is expected. Delete old snapshots on the backup host by name, for example keep the newest 30:
Run the first line on its own and read the list before you run the second. Don’t select old snapshots with find -mtime: rsync copies the source folder’s date onto each snapshot folder, so a brand-new snapshot can look years old.

How to run the rsync backup every night

Add:
See schedule tasks with cron.

How to restore files from an rsync backup

Swap source and destination, and restore to a temporary folder first:
Check the files, then copy them into place. Do not use --delete when restoring unless you mean to make the live folder identical to the backup.

How to check it worked

A second dry run straight after a backup should list nothing to transfer.

Frequently asked questions

Is rsync a real backup?

A single rsync mirror is a copy, not a history: mistakes and ransomware copy across on the next run. With dated --link-dest snapshots it becomes a simple versioned backup. For encryption and deduplication, use restic.

Should the server push or the backup host pull?

Pulling (the backup host runs rsync and connects to your server) is safer, because an attacker on your server then has no login to the backup host and cannot delete backups. Pushing is simpler to set up.

How do I use rsync with a custom SSH port?

Add the port to the SSH command: -e "ssh -p 2222 -i /root/.ssh/backup_ed25519".

How do I exclude folders?

Add --exclude='cache/' for each pattern, or list them in a file and use --exclude-from=/root/rsync-excludes.txt.

VPS and dedicated server guides

Every guide in this section.

Back up a Linux server

What to back up and which tool to use.

Copy files with scp and rsync

One-off transfers between machines.

Encrypted backups with restic

Versioned and encrypted.

Create and use SSH keys

Passwordless logins for scripts.

Checked against the official rsync manual page on 4 November 2026; rsync options, --delete, dry run and --link-dest tested locally on Ubuntu 24.04 LTS (rsync 3.2.7). Commands can differ on other distributions or releases.

Need Extra Help?

If you encounter any issues, our support team is ready to assist:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026