Skip to content

Instantly share code, notes, and snippets.

@numb95
Last active January 19, 2018 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save numb95/8e4ce3118743e23c6c43ac83d2fd5af5 to your computer and use it in GitHub Desktop.
Save numb95/8e4ce3118743e23c6c43ac83d2fd5af5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Daily Backup
#You can add script to Cron
BACKUP_DIR=/home/conf/backup/db
DAYS_TO_KEEP=30
PROJECT_NAME=project
FILE_SUFFIX=_pg_backup.sql
DATABASE=
USER=postgres
FILE=`date +"%Y%m%d%H%M"`${PROJECT_NAME}${FILE_SUFFIX}
OUTPUT_FILE=${BACKUP_DIR}/${FILE}
pg_dump -U ${USER} ${DATABASE} -F p -f ${OUTPUT_FILE}
gzip $OUTPUT_FILE
find $BACKUP_DIR -maxdepth 1 -mtime +$DAYS_TO_KEEP -name "*${FILE_SUFFIX}.gz" -exec rm -rf '{}' ';'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment