About

View Archive

Cron Job for Postgres Backups with Dokku

Posted on November 25, 2014

Found a script that backs up Postgres data for a given Dokku app.

Note: This script uses the Dokku PG plugin.

Contents of the script (dokku-pg-backup):

#! /bin/bash

# directory to save backups in, must be rwx by postgres user
BASE_DIR="/var/backups/postgres"
YMD=$(date "+%Y-%m-%d")
DIR="$BASE_DIR/$YMD"
mkdir -p $DIR
cd $DIR

# make database backup
dokku postgresql:dump $1 | gzip -9 > "$DIR/db.out.gz"

# delete backup files older than 7 days
OLD=$(find $BASE_DIR -type d -mtime +7)
if [ -n "$OLD" ] ; then
        echo deleting old backup files: $OLD
        echo $OLD | xargs rm -rfv
fi

You can call the script for the app:

./dokku-pg-backup appname

To perform a daily backup, I placed the script in the /etc/cron.daily.

Note: I’m using Ubuntu, and per the CronHowto docs, the script file cannot not accept a file name containing a period. The cron job will silently fail.

My fork of the gist.

About

Close

Hi, I'm Don Pottinger.

I love building things with computers. At 10 years old, I wrote my first program using BASIC. I built my first computer when I was 12 years old. I studied Electrical and Computer Engineering at Georgia Tech. Now, I'm a full-stack software developer and entrepreneur passionate about building rich web and mobile apps. My weapons of choice are Ruby, Javascript, and Objective-C.

I live in Atlanta with my amazing wife and son. For fun, I play too much soccer and follow my favorite soccer clubs, FC Barcelona and Arsenal F.C.

My CV so far

  • Chief Technology Officer at Kevy (2014 - Present)
  • Co-founder and Head of Technical Development of Body Boss Fitness (2010 - Present)
  • Co-founder and Head of Technical Development of Kickdrop (2014)
  • Resident Nerd, Full-stack Developer and Backend Team Manager at Big Nerd Ranch (2012 - 2014)
  • IT and Management Consultant for Accenture and Slalom Consulting (2008 - 2012)
  • Graduate of Georgia Tech with BS in Electrical and Computer Engineering (2008)

My Recent Projects

Facts About Me

  • I was born in Jamaica and raised in the United States.
  • I speak English, Spanish and Jamaican Patois.
  • I love to travel. So far, I've visited Peru, Argentina, Spain, Switzerland, Germany, Greece, France, Italy, Canada, Jamaica, Hawaii, Mexico and England.