Created
August 22, 2017 22:23
-
-
Save roylez/75c8508bb77631830e5f53b70a577687 to your computer and use it in GitHub Desktop.
dokku postgres backupscript
This file contains hidden or 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 | |
# | |
# to restore: | |
# gunzip XXX.db.gz | |
# dokku postgres:import <dbname> < XXX.db | |
# directory to save backups in, must be rwx by postgres user | |
BASE_DIR="/var/backups/postgres" | |
YMD=$(date "+%Y-%m-%d") | |
DIR="$BASE_DIR" | |
mkdir -p $DIR | |
cd $DIR | |
# make database backup | |
dokku postgres:export $1 | gzip -9 > "$YMD.db.gz" | |
# delete backup files older than 7 days | |
OLD=$(find $BASE_DIR -type f -mtime +7) | |
if [ -n "$OLD" ] ; then | |
echo deleting old backup files: $OLD | |
echo $OLD | xargs rm -rfv | |
fi |
This file contains hidden or 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
0 0 * * * /root/backup-db.sh huginn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment