Update backup script to include everything needed to do a bare metal restore of the new V6 server
Quality Gate / gate (push) Failing after 49s

This commit is contained in:
Jim Lancaster
2026-08-26 12:21:40 -05:00
parent 2c6ef46f5f
commit 89ed83239e
5 changed files with 88 additions and 14 deletions
+38 -5
View File
@@ -8,19 +8,52 @@ RETENTION_DAYS="${BACKUP_RETENTION_DAYS:-14}"
SYNOLOGY_BACKUP_DIR="${SYNOLOGY_BACKUP_DIR:-}"
timestamp="$(date -u +%Y%m%d-%H%M%S)"
backup_file="postgres-${timestamp}.dump"
postgres_file="postgres-${timestamp}.dump"
uploads_file="uploads-${timestamp}.tar.gz"
config_file="config-${timestamp}.tar.gz"
manifest_file="backup-${timestamp}.manifest"
mkdir -p "${BACKUP_DIR}"
docker compose --env-file "${ENV_FILE}" -f "${COMPOSE_FILE}" exec -T postgres sh -lc \
"PGPASSWORD=\"\$POSTGRES_PASSWORD\" pg_dump -U \"\$POSTGRES_USER\" -d \"\$POSTGRES_DB\" -Fc" \
> "${BACKUP_DIR}/${backup_file}"
> "${BACKUP_DIR}/${postgres_file}"
find "${BACKUP_DIR}" -type f -name 'postgres-*.dump' -mtime +"${RETENTION_DAYS}" -delete
docker compose --env-file "${ENV_FILE}" -f "${COMPOSE_FILE}" run --rm --no-deps --entrypoint sh app -lc \
"tar -C /app/uploads -czf - ." \
> "${BACKUP_DIR}/${uploads_file}"
tar -C . -czf "${BACKUP_DIR}/${config_file}" \
"${ENV_FILE}" \
"${COMPOSE_FILE}" \
deploy/cloudflared/config.yml
cat > "${BACKUP_DIR}/${manifest_file}" <<EOF
created_at_utc=${timestamp}
postgres_dump=${postgres_file}
uploads_archive=${uploads_file}
config_archive=${config_file}
compose_file=${COMPOSE_FILE}
env_file=${ENV_FILE}
EOF
find "${BACKUP_DIR}" -type f \( \
-name 'postgres-*.dump' -o \
-name 'uploads-*.tar.gz' -o \
-name 'config-*.tar.gz' -o \
-name 'backup-*.manifest' \
\) -mtime +"${RETENTION_DAYS}" -delete
if [ -n "${SYNOLOGY_BACKUP_DIR}" ]; then
mkdir -p "${SYNOLOGY_BACKUP_DIR}"
cp "${BACKUP_DIR}/${backup_file}" "${SYNOLOGY_BACKUP_DIR}/${backup_file}"
cp "${BACKUP_DIR}/${postgres_file}" "${SYNOLOGY_BACKUP_DIR}/${postgres_file}"
cp "${BACKUP_DIR}/${uploads_file}" "${SYNOLOGY_BACKUP_DIR}/${uploads_file}"
cp "${BACKUP_DIR}/${config_file}" "${SYNOLOGY_BACKUP_DIR}/${config_file}"
cp "${BACKUP_DIR}/${manifest_file}" "${SYNOLOGY_BACKUP_DIR}/${manifest_file}"
fi
echo "Created backup: ${BACKUP_DIR}/${backup_file}"
echo "Created backup set:"
echo " ${BACKUP_DIR}/${postgres_file}"
echo " ${BACKUP_DIR}/${uploads_file}"
echo " ${BACKUP_DIR}/${config_file}"
echo " ${BACKUP_DIR}/${manifest_file}"
+31
View File
@@ -15,6 +15,22 @@ if [ ! -f "${dump_file}" ]; then
exit 1
fi
backup_dir="$(dirname "${dump_file}")"
backup_name="$(basename "${dump_file}")"
timestamp="$(printf '%s' "${backup_name}" | sed -n 's/^postgres-\([0-9]\{8\}-[0-9]\{6\}\)\.dump$/\1/p')"
uploads_file=""
config_file=""
if [ -n "${timestamp}" ]; then
candidate_uploads="${backup_dir}/uploads-${timestamp}.tar.gz"
candidate_config="${backup_dir}/config-${timestamp}.tar.gz"
if [ -f "${candidate_uploads}" ]; then
uploads_file="${candidate_uploads}"
fi
if [ -f "${candidate_config}" ]; then
config_file="${candidate_config}"
fi
fi
docker compose --env-file "${ENV_FILE}" -f "${COMPOSE_FILE}" exec -T postgres sh -lc \
"PGPASSWORD=\"\$POSTGRES_PASSWORD\" psql -U \"\$POSTGRES_USER\" -d postgres -c \"DROP DATABASE IF EXISTS \\\"\$POSTGRES_DB\\\";\""
@@ -24,4 +40,19 @@ docker compose --env-file "${ENV_FILE}" -f "${COMPOSE_FILE}" exec -T postgres sh
cat "${dump_file}" | docker compose --env-file "${ENV_FILE}" -f "${COMPOSE_FILE}" exec -T postgres sh -lc \
"PGPASSWORD=\"\$POSTGRES_PASSWORD\" pg_restore -U \"\$POSTGRES_USER\" -d \"\$POSTGRES_DB\" --clean --if-exists --no-owner --no-privileges"
if [ -n "${uploads_file}" ]; then
cat "${uploads_file}" | docker compose --env-file "${ENV_FILE}" -f "${COMPOSE_FILE}" run --rm --no-deps --entrypoint sh app -lc \
"mkdir -p /app/uploads && find /app/uploads -mindepth 1 -delete && tar -xzf - -C /app/uploads"
fi
if [ -n "${config_file}" ]; then
tar -xzf "${config_file}" -C .
fi
echo "Restore complete from: ${dump_file}"
if [ -n "${uploads_file}" ]; then
echo "Restored uploads archive: ${uploads_file}"
fi
if [ -n "${config_file}" ]; then
echo "Restored config archive: ${config_file}"
fi