Every Linux user learns the same lesson eventually, usually at the worst possible moment: a failed drive, a botched upgrade, or one wrong command, and years of files are gone. Backups are the answer, and rsync is the simplest honest tool for the job. It is already installed on nearly every Linux system, it copies only the files that changed, and it stores plain files you can browse with a file manager. No proprietary container to crack open, no subscription, no daemon to babysit.
rsync is a mirror, not a time machine. It keeps a second copy of your files current, which is exactly what you want when a drive dies or you delete the wrong folder. It does not keep old versions of files by itself. If you want versioned system snapshots, pair it with Timeshift; if you want encrypted off-site backups, restic is the next step.
Prerequisites
You need a Linux system with a terminal, rsync installed, and a destination with at least as much free space as the data you are backing up: an external USB drive, a second internal disk, or a folder on a NAS. Back up your home directory as your own user. Reach for sudo only if you need files owned by root. Tested on: Ubuntu 24.04, rsync 3.2.7. The flags used here have been stable for years.
Check that rsync is there first:
rsync --versionIf the command is not found, install it with your package manager:
# Ubuntu, Debian, Linux Mint
sudo apt update && sudo apt install rsync
# Fedora
sudo dnf install rsync
# Arch Linux and derivatives
sudo pacman -S rsync
# openSUSE
sudo zypper install rsyncStep 1: Run your first backup
The one command that does most of the work looks like this:
rsync -av --delete /home/yourname/ /mnt/backup/home/Replace /home/yourname/ with your actual home directory and /mnt/backup/home/ with your destination. The flags matter:
-a(archive) preserves permissions, ownership, timestamps, and symlinks, and copies recursively.-v(verbose) lists every file as it is copied, so you can see what is happening.--deleteremoves files from the destination that you deleted from the source, so the backup stays a true mirror instead of growing stale copies forever.
Watch the trailing slash. This is the classic rsync trap, and it bites everyone once: /home/yourname/ with a trailing slash copies the contents of the folder into the destination, while /home/yourname without it creates a yourname folder inside the destination. I verified this on a test run: rsync -a src/ dest/ put the files straight into dest/, while rsync -a src dest/ created dest/src/.
A real first run looks like this:
sending incremental file list
photo.jpg
Documents/
Documents/notes.txt
sent 247 bytes received 66 bytes 626.00 bytes/sec
total size is 12 speedup is 0.04Run the exact same command a second time and almost nothing happens, which is the whole point:
sending incremental file list
sent 134 bytes received 13 bytes 294.00 bytes/sec
total size is 12 speedup is 0.08rsync compared both trees, found nothing changed, and copied nothing. On a real home directory the first run takes a while and every run after it finishes in seconds.
Step 2: Always dry-run when you change the command
Before you add --delete, change a path, or point rsync at a new destination, preview the run first:
rsync -av --dry-run --delete /home/yourname/ /mnt/backup/home/--dry-run (or -n) prints exactly what rsync would do without writing anything. Make it a habit: any rsync command you have not run before gets a dry run first. This single habit is what separates a backup from a data-loss incident, because --delete is a loaded gun. One typo in the source path and rsync will cheerfully delete your backup's files to match an empty or wrong source. Dry-run, read the list, then run it for real.
Step 3: Exclude the junk
A home directory is full of things no backup needs: browser caches, trash, and package caches that regenerate themselves. Excluding them makes backups smaller and faster:
rsync -av --delete \
--exclude '.cache/' \
--exclude '.local/share/Trash/' \
--exclude 'Downloads/' \
--exclude '.npm/' \
/home/yourname/ /mnt/backup/home/If the exclude list grows, put it in a file instead. Create ~/.rsync-excludes with one pattern per line:
.cache/
.local/share/Trash/
Downloads/
node_modules/
*.tmpThen reference it:
rsync -av --delete --exclude-from=$HOME/.rsync-excludes /home/yourname/ /mnt/backup/home/Be deliberate about what you exclude. Downloads/ is safe to skip only if you treat it as a temporary landing zone.
Step 4: Automate it so it actually happens
A backup you have to remember is a backup that stops happening. A weekly cron job keeps the mirror current without you thinking about it:
crontab -eAdd this line to run every Sunday at 3 AM and log the result:
0 3 * * 0 /usr/bin/rsync -a --delete --exclude-from=/home/yourname/.rsync-excludes /home/yourname/ /mnt/backup/home/ >> /home/yourname/backup.log 2>&1Two details matter here. First, cron runs with a minimal environment, so use the full path to rsync (which rsync tells you where it lives; on most distros it is /usr/bin/rsync). Second, use -a without -v in the cron job, or the log file grows with a line per file. If you prefer systemd timers over cron, they do the same job with better logging; our systemd timers guide walks through the setup.
One warning about automation: the destination must actually be mounted. If your USB drive is unplugged and /mnt/backup is just an empty folder on your root disk, rsync will happily fill your system disk with the backup. Check first with mountpoint /mnt/backup or df -h /mnt/backup. If your root disk does fill up, here is how to fix a full disk on a Linux server before it takes the system down.
Step 5: Restore and verify before you need it
A backup you have never restored is a hope, not a backup. Test it now, while nothing is on fire. To restore a single file, copy it back to a temporary location and open it:
rsync -av /mnt/backup/home/Documents/notes.txt /tmp/restored-notes.txtTo restore the whole home directory, reverse the original command, with a dry run first:
rsync -av --dry-run /mnt/backup/home/ /home/yourname/
rsync -av /mnt/backup/home/ /home/yourname/Then verify the two trees match. Run the same command with --dry-run once more: if it lists no files, source and destination are identical. For a spot check on one folder, diff -r works too:
diff -r /home/yourname/Documents /mnt/backup/home/DocumentsSilence from diff means the folders are identical. Do this restore test once after setting the backup up, and again every few months. The five minutes it costs are nothing next to discovering a broken backup during a real failure.
Gotchas worth knowing
- Backing up a running system: skip
/proc,/sys,/dev,/run, and/tmp; they are virtual or temporary. Home-directory backups avoid this entirely, which is one more reason to start there. - Ownership: files owned by root need
sudoto read, and restoring them as your own user scrambles ownership. If you back up as root, restore as root. - Remote destinations: rsync works over SSH with no extra setup:
rsync -av /home/yourname/ user@nas:/backup/home/copies to another machine, encrypted in transit. - One destination, one source: never point two different sources at the same destination with
--delete. Each will delete the other's files.
The bottom line
Install rsync, run one command with a dry run first, exclude the caches, automate it weekly, and test a restore. That is the whole system, and it is the difference between losing a weekend and losing years of work. Start with your home directory; the system files can wait until the habit sticks.


