The Pragmatic Backup Strategy for Home Servers (Rsync & Cron)
A realistic backup strategy for home servers: what to prioritize, what to skip, and how to automate Docker appdata backups with rsync and cron.
On this page
- Prioritizing Your Data (So Backups Actually Happen)
- What Belongs in Your Rsync Backup Script
- Step 1: Prepare the External Backup Drive Cleanly
- Step 2: Write a Safe Automated Rsync Script
- Step 3: Schedule It with Cron
- Optional Upgrade: Versioned Daily Snapshots with --link-dest
- Troubleshooting Common Rsync Backup Errors
Prioritizing Your Data (So Backups Actually Happen)
A lot of backup guides fail beginners on day one because they tell you to back up every terabyte on your server. If you have a 4 TB drive full of movies and TV shows, buying another 4 TB drive plus paying $24/month for cloud storage feels absurd — so people end up backing up nothing at all.
Right now, my own backup strategy is simple and strictly prioritized:
- Skip bulk replaceable media: Movies, Linux ISOs, and downloaded TV series on my 2 TB drive are not backed up. If that drive dies, it is annoying, not tragic.
- Protect irreplaceable data ruthlessly: My Immich family photo library on my 1 TB drive, my documents, and my Docker
appdata(Compose files,.envsecrets, and database exports) get meticulous backups to a disconnected external hard drive — plus an offsite copy following the full 3-2-1 backup strategy.
What Belongs in Your Rsync Backup Script
Keep your critical data under predictable directories so one script captures everything:
| Source Path | Typical Size | Why It Matters |
|---|---|---|
/opt/docker/ |
200 MB – 5 GB | Your docker-compose.yml, .env files, and app configs |
/mnt/1TB_photos/library/ |
50 GB – 800 GB | Irreplaceable family photos and videos |
/var/backups/databases/ |
50 MB – 500 MB | Clean SQL dumps exported right before rsync starts |
On USB 3.0 to a CMR external HDD (110–140 MB/s), 200 GB of photos takes roughly 30 minutes on day one (compare network vs local speeds in our transfer time calculator). Every nightly run after that transfers only new photos and finishes in under 30 seconds.
Step 1: Prepare the External Backup Drive Cleanly
Format your external drive with ext4 (not NTFS or exFAT, which lose Linux file permissions and ownership). Find its UUID with lsblk -f and mount it in /etc/fstab with nofail so unplugging the drive never stops your server from booting:
UUID=aaaa1111-bbbb-2222-cccc-3333dddd4444 /mnt/external_backup ext4 defaults,noatime,nofail 0 2Create the mount directory and mount it:
sudo mkdir -p /mnt/external_backupsudo mount -aStep 2: Write a Safe Automated Rsync Script
A bare rsync one-liner in crontab has two traps: it won’t dump live databases cleanly, and if the USB drive ever disconnects, rsync will happily write 200 GB straight into your small root SSD until the server crashes.
Put this protected script at /usr/local/sbin/backup-homelab.sh:
sudo nano /usr/local/sbin/backup-homelab.sh#!/bin/bashset -euo pipefail
DEST="/mnt/external_backup/homelab"DB_DUMP_DIR="/var/backups/databases"
# 1. Safety guard: abort immediately if the external drive is not mountedif ! mountpoint -q /mnt/external_backup; then echo "ERROR: /mnt/external_backup is not mounted. Aborting backup." >&2 exit 1fi
mkdir -p "$DB_DUMP_DIR" "$DEST"
# 2. Export live PostgreSQL databases safely (example: Immich / Nextcloud)if docker ps --format '{{.Names}}' | grep -qx 'immich_postgres'; then docker exec immich_postgres pg_dumpall -U postgres > "$DB_DUMP_DIR/immich-$(date +%F).sql"fi
# Keep only the last 7 daily SQL dumpsfind "$DB_DUMP_DIR" -name "*.sql" -type f -mtime +7 -delete
# 3. Sync Docker appdata, database dumps, and family photosrsync -aHAX --delete --info=stats2 \ /opt/docker/ \ "$DEST/docker/"
rsync -aHAX --delete --info=stats2 \ "$DB_DUMP_DIR/" \ "$DEST/databases/"
rsync -aHAX --info=stats2 \ /mnt/1TB_photos/ \ "$DEST/photos/"Notice why the photos line omits --delete: if you accidentally delete a photo folder on your server, --delete won’t wipe your external backup copy on the next run. Lock down permissions on the script so only root can edit it (check octal values in our chmod calculator):
sudo chmod 700 /usr/local/sbin/backup-homelab.shStep 3: Schedule It with Cron
Edit root’s crontab (needed so rsync can read container files owned by different UIDs without permission errors):
sudo crontab -eAdd this line to run every night at 3:30 AM:
30 3 * * * /usr/local/sbin/backup-homelab.sh >> /var/log/homelab-backup.log 2>&1Paste 30 3 * * * into our crontab translator anytime you want to double-check a schedule before trusting it with your backups.
Test once with --dry-run before trusting --delete
Whenever you change paths in anrsync script, run it once manually with –dry-run (-n) added. It prints every file it would copy or delete without touching a single byte on your backup drive.Optional Upgrade: Versioned Daily Snapshots with --link-dest
Want 7 days of browsable snapshots using almost no extra disk space? Add --link-dest to your rsync command pointing at yesterday’s folder. Unchanged files become hard links (0 bytes of duplicate storage), while modified files get stored cleanly in today’s dated directory — giving you instant point-in-time recovery without leaving standard rsync.
And when you are ready for offsite encrypted backups to Backblaze B2 or a remote friend’s server, add restic alongside this local external drive.
Troubleshooting Common Rsync Backup Errors
- The trailing slash
/trap (rsync /opt/dockervs/opt/docker/): adding a trailing slash on the source copies the contents ofdocker/into$DEST/docker/. Leaving it off creates$DEST/docker/docker/. Always be consistent and verify with--dry-run. rsync: chgrp ... failed: Operation not permittedon USB drives: your external drive is still formatted asexFATorNTFS, which do not support Linux POSIX permissions (-a/-HAX). Either reformat the backup drive asext4, or replace-aHAXwith-rlptD --no-perms --no-owner --no-group.- Root SSD suddenly hits 100% full: the external USB drive came unplugged or failed to mount, and the backup script lacked a
mountpoint -qcheck. Runsudo umount /mnt/external_backup(if needed), checkls -la /mnt/external_backupwhile unmounted, delete the accidental local copy inside that mount directory, and always keep themountpoint -qguard in place. docker execfails withpermission deniedor missing container: rundocker psto verify the exact database container name and username before adding it to your script.
Frequently Asked Questions
What is the difference between rsync and restic for home server backups?
rsync creates an exact 1:1 mirror of your folders that you can browse directly in any file manager without special tools, making it ideal for fast local external-drive backups. restic adds encryption, deduplication, and versioned snapshots, making it much better for offsite cloud storage.
Do I really need --delete on my rsync command?
Use --delete carefully. It keeps your backup drive from filling up with old deleted files, but if you accidentally delete a folder on your server before the nightly cron runs, --delete removes it from the backup too. Pairing rsync with --link-dest snapshots or keeping a separate offsite restic repo solves that.
How long does an initial rsync backup take over USB 3.0?
Over USB 3.0 to a spinning external hard drive (~110–140 MB/s), copying 200 GB of family photos and Docker configs takes roughly 25–35 minutes. Subsequent daily runs only copy changed files and usually finish in seconds.
Can I back up live SQLite or PostgreSQL files directly with rsync?
You shouldn't copy raw database data files while the container is writing to them, as that can leave an inconsistent state. Always run pg_dump or sqlite3 .backup into a staging folder right before rsync runs (or pause the container briefly).