#!/usr/bin/env bash # Backup the home directory to a remote SSH location using rsync. # # Excludes large, regenerable, or already-replicated data (caches, trash, # build artifacts, git checkouts, syncthing, media libraries, VM images, # etc.). See the EXCLUDES array below for the full list. # # Usage: # home-backup # Run the backup (real run) # home-backup -n # Dry run (show what would transfer) # home-backup -d user@host:/path/backup # Override destination # # The destination can also be set via the BACKUP_DEST environment variable. set -euo pipefail declare -r PROGRAM=${0##*/} # Remote SSH destination. Defaults to the encrypted ZFS dataset on f2 # (zdata/enc/earth-backup, inherits aes-256-gcm encryption from zdata/enc). # Override with the BACKUP_DEST env var or the -d flag. declare DEST=${BACKUP_DEST:-"paul@f2.lan:/data/enc/earth-backup"} # Source directory (trailing slash matters for rsync: copy contents of $HOME). declare -r SRC="$HOME/" declare DRY_RUN="" # Paths/patterns to exclude from the backup. Patterns are relative to $HOME. declare -ra EXCLUDES=( # --- Explicitly excluded by request --- "/git/" "/syncthing/" "/Pictures/" "/Music/" "/.gradle/" "/.thunderbird/" # --- Caches / trash / regenerable data --- "/.cache/" "/.local/share/Trash/" "/.local/share/baloo/" "/.local/share/containers/" "/.local/share/gnome-boxes/" "/.npm/" "/go/" "/.cargo/" "/.bun/" "/.android/" # --- Common regenerable junk anywhere in the tree --- "node_modules/" ".cache/" "*.tmp" "/.var/app/*/cache/" # --- Runtime / volatile --- "/.gvfs/" "/.dbus/" ) log() { printf '%s\n' "$*" } error() { log "$*" >&2 } usage() { cat <