From a00237de06e858dc8347f7967e4edf2fca860d0c Mon Sep 17 00:00:00 2001 From: "tommaso.piccioli" Date: Mon, 16 Apr 2018 17:09:18 +0200 Subject: [PATCH] postgres backup, cleanup fixed --- postgresql/files/postgresql-backup.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/postgresql/files/postgresql-backup.sh b/postgresql/files/postgresql-backup.sh index d490992..64d2082 100755 --- a/postgresql/files/postgresql-backup.sh +++ b/postgresql/files/postgresql-backup.sh @@ -41,7 +41,11 @@ create_backup_dirs() { cleanup_old_backups() { # Remove the old backups - find ${HISTDIR} -ctime +$N_DAYS_TO_SPARE -exec rm -f {} \; + TODELETE=`ls /var/lib/pgsql/backups/history | awk -F '.' '{print $NF}' | sort -ruV | tail -n +${N_DAYS_TO_SPARE}` + for i in ${TODELETE} + do + rm -f /var/lib/pgsql/backups/history/*.$i + done } create_db_list() {