Last active
December 18, 2016 19:07
-
-
Save henrik/5ebff4ba7d18df85144520e20210a178 to your computer and use it in GitHub Desktop.
For `dokku/dokku-postgres`. See https://gist.github.com/henrik/26bb73091712aa42abf2#db-backups for setup instructions.
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 | |
# For use with dokku/dokku-postgres. | |
# Based on https://gist.github.com/henrik/1043fecdd0937034cd62 | |
set -e | |
base_dir="/var/backups/postgres" | |
mkdir -p $base_dir | |
ymd=$(date "+%Y-%m-%d") | |
for db_name in `dokku postgres:list | sed 1d | awk '{print $1}'` | |
do | |
file="$base_dir/$ymd-$db_name.dump" | |
dokku postgres:export $db_name > "$file" | |
done | |
# delete backup files older than 10 days | |
# (since Digital Ocean disk backups can be as infrequent as every 7 days) | |
old=$(find $base_dir -mtime +10) | |
if [ -n "$old" ] ; then | |
echo deleting old backup files: $old | |
echo $old | xargs rm -rfv | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment