-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup_full.sh
More file actions
executable file
·34 lines (28 loc) · 845 Bytes
/
backup_full.sh
File metadata and controls
executable file
·34 lines (28 loc) · 845 Bytes
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
#!/bin/bash
set -euo pipefail
BACKUP_SUBDIR="${BACKUP_SUBDIR:-}"
if [ -n "$BACKUP_SUBDIR" ]; then
BASE_BACKUP_DIR="/backups/$BACKUP_SUBDIR"
else
BASE_BACKUP_DIR="/backups"
fi
DATE=$(date +%F_%H-%M-%S)
DEST_DIR="$BASE_BACKUP_DIR/full/$DATE"
if ! mkdir -p "$DEST_DIR"; then
echo "[ERROR] Failed to create directory $DEST_DIR"
exit 1
fi
export PGPASSWORD=$(cat $PGPASSWORD_FILE)
echo "[INFO] Performing full backup..."
if ! pg_dump -h "${POSTGRES_HOST}" \
-p "${POSTGRES_PORT}" \
-U "${POSTGRES_USER}" \
"${POSTGRES_DB}" | gzip > "$DEST_DIR/$BACKUP_NAME.gz"; then
echo "[ERROR] $1"
exit 1
fi
# Apply retention
if ! find "$BASE_BACKUP_DIR/full" -type d -mtime +"${RETENTION_FULL_DAYS}" -exec rm -rf {} +; then
echo "[WARNING] Retention cleanup failed"
fi
echo "[INFO] Full backup completed."