1. Home
  2. Linux
  3. Create dropbox backup server on linux

How To Create A Dropbox Backup Server On Linux

A headless Dropbox backup server starts out by installing a command-line version of Dropbox. In this instance, we’ll make use of the Dropbox Uploader. It’s a script that makes automatically uploading content to Dropbox over the command-line very easy.

Install Git

To get this script, you’ll need to have the Git package installed on your Linux PC. Open up a terminal window and enter the following commands to get going with Git.

Ubuntu

sudo apt install git

Debian

sudo apt-get install git

Arch Linux

sudo pacman-S git

Fedora

sudo dnf install git

OpenSUSE

sudo zypper install git

Other Linuxes

Git is ubiquitous. As a result, users on even the most obscure Linux distribution should be able to install it. Use your package manager to search for “git”, and install it. Alternatively, check Pkgs.org for a downloadable installer.

Dropbox Uploader

Once the Git tool is installed, we can use it to grab the code for Dropbox Uploader. In the terminal, clone the source code on your Linux PC:

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

Using the CD command, move the terminal into the newly cloned Dropbox-Uploader folder.

cd Dropbox-Uploader

From here, the script can be used, but it won’t work correctly. To ensure that Dropbox Uploader runs right on Linux, you’ll need to update the permissions of it. Ultimately, the Dropbox Uploader tool is a Shell script, so a simple chmod will suffice.

chmod +x dropbox_uploader.sh

Dropbox Uploader works by running dropbox_uploader.sh. However, the tool also comes with a few other scripts that users can use to work with Dropbox. Optionally, update the permissions on these files to with:

chmod +x dropShell.sh

chmod +x testUnit.sh

Set Up Dropbox API

Now that the Dropbox backup software is on your Linux PC, we can set up the backup system. The first step is to create a new Dropbox app code. This code will be used to log Dropbox into your account. To create a new app, head over to the official developer page, find the “create app” button and click it.

Clicking the “create app” brings you to the API page. Select “Dropbox API” to continue.

Next, choose the level of access Dropbox Uploader should have. For best results, select “Full Access”. Doing this will allow it to work within multiple folders, inside your entire account, rather than just a single area.

Write in the name of the app and click the “create app” button to finish up.

After going through the process of creating an App in the developer center, you’ll be brought to the Dropbox app entry for the Upload tool. Scroll down, find “Generated access token” and click the “Generate” button.

Creating Backups

You’ve got a Dropbox API page set up for the uploader, and an access token to use with it. The next step is to associate the script with your account. To do this, go to the terminal and run the Dropbox Uploader tool.

./dropbox_uploader.sh

When you run the script for the first time, it will ask you for the access token. Go back to the Dropbox API page and copy the new access code from earlier.

After adding the new access code, it’s safe to start running backups. Start off by using the uploader to create a new folder:

./dropbox_uploader.sh mkdir Backup

Running mkdir will create a remote backup folder in your Dropbox account. From here, you’ll be able to upload files to it. To upload,  run the command below.

Note: Dropbox Uploader can handle more than just Tar.gz files. Customize the command below to upload any kind of file.

./dropbox_uploader.sh upload /home/username/location/of/file.tar.gz

Automate Backups

Manual upload is nice, but it’s better to automate these kinds of things. For this job, it’s best to use Cron. In a terminal, gain Root with su or sudo.

su –

or

sudo -s

In the Root shell, access Cron:

crontab -e

Choose the option to use Nano as the editor. Then, paste the following in the Cron file.

Note: this Cron command will tell your Linux PC to compress a backup and upload it to the Backup folder in Dropbox every day at 8:06 AM.

06 08 * * 6 tar -zcvf backup-$(date +%Y-%m-%d).tar.gz /home/username/;/home/username/Dropbox-Uploader/dropbox_uploader.sh upload /home/username/backup-$(date +%Y-%m-%d).tar.gz Backups

Save the command into Cron. Once saved, your PC will automatically take a snapshot of /home/username/, compress it to a Tar.gz archive, date it, and upload it to Dropbox. Don’t want to backup your entire home folder on a schedule? Customize the folder paths, so that it points to a specific folder.

If everything looks good, save the new Cron file in Nano with Ctrl + O.

Disable Automated Backups

Automatic backups to Dropbox are cool, but if you only want to deal with it manually, remove the command from Cron:

su -
crontab -e

Like before, save the edits with Ctrl + O. After saving, the automatic backup will stop.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.