Skip to content

Commit

Permalink
WIP: Choose WAL-G backup by start time when deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
simonklb committed Jun 18, 2024
1 parent 70d718e commit fcb00b1
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions postgres-appliance/scripts/postgres_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ LEFT=0

NOW=$(date +%s -u)
readonly NOW
while read -r name last_modified rest; do
last_modified=$(date +%s -ud "$last_modified")
if [ $(((NOW-last_modified)/86400)) -ge $DAYS_TO_RETAIN ]; then
if [ -z "$BEFORE" ] || [ "$last_modified" -gt "$BEFORE_TIME" ]; then
BEFORE_TIME=$last_modified
while read -r name last_modified wal_segment_backup_start start_time rest; do
start_time=$(date +%s -ud "$start_time")
if [ $(((NOW-start_time)/86400)) -ge $DAYS_TO_RETAIN ]; then
if [ -z "$BEFORE" ] || [ "$start_time" -gt "$BEFORE_TIME" ]; then
BEFORE_TIME=$start_time
BEFORE=$name
fi
else
# count how many backups will remain after we remove everything up to certain date
((LEFT=LEFT+1))
fi
done < <($WAL_E backup-list 2> /dev/null | sed '0,/^name\s*\(last_\)\?modified\s*/d')
done < <($WAL_E backup-list --detail 2> /dev/null | sed '0,/^name\s*\(last_\)\?modified\s*/d')

# we want keep at least N backups even if the number of days exceeded
if [ -n "$BEFORE" ] && [ $LEFT -ge $DAYS_TO_RETAIN ]; then
Expand Down

0 comments on commit fcb00b1

Please sign in to comment.