Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ansible/tasks/paperless_backup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
#
# IMPORTANT: Also save the restic password in 1Password — lose it and backups are unrecoverable.
#
# Optional but recommended: a healthchecks.io dead-man's-switch so a silently
# broken or unscheduled backup job (e.g. the LaunchAgent never getting loaded)
# gets flagged, not just script errors. Create a free check at
# https://healthchecks.io with a 24h period matching the daily 3am schedule
# (a few hours of grace time), then store its ping URL:
#
# security add-generic-password -a $USER -s paperless-backup-healthcheck-url -w 'https://hc-ping.com/<uuid>'
#
# If this isn't set, backup.sh just skips the ping and runs as before.
#
# Then initialise the restic repo once:
# set -x B2_ACCOUNT_ID (security find-generic-password -a $USER -s paperless-backup-b2-id -w)
# set -x B2_ACCOUNT_KEY (security find-generic-password -a $USER -s paperless-backup-b2-key -w)
Expand Down
14 changes: 14 additions & 0 deletions paperless-ngx/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ log() {
echo "[$(date '+%Y-%m-%dT%H:%M:%S')] $*" | tee -a "$LOG_FILE"
}

HEALTHCHECK_PING_URL=$(security find-generic-password -a "$USER" -s paperless-backup-healthcheck-url -w 2>/dev/null || true)

ping_healthcheck() {
[ -z "$HEALTHCHECK_PING_URL" ] && return 0
curl -fsS -m 10 --retry 3 -o /dev/null "${HEALTHCHECK_PING_URL}${1:-}" || true
}

on_error() {
log "Paperless backup failed"
ping_healthcheck /fail
}
trap on_error ERR

log "Starting paperless backup"

export B2_ACCOUNT_ID
Expand All @@ -34,3 +47,4 @@ log "Pruning old snapshots"
restic -r b2:mb-paperless-backup:paperless forget --keep-daily 7 --keep-weekly 2 --keep-monthly 2 --prune

log "Paperless backup complete"
ping_healthcheck
Loading