From 23b773f0b2855238f985812032c44251f65c9ffe Mon Sep 17 00:00:00 2001 From: Juul Date: Thu, 22 May 2025 18:56:37 +0200 Subject: [PATCH] updated cron script --- files/cron/postgres-backup | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/files/cron/postgres-backup b/files/cron/postgres-backup index 8e4c887..8cab5d2 100644 --- a/files/cron/postgres-backup +++ b/files/cron/postgres-backup @@ -1,16 +1,24 @@ #!/bin/bash +DATABASES=( + "authentik" + "gitea" + "mealie" + "nextcloud" +) + # Variables LOCATION="/home/juulk/docker/postgresql" RETENTION=7 DATE=$(date +"%Y-%m-%d_%H-%M-%S") -FILENAME="backup-$DATE.sql" +BACKUP_DATE="backup-$DATE.sql" -# Dump all databases -docker exec -u postgres postgres pg_dumpall > "$LOCATION/$FILENAME" - -# Zip dump -gzip "$LOCATION/$FILENAME" +# Dump all databases and zip dump +for database in "${DATABASES[@]}"; do + FILE="$LOCATION/$database/$database-$BACKUP_DATE" + docker exec -u postgres postgres pg_dump -d "$database" > "$FILE" + gzip "$FILE" +done # Delete old backups -find "$LOCATION" -name "backup-*.sql.gz" -type f -mtime +$RETENTION -exec rm {} \; \ No newline at end of file +find "$LOCATION" -name "*backup*.sql.gz" -type f -mtime +$RETENTION -exec rm {} \; \ No newline at end of file