Skip to content

Instantly share code, notes, and snippets.

@dimmg
Last active February 1, 2017 15:36
Show Gist options
  • Save dimmg/77383359dcab86bd96fda84b061e7d99 to your computer and use it in GitHub Desktop.
Save dimmg/77383359dcab86bd96fda84b061e7d99 to your computer and use it in GitHub Desktop.
basic postgresql backup
#!/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
#!/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