Created
November 12, 2014 11:43
-
-
Save cihann/cc9d7c0c837cf29c78d4 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# Location to place backups. | |
backup_dir="/home/postgres-backup/" | |
#String to append to the name of the backup files | |
backup_date=`date +%d-%m-%Y` | |
#Numbers of days you want to keep copie of your databases | |
number_of_days=30 | |
databases=`psql -l -t | cut -d'|' -f1 | sed -e 's/ //g' -e '/^$/d'` | |
for i in $databases; do | |
if [ "$i" != "template0" ] && [ "$i" != "template1" ]; then | |
echo Dumping $i to $backup_dir$i\_$backup_date | |
pg_dump -Fc $i > $backup_dir$i\_$backup_date | |
fi | |
done | |
find $backup_dir -type f -prune -mtime +$number_of_days -exec rm -f {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment