mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-22 19:25:56 +00:00
feat(phase15): release and security hardening, DPAPI key store, probe & protocol hardening, secret redaction, audit and readiness report
This commit is contained in:
1 parent
b69fa6b867
commit
51e0f136d6
207 files changed
+38235
-7770
No files matched your search
@@ -0,0 +1,40 @@
|
||||
#!/bin/sh
|
||||
# /opt/coa/registry/backup-db.sh
|
||||
# Production logical database backup with retention and atomic completion marker.
|
||||
# Run on the node: sudo sh backup-db.sh
|
||||
set -eu
|
||||
|
||||
BACKUP_DIR="${BACKUP_DIR:-/opt/coa/backups}"
|
||||
RETENTION_DAYS="${RETENTION_DAYS:-14}"
|
||||
TIMESTAMP=$(date -u +"%Y%m%d_%H%M%SZ")
|
||||
TARGET_FILE="${BACKUP_DIR}/coa_registry_${TIMESTAMP}.dump"
|
||||
TMP_FILE="${TARGET_FILE}.tmp"
|
||||
MARKER_FILE="${TARGET_FILE}.complete"
|
||||
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
chmod 700 "$BACKUP_DIR"
|
||||
|
||||
echo "[INFO] Starting database backup for coa_registry to ${TARGET_FILE}..."
|
||||
|
||||
# Execute pg_dump inside postgres container into temp file
|
||||
docker exec -i coa-postgres-postgres-1 sh -c 'PGPASSWORD=$(cat /run/secrets/postgres_password) exec pg_dump -U coa -d coa_registry --format=custom --blobs' > "$TMP_FILE"
|
||||
|
||||
# Verify dump file is non-empty
|
||||
FILE_SIZE=$(wc -c < "$TMP_FILE" || stat -c%s "$TMP_FILE" 2>/dev/null || echo 0)
|
||||
if [ "$FILE_SIZE" -lt 1024 ]; then
|
||||
echo "[ERROR] Backup failed or file too small (${FILE_SIZE} bytes)" >&2
|
||||
rm -f "$TMP_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Atomic commit
|
||||
mv "$TMP_FILE" "$TARGET_FILE"
|
||||
sha256sum "$TARGET_FILE" > "${TARGET_FILE}.sha256"
|
||||
touch "$MARKER_FILE"
|
||||
|
||||
echo "[INFO] Backup completed successfully: ${TARGET_FILE} (${FILE_SIZE} bytes)"
|
||||
|
||||
# Retention pruning
|
||||
echo "[INFO] Pruning backups older than ${RETENTION_DAYS} days..."
|
||||
find "$BACKUP_DIR" -name "coa_registry_*.dump" -mtime +"$RETENTION_DAYS" -exec rm -f {} {}.sha256 {}.complete \; 2>/dev/null || true
|
||||
echo "[INFO] Backup rotation complete."
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/bin/sh
|
||||
# /opt/coa/registry/restore-db.sh
|
||||
# Production database restore from an existing backup dump file.
|
||||
# Usage: sudo sh restore-db.sh /opt/coa/backups/coa_registry_YYYYMMDD_HHMMSSZ.dump
|
||||
set -eu
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "Usage: $0 <path_to_backup_dump>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BACKUP_FILE="$1"
|
||||
|
||||
if [ ! -f "$BACKUP_FILE" ]; then
|
||||
echo "[ERROR] Backup file not found: $BACKUP_FILE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Verify checksum if present
|
||||
if [ -f "${BACKUP_FILE}.sha256" ]; then
|
||||
echo "[INFO] Verifying backup checksum..."
|
||||
sha256sum -c "${BACKUP_FILE}.sha256"
|
||||
fi
|
||||
|
||||
echo "[WARNING] Restoring database coa_registry from $BACKUP_FILE. Existing connections will be terminated."
|
||||
read -p "Type 'RESTORE' to proceed: " CONFIRM
|
||||
if [ "$CONFIRM" != "RESTORE" ]; then
|
||||
echo "[INFO] Restore aborted."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Terminate existing connections to coa_registry
|
||||
docker exec -i coa-postgres-postgres-1 sh -c 'PGPASSWORD=$(cat /run/secrets/postgres_password) exec psql -U coa -d coa -v ON_ERROR_STOP=1 -q' <<SQL
|
||||
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'coa_registry' AND pid <> pg_backend_pid();
|
||||
SQL
|
||||
|
||||
# Restore dump
|
||||
docker exec -i coa-postgres-postgres-1 sh -c 'PGPASSWORD=$(cat /run/secrets/postgres_password) exec pg_restore -U coa -d coa_registry --clean --if-exists --no-owner' < "$BACKUP_FILE"
|
||||
|
||||
echo "[INFO] Database restore completed successfully from $BACKUP_FILE."
|
||||
Reference in new issue
Block a user