(Linux) How to automatically backup server files to Dropbox

Post Reply
furntree
Compulsive poster
Compulsive poster
Posts: 74
https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA
Joined: Fri May 24, 2013 7:41 pm

(Linux) How to automatically backup server files to Dropbox

Post by furntree »

Have some Dropbox space free? Want to keep backups of all your important server files? Well you have come to the right place!

For my tutorial I will be doing this on Ubuntu 13.04, however with some basic Linux knowledge you should be able to adapt this for almost any Linux deployment.

Now first of all we will need to install Dropbox itself from the official website. This is pretty straight forward and works well on Debian. I am not going to go into detail on how to compile from source. If you need to compile from source I would hope you already have that knowledge.

Image

For me I downloaded the 32 bit .deb and it opened up automatically in Ubuntu Software Center. It was as easy as a few clicks.

Image

After Ubuntu Software Center was finished I was prompted with a notification on the desktop requesting to open Dropbox and download more required files.

Image

From there log into Dropbox and go through the general config. The Linux version of Dropbox is great and runs just like the Windows version.
Image

Now that we have Dropbox setup we need need to get this really cool Bash script "Dropbox Uploader". This script does use curl so you will want to check that you have curl installed.

https://github.com/andreafabrizi/Dropbox-Uploader

I used the instructions on the github to download the file to my home directory. It will create a directory named Dropbox-Uploader

Code: Select all

git clone https://github.com/andreafabrizi/Dropbox-Uploader/
Now we need to make a script that can easily call our bash script that we just downloaded. So open up a text editor and lets start scripting.

Here is a simple perl script. Enter in the required information and save it as .pl (I named mine backupscript.pl)

Image

Code: Select all

#!/usr/bin/perl -w

use strict;
use POSIX qw(strftime);

my $time = strftime "%Y-%m-%d_%H-%M-%S", localtime;
my $backup_folder = "/home/furntree/srcds";
my $path = "/home/furntree/Dropbox-Uploader/";
my $bu_prefix = "furntree";
my $script = "dropbox_uploader.sh";
my $exe = $path . $script;
my $filename = $bu_prefix . "_" . "backup_" . $time . ".tgz";
my $tar = "/bin/tar";
my $rm = "/bin/rm";
my $target_folder = "/LocalBackup/" . $filename;
 
system($tar . " -cvzf " . $path . $filename . " " . $backup_folder);
system($exe . " upload " . $path . $filename . " " . $target_folder);
system($rm . "  " . $path . $filename);
What this script does.

Code: Select all

Performs tar on the directory you wish. 
Executes the upload using the bash script.
Removes the temporary tarball from the disc.

These are the things you will need to worry about.

Code: Select all

my $backup_folder =
What directory you want backed up. (In this example I am backing up a directory I might use for a Valve game)

Code: Select all

my $path =
The location of our upload bash script.

Code: Select all

my $bu_prefix
What you want your backups named.

Code: Select all

my $target_folder =
The folder you want uploaded to on Dropbox itself.


Once everything is setup you should be able to run your script. For myself I did.

Code: Select all

perl backupscript.pl
The first time the script runs you will be asked to create an application with the Dropbox API.
Go to https://www.dropbox.com/developers/apps/create and create the the following.

Database App
Files and datastores
App not limited or App folder (I did not limited)
All file types

Use the app name given to you in console.

Image

Enter in the information given to you by Dropbox and follow all instructions you see. Once the setup is complete you can run your perl script again and it should work! From here you can add the script to Cron to run everyday, week, etc. Making automatic backups easily available offsite.

Image

If you run into any problems or have suggestions on how to improve this post below!
Last edited by furntree on Sun Oct 13, 2013 8:10 pm, edited 1 time in total.
Reason: Spelling
Post Reply