Downtown Doug Brown Wiki

Thoughts from a combined Apple/Linux/Windows geek

User Tools

Site Tools


ubuntu:automatic_backups_to_dropbox

Automatic backups to Dropbox

This is just a simple way to do a daily backup of a directory to Dropbox. I generally put this stuff in ~/backup_scripts.

Set up dropbox_uploader

Start out by grabbing a copy of dropbox_uploader.sh:

cd ~/backup_scripts
wget https://github.com/andreafabrizi/Dropbox-Uploader/raw/master/dropbox_uploader.sh

Make it executable and run it:

chmod +x dropbox_uploader.sh
./dropbox_uploader.sh

Follow the directions that the script gives you to set up an app on Dropbox. The app can be limited to its own folder. Get an app key. When the script asks for a permission type, you can type “a” since we chose to limit it to its own folder. Note that it will store these settings in ~/.dropbox_uploader, so if you have another uploader on the same user account, you may want to customize the script to change the location of the config file.

The script will spit out a URL that you need to access once in order to authorize it to access your Dropbox folder. This should complete setup for the script; now it's time to make it do something.

Set up files to back up

Let's make a script that will tar up a directory and use dropbox_uploader to send it to Dropbox. In this example, we're going to back up the directory /home/doug/test to the file /home/doug/test_backup.tar.lzma. I'm assuming you know how to use vi; otherwise, use an editor of your choice.

cd ~/backup_scripts
vi do_backup.sh

Enter the following:

#!/bin/bash

BACKUP_FILE=/home/doug/test_backup.tar.lzma
REMOTE_FILE_NAME=test_backup.tar.lzma
BACKUP_DIR_PARENT=/home/doug
BACKUP_DIRS=test
DROPBOX_UPLOADER=/home/doug/backup_scripts/dropbox_uploader.sh
DROPBOX_UPLOADER_SETTINGS=/home/doug/.dropbox_uploader

# Tar up the directory
tar --lzma -cf $BACKUP_FILE -C $BACKUP_DIR_PARENT $BACKUP_DIRS

# Upload it to dropbox
$DROPBOX_UPLOADER -f $DROPBOX_UPLOADER_SETTINGS upload $BACKUP_FILE $REMOTE_FILE_NAME

Make it executable:

chmod +x do_backup.sh

Run it to make sure it works:

./do_backup.sh

As long as it works, we're good to go. Now, let's set up a cron job so it's automatically done every day.

Make a cron job to automate it

We're going to create a job in your crontab:

crontab -e

Now, add the following line to the bottom of the file (do whitespace however you want):

0 3 * * 1,3,5 /home/doug/backup_scripts/do_backup.sh

This should run a backup at 3 AM on Mondays, Wednesdays, and Fridays. See the crontab documentation for more info on how to customize when you want this script to run.

Save the file; you're done!

ubuntu/automatic_backups_to_dropbox.txt · Last modified: 2014/08/12 13:35 by doug