Last active
June 12, 2019 17:29
-
-
Save kouk/58dbd73c406a6a868344b992b8733d8a to your computer and use it in GitHub Desktop.
wale-delete-backups.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
# cf. https://github.com/wal-e/wal-e/issues/206 | |
cutoff=`date -u -d '1 month ago' +%s` | |
latest=`date -u +%s` | |
wal-e --terse backup-list | tail -n +2 | { | |
# find the oldest backup after the cutoff date | |
while IFS= read -r line; do | |
last_modified_date=`echo $line|awk '{print $2}'` | |
last_modified=`date -u -d "$last_modified_date" +%s` | |
if [ $last_modified -gt $cutoff -a $last_modified -lt $latest ]; then | |
oldest=`echo $line|awk '{print $1}'` | |
latest=$last_modified | |
fi | |
done | |
if [ -z "$oldest" ] ; then | |
echo "No backups found younger than one month! Aborting.." | |
echo "Cutoff date: `date -u -d @$cutoff`" | |
echo "Last backup date: $last_modified_date" | |
exit 1 | |
fi | |
wal-e delete --confirm before $oldest | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment