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
rsyncinstalled. - Commands use
sudo. Root users can leave it out. - rsync is often installed already. If not:
- Ubuntu / Debian
- AlmaLinux / Rocky / Fedora
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
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: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.How to keep daily snapshots with —link-dest
--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.
--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:
How to run the rsync backup every night
How to restore files from an rsync backup
Swap source and destination, and restore to a temporary folder first:--delete when restoring unless you mean to make the live folder identical to the backup.
How to check it worked
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.
Related guides
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:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026