-
-
Save julienma/454bca43cd9508098d06 to your computer and use it in GitHub Desktop.
dokku postgres (and volume folders) backup cronjob (using https://github.com/dokku/dokku-postgres)
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 | |
MAILTO=$(whoami) | |
SHELL=/bin/bash | |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
# directory to save backups in, must be rwx by dokku user | |
BASE_DIR="/var/lib/dokku/data/storage/backups/postgres" | |
YMD=$(date "+%Y-%m-%d") | |
DIR="$BASE_DIR/$YMD" | |
mkdir -p $DIR | |
cd $DIR | |
# make database backup | |
dokku postgres:export $1 | gzip -9 > "$DIR/$1_db.dump.gz" | |
# delete backup files older than 30 days | |
OLD=$(find $BASE_DIR -type d -mtime +30) | |
if [ -n "$OLD" ] ; then | |
echo deleting old backup files: $OLD | |
echo $OLD | xargs rm -rfv | |
fi |
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 | |
MAILTO=$(whoami) | |
SHELL=/bin/bash | |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
# directory to save backups in, must be rwx by dokku user | |
BASE_DIR="/var/lib/dokku/data/storage/backups/volumes/volume-$1" | |
YMD=$(date "+%Y-%m-%d") | |
DIR="$BASE_DIR/$YMD" | |
mkdir -p $DIR | |
cd $DIR | |
# backup target folder | |
cd /var/www | |
tar -czf "$DIR/$1_volume.tar.gz" $1 | |
# delete backup files older than 30 days | |
OLD=$(find $BASE_DIR -type d -mtime +30) | |
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
Requirements
Don't forget to
chmod +x dokku-pg-backup.sh dokku-volume-backup.sh
.PostGres Backup
Use it like
dokku-pg-backup.sh your-pg-db
.To set it up as CRON:
And edit crontab as follow (for a backup every day at 2:15am):
Volume Backup
Use it like
dokku-volume-backup.sh your-app-volume-folder
where your app's volume folder(s) lives in/var/www/
(e.g./var/www/your-app-volume-folder/lots_of_directories_and_files
).To set it up as CRON:
And edit crontab as follow (for a backup every day at 2:45am):