Last active
November 26, 2015 13:09
-
-
Save RavenXce/38683a95abe233fe8c30 to your computer and use it in GitHub Desktop.
Hourly postgres backup for dokku
This file contains 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 | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put this file in /etc/cron.hourly