Instantly share code, notes, and snippets.

Embed
What would you like to do?
For `dokku/dokku-postgres`. See https://gist.github.com/henrik/26bb73091712aa42abf2#db-backups for setup instructions.
#!/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