added the official docker cli
All checks were successful
Build and Push Docker Image / build (push) Successful in 39s
All checks were successful
Build and Push Docker Image / build (push) Successful in 39s
-switched to user 1000 for security. -added user to docker group -properly mounted btrfs drive on host allows users to create snapshots
This commit is contained in:
17
backup.sh
17
backup.sh
@@ -4,7 +4,6 @@
|
||||
# Author: Calahil Studios
|
||||
|
||||
# === CONFIGURATION ===
|
||||
LOG_FILE="$1"
|
||||
BACKUP_DIR="/backups/postgres_dumps"
|
||||
RETENTION_DAYS="${RETENTION_DAYS:-7}" # Keep 7 days of backups
|
||||
|
||||
@@ -19,12 +18,12 @@ ghcr.io/immich-app/postgres:14-vectorchord0.4.3-pgvectors0.2.0
|
||||
EOF
|
||||
)
|
||||
|
||||
echo "[BACKUPBOT_INFO] Starting PostgreSQL backup service..." | tee -a "$LOG_FILE"
|
||||
echo "[BACKUPBOT_INFO] Starting PostgreSQL backup service..."
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
|
||||
TIMESTAMP=$(date +'%Y-%m-%d_%H-%M-%S')
|
||||
echo "[BACKUPBOT_INFO] $(date) - Starting backup cycle ($TIMESTAMP)" | tee -a "$LOG_FILE"
|
||||
echo "[BACKUPBOT_INFO] Checking for running Postgres containers..." | tee -a "$LOG_FILE"
|
||||
echo "[BACKUPBOT_INFO] $(date) - Starting backup cycle ($TIMESTAMP)"
|
||||
echo "[BACKUPBOT_INFO] Checking for running Postgres containers..."
|
||||
|
||||
# Find running containers matching known image names
|
||||
MATCHING_CONTAINERS=$(
|
||||
@@ -41,7 +40,7 @@ MATCHING_CONTAINERS=$(
|
||||
)
|
||||
|
||||
if [ -z "$MATCHING_CONTAINERS" ]; then
|
||||
echo "[BACKUPBOT_WARN] No Postgres containers found." | tee -a "$LOG_FILE"
|
||||
echo "[BACKUPBOT_WARN] No Postgres containers found."
|
||||
else
|
||||
for container in $MATCHING_CONTAINERS; do
|
||||
NAME=$(docker inspect --format '{{.Name}}' "$container" | sed 's#^/##')
|
||||
@@ -54,16 +53,16 @@ else
|
||||
PG_USER=$(docker inspect --format '{{range .Config.Env}}{{println .}}{{end}}' "$container" | grep POSTGRES_USER | cut -d= -f2)
|
||||
PG_PASS=$(docker inspect --format '{{range .Config.Env}}{{println .}}{{end}}' "$container" | grep POSTGRES_PASSWORD | cut -d= -f2)
|
||||
if docker exec -e PGPASSWORD="$PG_PASS" "$container" pg_dumpall -U "$PG_USER" -h 127.0.0.1 >"$FILE" 2>/tmp/pg_backup_error.log; then
|
||||
echo "[BACKUPBOT_SUCCESS] Backup complete for $NAME -> $FILE" | tee -a "$LOG_FILE"
|
||||
echo "[BACKUPBOT_SUCCESS] Backup complete for $NAME -> $FILE"
|
||||
else
|
||||
echo "[BACKUPBOT_ERROR] Backup failed for $NAME (check /tmp/pg_backup_error.log)" | tee -a "$LOG_FILE"
|
||||
echo "[BACKUPBOT_ERROR] Backup failed for $NAME (check /tmp/pg_backup_error.log)"
|
||||
fi
|
||||
# Retention cleanup
|
||||
find "$CONTAINER_BACKUP_DIR" -type f -mtime +$RETENTION_DAYS -name '*.sql' -delete
|
||||
done
|
||||
fi
|
||||
|
||||
echo "[BACKUPBOT_INFO] Creating a snapshot of /srv/appdata" | tee -a "$LOG_FILE"
|
||||
echo "[BACKUPBOT_INFO] Creating a snapshot of /srv/appdata"
|
||||
btrfs subvolume snapshot -r /source/appdata /backups/snapshots/$(hostname)-$(date +%F)
|
||||
|
||||
echo "[BACKUPBOT_INFO] Backup cycle complete." | tee -a "$LOG_FILE"
|
||||
echo "[BACKUPBOT_INFO] Backup cycle complete."
|
||||
|
||||
Reference in New Issue
Block a user