Last active
February 1, 2017 15:36
-
-
Save dimmg/77383359dcab86bd96fda84b061e7d99 to your computer and use it in GitHub Desktop.
basic postgresql backup
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 | |
BACKUP_DIRECTORY="/var/lib/_postgresql/backup" | |
LOGFILE="$BACKUP_DIRECTORY/backup.log" | |
CURRENT_DATE=$(date "+%Y%m%d") | |
FILENAME=$BACKUP_DIRECTORY/$1_$CURRENT_DATE.sql | |
if [ -z "$1" ] | |
then | |
echo "[$(date)] FAILURE: Database name was not specified" >> $LOGFILE | |
else | |
pg_dump -Fc $1 > $FILENAME | |
gzip $FILENAME | |
echo "[$(date)] SUCCESS: Backup created. File: $FILENAME.gz" >> $LOGFILE | |
fi |
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 | |
BACKUP_DIRECTORY="/var/lib/_postgresql/backup" | |
LOGFILE="$BACKUP_DIRECTORY/backup.log" | |
BACKUP_EXTENSION="*.sql.gz" | |
CURRENT_DATE=$(date "+%Y%m%d") | |
DAYS=7 | |
for backup in `find $BACKUP_DIRECTORY -mtime +$DAYS -type f -name $BACKUP_EXTENSION` | |
do | |
echo "[$(date)] REMOVING: $backup" >> $LOGFILE | |
rm $backup | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment