Update 'templates/postgresql-backup.sh.j2'

- Cleanup older dumps leaving N_DAYS_TO_SPARE dump, don't use find by date
- clean old dumps before new dump
This commit is contained in:
Tommaso Piccioli 2023-03-23 16:15:08 +01:00
parent c3f33257ad
commit 56cdc39d7b
1 changed files with 9 additions and 7 deletions

View File

@ -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