diff --git a/Dockerfile b/Dockerfile index 4185c0b..9a3fc87 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ RUN localedef -i fr_FR -c -f UTF-8 -A /usr/share/locale/locale.alias fr_FR.UTF-8 RUN apt update && apt install pgtop ENV LANG fr_FR.utf8 +ENV PURGE_OLD false ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/backup-database.sh b/backup-database.sh index c8a6489..ae1a24b 100755 --- a/backup-database.sh +++ b/backup-database.sh @@ -6,6 +6,13 @@ fileDt=$(date '+%d_%m_%Y_%H_%M_%S'); backUpFileName="postgres-backup-$fileDt.gz" backUpFilePath="$BACKUP_DESTINATION_FOLDER/$backUpFileName" +if $PURGE_OLD; then DRY_RUN=false; else DRY_RUN=true; fi +echo "Following file are older than 14 day, it will be deleted (dry-run $DRY_RUN)" +find /var/lib/backup/ -type f -mtime +14 -name '*.gz' -execdir ls -- '{}' \; +if [ $PURGE_OLD = true ]; then + find /var/lib/backup/ -type f -mtime +14 -name '*.gz' -execdir rm -- '{}' \; +fi + echo "$dt - Starting DB backup into file: $backUpFilePath"; echo "$dt - Running: pg_dumpall -h $BACKUP_SOURCE_DB_HOST_NAME -U $POSTGRES_USER -c | gzip > $backUpFilePath"