forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify-backup.sh
More file actions
executable file
路42 lines (33 loc) 路 1.09 KB
/
Copy pathverify-backup.sh
File metadata and controls
executable file
路42 lines (33 loc) 路 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env bash
set -euo pipefail
BACKUP_FILE="${1:-}"
TEST_DB_URL="${TEST_DB_URL:-postgres://postgres:postgres@localhost:5432/gistpin_backup_test}"
SQL_CHECKS="infrastructure/ci/backup-tests/integrity-checks.sql"
if [[ -z "${BACKUP_FILE}" ]]; then
echo "Usage: verify-backup.sh <backup-file.sql>"
exit 1
fi
if [[ ! -f "${BACKUP_FILE}" ]]; then
echo "Backup file not found: ${BACKUP_FILE}"
exit 1
fi
if [[ ! -f "${SQL_CHECKS}" ]]; then
echo "SQL checks file not found: ${SQL_CHECKS}"
exit 1
fi
createdb "${TEST_DB_URL##*/}" >/dev/null 2>&1 || true
psql "${TEST_DB_URL}" -f "${BACKUP_FILE}" >/tmp/backup-restore.log
psql "${TEST_DB_URL}" -f "${SQL_CHECKS}" >/tmp/backup-integrity.log
if ! grep -q "user_count" /tmp/backup-integrity.log; then
echo "Integrity check failed: users count missing"
exit 1
fi
if ! grep -q "gist_count" /tmp/backup-integrity.log; then
echo "Integrity check failed: gists count missing"
exit 1
fi
if ! grep -q "comment_count" /tmp/backup-integrity.log; then
echo "Integrity check failed: comments count missing"
exit 1
fi
echo "Backup verification passed"