Files
awoooi/scripts/backup/enforce-latest-only-retention.sh
Your Name e614f061f7
Some checks failed
CD Pipeline / select-latest-carrier (push) Successful in 49s
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 2m28s
CD Pipeline / revalidate-deploy-carrier (push) Successful in 27s
CD Pipeline / build-and-deploy (push) Failing after 17m18s
CD Pipeline / revalidate-post-deploy-carrier (push) Has been skipped
CD Pipeline / post-deploy-checks (push) Has been skipped
E2E Health Check / e2e-health (push) Successful in 48s
AI 技術雷達監控 / ai-technology-watch (push) Successful in 1m4s
AWOOOI Harbor 110 Local Repair / workflow-shape (push) Successful in 0s
AWOOOI Harbor 110 Local Repair / harbor-110-local-repair (push) Successful in 22s
fix(backup): verify host188 recovery end to end
2026-07-18 19:12:42 +08:00

45 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# =============================================================================
# AWOOOI backup retention enforcer
#
# Operator policy: each backup repository keeps only the latest successful copy.
# This script is safe to run after backup jobs have succeeded; it never creates
# a snapshot and never touches production data, only restic repository metadata.
# =============================================================================
set -euo pipefail
source "$(dirname "$0")/common.sh"
EXPECTED_REPOS_DEFAULT="awoooi configs gitea harbor momo langfuse monitoring signoz open-webui clawbot sentry ai-artifacts public-routes host188-products"
REPOS="${BACKUP_RETENTION_REPOS:-${EXPECTED_REPOS_DEFAULT}}"
KEEP_LAST="${BACKUP_KEEP_LAST:-1}"
main() {
local failed=0
log_info "========== Latest-only retention enforcement start (keep-last=${KEEP_LAST}) =========="
for name in ${REPOS}; do
local repo="${BACKUP_BASE}/${name}"
if [ ! -d "${repo}/data" ]; then
log_warn "跳過未初始化 repo: ${repo}"
continue
fi
log_info "Enforce latest-only retention: ${name}"
if ! BACKUP_RETENTION_MODE=latest BACKUP_KEEP_LAST="${KEEP_LAST}" \
cleanup_old_backups "${repo}"; then
failed=$((failed + 1))
fi
done
if [ "${failed}" -eq 0 ]; then
log_success "========== Latest-only retention enforcement complete =========="
else
log_error "========== Latest-only retention enforcement failed: ${failed} repo(s) =========="
fi
return "${failed}"
}
main "$@"