Fix backup cron scripts for Kopia password and MariaDB dumps.

Pass KOPIA_REPOSITORY_PASSWORD into snapshot create; use MARIADB_ROOT_PASSWORD for romm and bookstack app user for bookstack root mismatch.
This commit is contained in:
ginnoir
2026-06-10 22:01:26 -05:00
parent 4bb9413391
commit c053f285b8
2 changed files with 18 additions and 5 deletions
+11 -4
View File
@@ -22,16 +22,23 @@ dump_postgres() {
docker exec "${name}" pg_dump -U "${user}" "${db}" | gzip -c > "${DIR}/${name}.sql.gz" docker exec "${name}" pg_dump -U "${user}" "${db}" | gzip -c > "${DIR}/${name}.sql.gz"
} }
# user: root (default) or app account (e.g. bookstack — root password may not match env)
dump_mariadb() { dump_mariadb() {
name="$1" name="$1"
db="$2" db="$2"
user="${3:-root}"
if ! docker ps --format '{{.Names}}' | grep -qx "${name}"; then if ! docker ps --format '{{.Names}}' | grep -qx "${name}"; then
log "skip ${name} (not running)" log "skip ${name} (not running)"
return 0 return 0
fi fi
log "dump ${name}${db}" log "dump ${name}${db} (as ${user})"
docker exec "${name}" sh -c "mariadb-dump -u root -p\"\$MYSQL_ROOT_PASSWORD\" \"${db}\"" \ if [ "${user}" = "root" ]; then
| gzip -c > "${DIR}/${name}.sql.gz" docker exec "${name}" sh -c "mariadb-dump -u root -p\"\${MARIADB_ROOT_PASSWORD:-\$MYSQL_ROOT_PASSWORD}\" \"${db}\"" \
| gzip -c > "${DIR}/${name}.sql.gz"
else
docker exec "${name}" sh -c "mariadb-dump -u \"${user}\" -p\"\${MYSQL_PASSWORD:-\$MARIADB_PASSWORD}\" \"${db}\"" \
| gzip -c > "${DIR}/${name}.sql.gz"
fi
} }
log "starting database dumps → ${DIR}" log "starting database dumps → ${DIR}"
@@ -42,7 +49,7 @@ dump_postgres postgres_authentik authentik authentik
dump_postgres postgres_famapp famapp famapp dump_postgres postgres_famapp famapp famapp
dump_postgres postgres_resume postgres postgres dump_postgres postgres_resume postgres postgres
dump_mariadb mariadb_bookstack bookstack dump_mariadb mariadb_bookstack bookstack bookstack
dump_mariadb owncloud_mariadb owncloud dump_mariadb owncloud_mariadb owncloud
dump_mariadb romm-db romm dump_mariadb romm-db romm
@@ -5,6 +5,7 @@ set -eu
NTFY_URL="${NTFY_URL:-https://ntfy.ginnoir.com/backup}" NTFY_URL="${NTFY_URL:-https://ntfy.ginnoir.com/backup}"
NTFY_TITLE="${NTFY_TITLE:-ValhallaBackup}" NTFY_TITLE="${NTFY_TITLE:-ValhallaBackup}"
KOPIA_PASSWORD="${KOPIA_REPOSITORY_PASSWORD:-${KOPIA_PASSWORD:-}}"
notify() { notify() {
priority="$1" priority="$1"
@@ -12,6 +13,11 @@ notify() {
curl -sf -H "Title: ${NTFY_TITLE}" -H "Priority: ${priority}" -d "${message}" "${NTFY_URL}" >/dev/null 2>&1 || true curl -sf -H "Title: ${NTFY_TITLE}" -H "Priority: ${priority}" -d "${message}" "${NTFY_URL}" >/dev/null 2>&1 || true
} }
if [ -z "${KOPIA_PASSWORD}" ]; then
notify high "KOPIA_REPOSITORY_PASSWORD not set — snapshots skipped"
exit 1
fi
if ! docker ps --format '{{.Names}}' | grep -qx kopia; then if ! docker ps --format '{{.Names}}' | grep -qx kopia; then
notify high "Kopia container not running — snapshots skipped" notify high "Kopia container not running — snapshots skipped"
exit 1 exit 1
@@ -20,7 +26,7 @@ fi
FAILED=0 FAILED=0
while IFS= read -r path || [ -n "${path}" ]; do while IFS= read -r path || [ -n "${path}" ]; do
case "${path}" in ''|\#*) continue ;; esac case "${path}" in ''|\#*) continue ;; esac
if ! docker exec kopia kopia snapshot create "${path}"; then if ! docker exec -e KOPIA_PASSWORD="${KOPIA_PASSWORD}" kopia kopia snapshot create "${path}"; then
FAILED=1 FAILED=1
fi fi
done < /snapshot-paths.txt done < /snapshot-paths.txt