Skip to content

Instantly share code, notes, and snippets.

@RavenXce
Last active November 26, 2015 13:09
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 RavenXce/38683a95abe233fe8c30 to your computer and use it in GitHub Desktop.
Save RavenXce/38683a95abe233fe8c30 to your computer and use it in GitHub Desktop.
Hourly postgres backup for dokku
#! /bin/bash
# directory to save backups in, must be rwx by postgres user
BASE_DIR="/var/backups/dokku-postgres/hourly"
TIME=$(date "+%Y%m%d-%H%M%S")
DIR="$BASE_DIR"
# make dir if it doesn't exist
mkdir -p $DIR
cd $DIR
# make database backup for all dbs
dbs=($(dokku postgres:list | awk 'NR>1{ print $1 }'))
for APP in "${dbs[@]}"
do
dokku postgres:export $APP > "$DIR/$APP-db_${TIME}.sql"
done
# delete backup files older than 2 days
OLD=$(find $BASE_DIR -type d -mtime +2)
if [ -n "$OLD" ] ; then
echo deleting old backup files: $OLD
echo $OLD | xargs rm -rfv
fi
@RavenXce
Copy link
Author

Put this file in /etc/cron.hourly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment