Computers & Electronics
65,059 views
25 min · 3 min read
7 steps
Advanced

How to set up Automated Home Backups using rsync on Linux

Setting up automated home backups with rsync on Linux gives you a fast, efficient, and reliable way to protect documents, photos, and system configurations. This guide walks you through planning, creating, testing, and scheduling incremental backups so you can recover from accidental deletes or hardware failure with minimal fuss. Follow the steps below and adapt paths, retention, and schedules to match your storage and needs.

Verified by pleasexplain editors
  1. Step 1: Choose backup destination

    Decide where to store backups: an external USB drive, a NAS over SMB/SSH, or a remote server. Allow at least 2–3 times the size of the data you plan to back up; for example, if you have 200 GB of home data pick a 500 GB drive or larger to allow growth and snapshots.

    [Illustration: photo of a desktop with an external hard drive and NAS device connected to a Linux laptop]

  2. Step 2: Install required tools

    Install rsync and SSH if you plan to back up over the network: on Debian/Ubuntu use apt install rsync openssh-client; on Fedora use dnf install rsync openssh-clients. Confirm versions with rsync --version and test SSH connectivity with ssh user@host to ensure authentication works.

    [Illustration: terminal window showing package manager install commands and rsync --version output]

  3. Step 3: Plan which files to include

    Create a list of important paths to copy, such as /home/youruser/Documents, /home/youruser/.config, and /var/www if needed. Exclude large transient folders like /tmp, browser caches, or VM images unless specifically required; this keeps backups fast and storage-efficient.

    [Illustration: notebook or text file listing include and exclude paths for backing up a home directory]

  4. Step 4: Create an rsync command

    Build an rsync command that preserves attributes and transfers efficiently, for example: rsync -aAXv --delete --exclude={'*.cache/*','/tmp/*'} /home/youruser/ /mnt/backup/homeuser/. This preserves ACLs, xattrs, and deletes removed files on the destination to mirror the source state; test with --dry-run first.

    [Illustration: terminal showing an rsync command line and a dry-run output example]

  5. Step 5: Set up SSH key authentication

    For network backups, create an SSH key pair with ssh-keygen -t ed25519 -f ~/.ssh/backup_key and copy the public key with ssh-copy-id -i ~/.ssh/backup_key.pub user@remote. Use the key-only account and restrict commands in authorized_keys for extra safety and test that ssh -i ~/.ssh/backup_key user@remote runs without a password.

    [Illustration: terminal showing ssh-keygen command and ssh-copy-id in use between a laptop and remote server]

  6. Step 6: Create a backup script

    Write a small shell script that runs rsync with your chosen options and logs output to /var/log/rsync-backup.log; include rotation by timestamping or using logrotate. Make the script executable with chmod +x and run it manually to verify exit code 0 and correct file copies before automating.

    [Illustration: text editor window with a short bash script saving rsync output to a dated logfile]

  7. Step 7: Schedule with cron or systemd

    Automate by adding a cron job like 0 2 * * * /usr/local/bin/backup.sh for nightly 2:00 AM runs, or create a systemd timer for more flexible triggers. Monitor initial runs for 1–2 weeks and check logs weekly; keep at least two weeks of backups and consider monthly snapshots for long-term retention.

    [Illustration: screenshot of crontab -e with a scheduled job and a systemd timer unit list]


  • Keep one offline copy stored disconnected at least once per month to protect against ransomware or device failure.
  • Compress rarely-changed archives (tar.gz) of large static directories to save space; run compression during low-usage hours like midnight.
  • Use --bwlimit=5000 to throttle bandwidth to about 5 MB/s during daytime network use to avoid saturating Wi-Fi.
  • Test restores every 1–3 months by copying a few files back to a separate location to ensure backups are usable.
  • Consider using --link-dest with rsync to create daily incremental snapshots while saving space via hard links.
  • Encrypt the backup disk with LUKS or use rsync over SSH to protect sensitive data in transit and at rest.

  • Do not use --delete without testing first; a wrong path can remove files permanently from your destination during the first run.
  • Avoid backing up live databases with plain rsync; either stop the database, use database dumps, or use filesystem snapshots to ensure consistency.
  • Never store the only backup on the same physical machine as the source; hardware failure or theft can destroy both copies.
  • Do not share private SSH keys; use a dedicated keypair for automated backups and restrict it on the server side to minimize risk.

Was this guide helpful?