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 graduated from Georgia Institute of Technology with a BS in Electrical and Computer Engineering. I have a background as a technology consultant and software engineer.

Now, I'm a co-founder of LanguaTalk, a language learning platform, and an engineering manager at Google.

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

My CV so far

  • Engineering Manager at Google (2022 - Present)
  • Co-founder at LanguaTalk (2020 - Present)
  • Cloud Engineer at Google (2019 - 2022)
  • Founder and CEO at Kevy (2014 - 2019)
  • Co-founder and Head of Technical Development of Body Boss Fitness (2010 - 2015)
  • Engineering Manager and Software Engineer 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)

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.