Skip to content

Instantly share code, notes, and snippets.

@henrik
Last active December 18, 2016 19:07
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 henrik/5ebff4ba7d18df85144520e20210a178 to your computer and use it in GitHub Desktop.
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.
#!/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