- scripts/cron_backup_restore_test.sh: Velero restore dry-run 腳本 - k8s/awoooi-prod/16-cronjob-backup-restore-test.yaml: 每週日 02:00 台北執行 - k8s/awoooi-prod/17-configmap-backup-restore-scripts.yaml: 腳本 ConfigMap - flywheel-alerts.yaml: BackupRestoreTestFailed + BackupRestoreTestStale 告警 失敗時寫入 node-exporter textfile → Prometheus 告警 → TYPE-3 Incident 2026-04-12 ogt (ADR-074 M4) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
50 lines
2.2 KiB
YAML
50 lines
2.2 KiB
YAML
# =============================================================================
|
|
# ConfigMap: backup-restore-test-scripts — ADR-074 M4
|
|
# =============================================================================
|
|
# 掛載備份還原驗證腳本到 CronJob Pod
|
|
#
|
|
# 2026-04-12 ogt (ADR-074 M4)
|
|
# =============================================================================
|
|
|
|
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
name: backup-restore-test-scripts
|
|
namespace: velero
|
|
labels:
|
|
app: awoooi
|
|
component: backup-restore-test
|
|
adr: "074-m4"
|
|
data:
|
|
cron_backup_restore_test.sh: |
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
TEXTFILE="/var/lib/node_exporter/textfile_collector/backup_restore_test.prom"
|
|
NAMESPACE="${VELERO_NAMESPACE:-velero}"
|
|
BACKUP_NAME="${VELERO_BACKUP_NAME:-awoooi-daily}"
|
|
EXIT_CODE=0
|
|
|
|
echo "=== backup-restore-test: $(date '+%Y-%m-%d %H:%M:%S %Z') ==="
|
|
echo "Backup: ${BACKUP_NAME} Namespace: ${NAMESPACE}"
|
|
|
|
velero restore create \
|
|
--from-backup "${BACKUP_NAME}" \
|
|
--namespace-mappings "${NAMESPACE}:restore-test-dry" \
|
|
--dry-run \
|
|
--wait \
|
|
2>&1 || EXIT_CODE=$?
|
|
|
|
TS=$(date +%s%3N)
|
|
mkdir -p "$(dirname "${TEXTFILE}")"
|
|
|
|
if [ "${EXIT_CODE}" -eq 0 ]; then
|
|
echo "backup restore dry-run OK"
|
|
printf '# HELP awoooi_backup_restore_test_success 1 = last backup restore dry-run succeeded\n# TYPE awoooi_backup_restore_test_success gauge\nawoooi_backup_restore_test_success 1 %s\n# HELP awoooi_backup_restore_test_timestamp_seconds Unix timestamp of last test run\n# TYPE awoooi_backup_restore_test_timestamp_seconds gauge\nawoooi_backup_restore_test_timestamp_seconds %s %s\n' "${TS}" "$(date +%s)" "${TS}" > "${TEXTFILE}"
|
|
exit 0
|
|
else
|
|
echo "backup restore dry-run FAILED (exit ${EXIT_CODE})"
|
|
printf '# HELP awoooi_backup_restore_test_success 1 = last backup restore dry-run succeeded\n# TYPE awoooi_backup_restore_test_success gauge\nawoooi_backup_restore_test_success 0 %s\n# HELP awoooi_backup_restore_test_timestamp_seconds Unix timestamp of last test run\n# TYPE awoooi_backup_restore_test_timestamp_seconds gauge\nawoooi_backup_restore_test_timestamp_seconds %s %s\n' "${TS}" "$(date +%s)" "${TS}" > "${TEXTFILE}"
|
|
exit 1
|
|
fi
|