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.

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, .env secrets, 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 2

Create the mount directory and mount it:

Terminal window
sudo mkdir -p /mnt/external_backup
sudo mount -a

Step 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:

Terminal window
sudo nano /usr/local/sbin/backup-homelab.sh
#!/bin/bash
set -euo pipefail
DEST="/mnt/external_backup/homelab"
DB_DUMP_DIR="/var/backups/databases"
# 1. Safety guard: abort immediately if the external drive is not mounted
if ! mountpoint -q /mnt/external_backup; then
echo "ERROR: /mnt/external_backup is not mounted. Aborting backup." >&2
exit 1
fi
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 dumps
find "$DB_DUMP_DIR" -name "*.sql" -type f -mtime +7 -delete
# 3. Sync Docker appdata, database dumps, and family photos
rsync -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):

Terminal window
sudo chmod 700 /usr/local/sbin/backup-homelab.sh

Step 3: Schedule It with Cron

Edit root’s crontab (needed so rsync can read container files owned by different UIDs without permission errors):

Terminal window
sudo crontab -e

Add this line to run every night at 3:30 AM:

30 3 * * * /usr/local/sbin/backup-homelab.sh >> /var/log/homelab-backup.log 2>&1

Paste 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 an rsync 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.

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/docker vs /opt/docker/): adding a trailing slash on the source copies the contents of docker/ into $DEST/docker/. Leaving it off creates $DEST/docker/docker/. Always be consistent and verify with --dry-run.
  • rsync: chgrp ... failed: Operation not permitted on USB drives: your external drive is still formatted as exFAT or NTFS, which do not support Linux POSIX permissions (-a / -HAX). Either reformat the backup drive as ext4, or replace -aHAX with -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 -q check. Run sudo umount /mnt/external_backup (if needed), check ls -la /mnt/external_backup while unmounted, delete the accidental local copy inside that mount directory, and always keep the mountpoint -q guard in place.
  • docker exec fails with permission denied or missing container: run docker ps to 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).

Portrait of Guillermo

Written by Guillermo

IT Student & Home Server Enthusiast

Building private clouds to break free from Big Tech. I document everything I learn about home servers and self-hosting on MyHomeServerGuide.

More about the author