Simple MediaTemple DV Wordpress Database Backups to Amazon S3
Subtitle: A Glaring Use Case for Go
What we wanted:
A simple database backup scheme
What we ended with (after much pain and tears):
A backup of every database on the server (each database by name as a separate file) to S3 every 8 hours, with version persistence.
How and why:
tl;dr: We used Gof3r and an S3 bucket with versioning enabled.
We were looking for a simpler solution than our previous Duplicity backup script, which works great, but leaves all the databases packed inside incremental backup archives. This is great for large files, but for databases I’ll trade some extra pennies to Amazon for the ease of having my backups downloadable/rollbackable in one click.
To backup to AWS, we first looked to the official AWS Cli, but alas our MediaTemple DV is running CentOS, and the version of Python wasn’t up to the pre-reqs. After investigating further, it seemed that updating python could also break
yum, which was not justifiable.
So back to the drawing board. Without wanting to install major language updates (or entirely new languages), and without using a very limited, very gnarly set of shell scripts, we struck paydirt.
We found Gof3r by Randall McPherson.
Per the readme: “s3gof3r provides fast, parallelized, pipelined streaming access to Amazon S3. It includes a command-line interface …” And it compiles to a static binary.
Using a riff of the aforementioned Duplicity backup script and s3gof3r, we setup a simple cron job to run every 8 hours, dump each database to a file named after it, and copy each file to an S3 bucket.
Enabling versioning on the S3 bucket, and using the (newly compatible with versioning) S3 lifecycle rules, we basically have a super-smooth backup that just overwrites each database file every 8 hours, but we can retrieve past versions as far back in time as we want.