Skip to content

Commit

Permalink
Merge branch 'master' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
mickaobrien committed Feb 28, 2020
2 parents 826e2c7 + a26a090 commit a745034
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions daily_backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
#
# Backup a Postgresql database into a daily file.
# Run daily at midnight as a cron job:
# crontab -e
# 0 0 * * * sudo /bin/su -c "/var/lib/postgresql/daily_backup.sh" - postgres >/dev/null 2>&1
#
TODAY=`date --iso-8601`
BACKUP_DIR=/home/alex/curate_backups
DAYS_TO_KEEP=30
DATABASE=curate
USER=postgres
OUTPUT_FILE=${BACKUP_DIR}/curate$TODAY.bak

# do the database backup (dump)
# use this command for a database server on localhost. add other options if need be.
pg_dump ${DATABASE} > ${OUTPUT_FILE}

# gzip the mysql database dump file
# gzip $OUTPUT_FILE

# show the user the result
# echo "${OUTPUT_FILE} was created."
# ls -l ${OUTPUT_FILE}.gz

# prune old backups
find $BACKUP_DIR -maxdepth 1 -mtime +$DAYS_TO_KEEP -name "*.bak" -exec rm -rf '{}' ';'

0 comments on commit a745034

Please sign in to comment.