Created
December 23, 2021 02:50
-
-
Save dillonhafer/4365150aa3e371322c8072f1ce3de227 to your computer and use it in GitHub Desktop.
Keep last 5 days worth of pg backups
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/bash | |
# Keep last 5 files ending in .dump | |
# Don't forget to | |
# Installation | |
# 1. cp pg-backups.sh /usr/local/bin/ | |
# 2. chmod u+x /usr/local/bin/pg-backups.sh | |
# 3. Set the DB variable | |
# 4. Set the BACKUP_DIR variable | |
# Example usage for cron to run at 4:05 am every day: | |
# 5 4 * * * /usr/local/bin/pg-backups.sh | |
DB=mydatabase | |
BACKUP_DIR=/mnt/object/production/db-backups | |
DATE=$(date "+%Y-%m-%d_%H%M") | |
pg_dump -Fc $DB > $BACKUP_DIR/$DATE.dump | |
/bin/ls -t $BACKUP_DIR/*.dump | tail +6 | xargs rm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment