Skip to content

Instantly share code, notes, and snippets.

@sethbergman
Forked from henrik/dokku_postgres_backups.sh
Created January 10, 2016 23:23
Show Gist options
  • Save sethbergman/3f5a74d127d557f791cd to your computer and use it in GitHub Desktop.
Save sethbergman/3f5a74d127d557f791cd to your computer and use it in GitHub Desktop.
#! /bin/bash
# For use with Flink/dokku-psql-single-container.
# Based on http://donpottinger.net/blog/2014/11/25/postgres-backups-with-dokku.html
set -e
BASE_DIR="/var/backups/postgres"
mkdir -p $BASE_DIR
YMD=$(date "+%Y-%m-%d")
FILE="$BASE_DIR/$YMD.dump"
/usr/bin/docker exec psql-single-container su postgres -c "pg_dumpall" > "$FILE"
# delete backup files older than 10 days
# (since Digital Ocean disk backups can be as infrequent as every 7 days)
OLD=$(find $BASE_DIR -type d -mtime +10)
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