Phabricator - Automate Data Backup using Dropbox

Phabricator does not currently have a comprehensive backup system, but creating backups is not particularly difficult. We will share an approach to automate backups and save them onto Dropbox. We don't like to think about what might happen, but its always good to have some backups.

Phabricator backup using Dropbox

Dropbox Uploader

First up, get yourself familiar with this nifty tool, Dropbox Uploader. Dropbox uploader is a bash script which allows you to upload, download, delete and list files (and more!) from Dropbox. The Dropbox uploader script github page explains setting this tool up and getting started. You can set it up and get going real quick.

Now that we have setup the uploader script, we need to identify things that we need to backup.

  • Phabricator Database Dump
  • Phabricator Codebase (Just in case)
  • Phabricator hosted repositories
  • You can extend this list to include more stuff!

Backup Script

We need to first gather files and data to be backed up. Using the uploader script, we will upload the backups onto Dropbox. If something goes weird with the phabricator setup, at least we will be able to prevent data loss to a reasonable extent.

#!/usr/bin/env bash

set +x

DATE=`date +%Y%m%d`
DUMP=phabricator.dump.$DATE.tar.bz2
REPO=phabricator.repo.$DATE.tar.bz2
CODE=phabricator.code.$DATE.tar.bz2

## Database dump
# take mysql data dump of Phabricator database
# update mysql credentials as needed
mysqldump -uroot -p***** --single-transaction --quick --all-databases > dump.sql
# compress the dump file
tar -Pcjf $DUMP dump.sql

## Phabricator hosted repositories archive
tar -Pcjf $REPO /var/repo

## Phabricator source code archive including arcanist and libphutil
tar -Pcjf $CODE /opt/taskman

## Upload the dump files to Dropbox
./dropbox_uploader.sh upload *.$DATE.tar.bz2 /

# cleanup local files
rm dump.sql $DUMP $REPO $CODE

To run this script, say daily, set up a cron --too easy, add a new cron using crontab -e;

# Phabricator backups Runs daily 18.30 EST = 4.00 AM IST
30 18 * * * cd /root/backup && ./backup.sh >> ./backup.log &

There you have it, a nice little script to keep your backup worries at bay. You may have to cleanup old backup files from your Dropbox account once in while, or you can always purchase more storage space from Dropbox.

You can improve the backup script by automatically removing old backups from Dropbox, using the same uploader script.

Hope this helps. Good day!

\m/

Vinayak Mishra

Vinayak Mishra, a Cricket Enthusiast with keen interest in web and mobile applications. Hails from Mithila, Nepal, married to Rani and dad to his bundle of joy Bunu. Lives in New Delhi, India. You can follow him on Twitter or check out his website, vnykmshr.com.