Deglazing slbackup.py Usage In the Object Storage Kitchen

Backups are dandy; especially when you delete everything by accident. But when some joker writes a backup script that you think will be helpful and doesn’t document how to use it properly, it’s probably more frustrating than figuring things out yourself. We’ve been busy launching a private cloud offering so this blog is much overdue.

Let’s take the very common use case of database backups. And let’s do this up foodie style.

1x backup user
1x backup output directory
1x copy of slbackup.py and it’s dependencies
1x copy of a database backup script
1x object storage account

First thing we do is take this assigned backup user and create a directory to mix everything up in; mkdir ~/database-backups. Next we get slbackup.py setup by populating it’s config; slbackup.py --example > ~/.slbackup. We open up ~/.slbackup with either vim, emacs, or whatever your favorite cli utensil is. Once opened for editing, replace the words MISSING with the appropriate values (account details) and adjust any other parameters you see fit. Add a dolup of semicolon at the beginning of a line to comment it out and slbackup.py will use the defaults.

; bunch of stuff before this, skipped
[slbackup]
username = MISSING
datacenter = dal05
apikey = MISSING
checksum = False
internal = False
;threads = 2
retention = 30

Save and close the file. Open another file called database-backup-script.sh, and put the following (please add your own personal touches here as cooking times may vary).

#!/bin/sh
database=$1
dow=$(date +%a)
mysqldump --opt $database | xz -3 - > ../../database-backups/${database}-${dow}.sql.xz

This particular script backups up a specific database table using the day of the week (Mon, Tue, ..) as part of the filename, overwriting the file if it already exists. With the scripts configured, we need to mix everything up with cron. Edit the user’s cron by using crontab -e (use crontab -e -u backupuser if logged in as root). Choose an interval that’s good for your database work load, typically once a day.

# backup an ecommerce database
15  1   *  *  *   ~/database-backup-script.sh ecommerce_site_1
# backup the database backup folder to object storage, 
# keeping old files for 8 days
20  2   *  *  *   slbackup.py -o dbbackups -s ~/database-backups -r 8

This will place all of your database backups into the database-backups directory and then upload it to the object storage container dbbackups. Any identically named files will be copied out of the way and will spoil after 8 days. No worries however as the script will bin it automatically.

That’s it, enjoy sleeping at night as your databases are backed up and safe in your private container. Well, at least that one ecommerce site is for now.

-Kevin