diff --git a/templates/postgresql-backup.sh.j2 b/templates/postgresql-backup.sh.j2 index 082fdde..a1c8e3e 100755 --- a/templates/postgresql-backup.sh.j2 +++ b/templates/postgresql-backup.sh.j2 @@ -46,12 +46,13 @@ create_backup_dirs() { cleanup_old_backups() { # Remove the old backups - find ${HISTDIR} -mtime +${N_DAYS_TO_SPARE} -type f -exec rm -fv {} \; - # TODELETE=$( /bin/ls "${HISTDIR}/" | awk -F '.' '{print $NF}' | sort -ruV | tail -n +${N_DAYS_TO_SPARE} ) - # for i in ${TODELETE} - # do - # rm -f "${HISTDIR}/*.${i}" - # done + # find ${HISTDIR} -mtime +${N_DAYS_TO_SPARE} -type f -exec rm -fv {} \; + ORD_DUMP_TO_DEL=$( expr $N_DAYS_TO_SPARE + 1 ) + TODELETE=$( /bin/ls "${HISTDIR}/" | awk -F '.' '{print $NF}' | sort -ruV | tail -n +${ORD_DUMP_TO_DEL} ) + for i in ${TODELETE} + do + rm -f "${HISTDIR}/*.${i}" + done } create_db_list() { @@ -118,6 +119,8 @@ fix_backup_permissions() { # umask 0077 +cleanup_old_backups + create_backup_dirs if [ "$BUILD_DBLIST" == "yes" ] ; then create_db_list @@ -150,6 +153,5 @@ else fi fix_backup_permissions -cleanup_old_backups exit $RETVAL