Backing up a directory in Linux with duplicity and Backblaze B2

Back up your server to Backblaze B2 with Duplicity
Amazon S3 has been around for more than ten years now and I have been happily using it for offsite backups of my servers for a long time. Backblaze’s cloud backup service has been around for …

Duplicity - see http://www.nongnu.org/duplicity/ - is a backup tool for backing up a directory to any of a number of destinations. It looks pretty promising. I'm going to give it whirl. I'll update this once I get it working. I implemented the backup solution described in David Keen's article on my minecraft server as well as on my blog.

Here's what I came up with:

# Minecraft backup script

~/minecraft$ cat backup.sh
#!/usr/bin/env bash
screen -r mc -X stuff "/say Backup starting.$(printf '\r')"
screen -r mc -X stuff "/save-off$(printf '\r')"
screen -r mc -X stuff "/save-all$(printf '\r')"
sleep 4

B2_ACCOUNT_ID='...'
B2_APPLICATION_KEY='...'
BUCKET='...'

# back up to b2
duplicity --full-if-older-than 1D --no-encryption /home/mc/minecraft b2://$B2_ACCOUNT_ID:$B2_APPLICATION_KEY@$BUCKET

# verify
# duplicity verify --no-encryption b2://$B2_ACCOUNT_ID:$B2_APPLICATION_KEY@$BUCKET ~/minecraft

# cleanup
duplicity remove-older-than 2D --force --no-encryption b2://$B2_ACCOUNT_ID:$B2_APPLICATION_KEY@$BUCKET

screen -r mc -X stuff "/save-on$(printf '\r')"
screen -r mc -X stuff "/say Backup finished.$(printf '\r')"
# Ghost Blog backup script

~$ cat backup.sh
#!/usr/bin/env bash

B2_ACCOUNT_ID='...'
B2_APPLICATION_KEY='...'
BUCKET='...'
WORKING_DIR=/var/www/ghost/content
WORKING_DIR2=/home/ghostsvc/ghostmysqlbackup

mkdir -p $WORKING_DIR2

mysqldump ghost_prod | gzip > $WORKING_DIR2/ghost_prod.sql.gz

# back up to b2
duplicity --full-if-older-than 1D --no-encryption $WORKING_DIR b2://$B2_ACCOUNT_ID:$B2_APPLICATION_KEY@$BUCKET/ghostcontent
duplicity --full-if-older-than 1D --no-encryption $WORKING_DIR2 b2://$B2_ACCOUNT_ID:$B2_APPLICATION_KEY@$BUCKET/ghostmysql

# cleanup
duplicity remove-older-than 2D --force --no-encryption b2://$B2_ACCOUNT_ID:$B2_APPLICATION_KEY@$BUCKET/ghostcontent
duplicity remove-older-than 2D --force --no-encryption b2://$B2_ACCOUNT_ID:$B2_APPLICATION_KEY@$BUCKET/ghostmysql

Then, I just added those two scripts to run as a cron job, hourly. Every time they run, they will create either a full or incremental backup, and store it in a Backblaze B2 bucket. I have one bucket for the blog, and one bucket for the minecraft backups.