backup-relay.sh now pushes the archive to restic.env AND, if present, restic-2.env — so adding an R2/B2 bucket gives true 3-2-1 (local + CVM + object storage) instead of replacing one offsite with another. Each repo is sourced in its own subshell so RESTIC_* don't leak between them. Verified with a throwaway local second repo: both pushes ran, both snapshots exist. Also documents the umask trap (mode-600 cache dirs break restic).
59 lines
2 KiB
Bash
Executable file
59 lines
2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
#
|
|
# Weekly SkateSpots relay archive + optional offsite copy.
|
|
#
|
|
# Driven by the systemd user timer `skatespots-archive.timer` (install with
|
|
# scripts/install-archive-timer.sh). Local archives land in
|
|
# ~/.backups/relay; if ~/.config/skatespots/restic.env exists, the whole
|
|
# directory is pushed to a restic repository (S3/R2/B2/SFTP) and old snapshots
|
|
# are pruned. Without that file the archive is local-only — still useful, but
|
|
# not a real offsite backup.
|
|
#
|
|
# Manual run / debug:
|
|
# scripts/backup-relay.sh
|
|
# journalctl --user -u skatespots-archive -n 50
|
|
set -euo pipefail
|
|
|
|
REPO="/home/sovereignsk8/SkateSpots"
|
|
# systemd runs with a minimal PATH; node lives under nvm here.
|
|
export PATH="/home/sovereignsk8/.nvm/versions/node/v22.23.1/bin:$PATH"
|
|
|
|
ARCHIVE_DIR="${SKATESPOTS_ARCHIVE_DIR:-$HOME/.backups/relay}"
|
|
RESTIC_ENV="$HOME/.config/skatespots/restic.env"
|
|
# Optional SECOND offsite (e.g. an R2/B2 bucket) so we get true 3-2-1: local +
|
|
# CVM host + object storage. Same format as restic.env.
|
|
RESTIC_ENV_2="$HOME/.config/skatespots/restic-2.env"
|
|
|
|
log() { echo "[$(date -Is)] $*"; }
|
|
|
|
mkdir -p "$ARCHIVE_DIR"
|
|
cd "$REPO"
|
|
|
|
log "archiving the community relay…"
|
|
node scripts/archive-relay.mjs
|
|
|
|
# Push the archive directory to every configured restic repo. Each is sourced in
|
|
# its own subshell so RESTIC_* variables don't leak between destinations.
|
|
copy_offsite() {
|
|
local envfile="$1"
|
|
[ -f "$envfile" ] || return 0
|
|
(
|
|
set -a; . "$envfile"; set +a
|
|
if [ -z "${RESTIC_REPOSITORY:-}" ]; then
|
|
log " $(basename "$envfile"): no RESTIC_REPOSITORY — skipping"
|
|
exit 0
|
|
fi
|
|
log " → $RESTIC_REPOSITORY"
|
|
restic backup --tag skatespots-relay "$ARCHIVE_DIR"
|
|
restic forget --tag skatespots-relay --keep-last 12 --prune
|
|
)
|
|
}
|
|
|
|
if [ -f "$RESTIC_ENV" ] || [ -f "$RESTIC_ENV_2" ]; then
|
|
log "pushing offsite copies…"
|
|
copy_offsite "$RESTIC_ENV"
|
|
copy_offsite "$RESTIC_ENV_2"
|
|
log "offsite copies done"
|
|
else
|
|
log "no $RESTIC_ENV — archive kept local-only (set one up for a real offsite backup)"
|
|
fi
|