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.
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!
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
# 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!