Skip to content

Commit

Permalink
🐞 Old PostgreSQL backups not being removed and rotated
Browse files Browse the repository at this point in the history
Parent issue: sequentech/meta#309

WAL backups are not being removed and default backup config retains too many backups.
  • Loading branch information
edulix committed Nov 5, 2023
1 parent 6be2f64 commit c0ddc65
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ config:
# cron tab configuration for base backups
base_backups:
# number of days base backups are kept/stored (0 means forever)
keep_days: 30
keep_days: 15
# day of the week that the job should run ( 0-6 for Sunday-Saturday, *, etc )
weekday: '*'
# Day of the month the job should run ( 1-31, *, */2, etc )
Expand Down
2 changes: 1 addition & 1 deletion doc/devel/auth1.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ config:
# cron tab configuration for base backups
base_backups:
# number of days base backups are kept/stored (0 means forever)
keep_days: 30
keep_days: 15
# day of the week that the job should run ( 0-6 for Sunday-Saturday, *, etc )
weekday: '*'
# Day of the month the job should run ( 1-31, *, */2, etc )
Expand Down
2 changes: 1 addition & 1 deletion doc/devel/auth2.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ config:
# cron tab configuration for base backups
base_backups:
# number of days base backups are kept/stored (0 means forever)
keep_days: 30
keep_days: 15
# day of the week that the job should run ( 0-6 for Sunday-Saturday, *, etc )
weekday: '*'
# Day of the month the job should run ( 1-31, *, */2, etc )
Expand Down
2 changes: 1 addition & 1 deletion doc/devel/sequent.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ config:
# cron tab configuration for base backups
base_backups:
# number of days base backups are kept/stored (0 means forever)
keep_days: 30
keep_days: 15
# day of the week that the job should run ( 0-6 for Sunday-Saturday, *, etc )
weekday: '*'
# Day of the month the job should run ( 1-31, *, */2, etc )
Expand Down
2 changes: 1 addition & 1 deletion doc/production/config.auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ config:
# cron tab configuration for base backups
base_backups:
# number of days base backups are kept/stored (0 means forever)
keep_days: 30
keep_days: 15
# day of the week that the job should run ( 0-6 for Sunday-Saturday, *, etc )
weekday: '*'
# Day of the month the job should run ( 1-31, *, */2, etc )
Expand Down
2 changes: 1 addition & 1 deletion doc/production/config.master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ config:
# cron tab configuration for base backups
base_backups:
# number of days base backups are kept/stored (0 means forever)
keep_days: 30
keep_days: 15
# day of the week that the job should run ( 0-6 for Sunday-Saturday, *, etc )
weekday: '*'
# Day of the month the job should run ( 1-31, *, */2, etc )
Expand Down
15 changes: 14 additions & 1 deletion templates/clean_old_postgres_backups.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ DATE_OLDEST=`echo "$DATE_NOW - (24*3600*$KEEP_DAYS)" | bc`

LIST_BASE=`ls $BACKUP_DIR/base`
LIST_DUMP=`ls $BACKUP_DIR/dump`
LIST_WAL=`ls $BACKUP_DIR/wal`

for FNAME in $LIST_BASE
do
Expand Down Expand Up @@ -62,4 +63,16 @@ do
fi
done

exit 0
for FNAME in $LIST_WAL
do
# Get file's last modification time in seconds since the epoch
FDATE=`date -r "$BACKUP_DIR/wal/$FNAME" +%s`

# check date and remove if it's too old
if [ "$DATE_OLDEST" -gt "$FDATE" ]; then
echo "deleting $BACKUP_DIR/wal/$FNAME"
rm -f $BACKUP_DIR/wal/$FNAME
fi
done

exit 0

0 comments on commit c0ddc65

Please sign in to comment.