Last active
December 27, 2020 14:18
-
-
Save RavenXce/3a4e3793e3e16df00de8 to your computer and use it in GitHub Desktop.
Daily 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" | |
YMD=$(date "+%Y-%m-%d") | |
DIR="$BASE_DIR/$YMD" | |
# 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.sql" | |
done | |
# delete backup files older than 14 days | |
OLD=$(find $BASE_DIR -type d -mtime +14) | |
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
This backs up PostgreSQL dokku containers ran by the official dokku postgresql plugin: dokku/dokku-postgres
See previous revisions for usage with the older unmaintained plugin: Kloadut/dokku-pg-plugin