Skip to content

Instantly share code, notes, and snippets.

@RavenXce
Last active December 27, 2020 14:18
Show Gist options
  • Save RavenXce/3a4e3793e3e16df00de8 to your computer and use it in GitHub Desktop.
Save RavenXce/3a4e3793e3e16df00de8 to your computer and use it in GitHub Desktop.
Daily postgres backup for dokku
#! /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
@RavenXce
Copy link
Author

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

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