diff options
| author | Ahmed Abdelhalim <[email protected]> | 2026-07-21 12:41:07 +0200 |
|---|---|---|
| committer | Ahmed Abdelhalim <[email protected]> | 2026-07-21 12:46:53 +0200 |
| commit | 0be7583911bfe15276b736697caebb3752da56b6 (patch) | |
| tree | 869bbd8b270f22c6c02460b20d3146dcc04e5be3 /roles/backup/templates/backup-openrc.sh.j2 | |
| parent | 34157b435c2103ecb87c26c1368c6ccf7b3d6410 (diff) | |
Fix restic install and add backup role
Co-Authored-By: Claude.ai
Diffstat (limited to 'roles/backup/templates/backup-openrc.sh.j2')
| -rw-r--r-- | roles/backup/templates/backup-openrc.sh.j2 | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/roles/backup/templates/backup-openrc.sh.j2 b/roles/backup/templates/backup-openrc.sh.j2 new file mode 100644 index 00000000..85dc8d1e --- /dev/null +++ b/roles/backup/templates/backup-openrc.sh.j2 @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -euo pipefail + +# shellcheck source=/dev/null +source "/etc/credstore/{{ backup_name }}-backup.env" + +export RESTIC_REPOSITORY="${BACKUP_REPO}" +export RESTIC_PASSWORD="${BACKUP_PASSWORD}" +export AWS_ACCESS_KEY_ID="${BACKUP_ACCESS_KEY_ID}" +export AWS_SECRET_ACCESS_KEY="${BACKUP_SECRET_ACCESS_KEY}" +export CACHE_DIR="/var/cache/{{ backup_name }}-backup" + +# -p (--preserve-environment) -s (--shell): busybox su has no long-form flags +exec su -p -s /bin/sh {{ backup_user }} <<'BACKUP_SU_EOF' +restic --cache-dir "$CACHE_DIR" snapshots &>/dev/null || restic --cache-dir "$CACHE_DIR" init + +restic --cache-dir "$CACHE_DIR" backup {{ backup_paths | map('quote') | join(' ') }} + +restic --cache-dir "$CACHE_DIR" forget \ + --keep-daily {{ backup_retention_daily }} \ + --keep-weekly {{ backup_retention_weekly }} \ + --keep-monthly {{ backup_retention_monthly }} \ + --prune +BACKUP_SU_EOF |
