Virendra Rajput (BkVirendra)

home me my projects

Using Dropbox as your database backup space

By Virendra Rajput Tagged:

Recently, due to loss of hardware on AWS, we ( lost access to our EC2 instance, and Amazon couldn’t do anything to help us out it.

And well since we already keep everything backed up, it wasn’t much of a big deal to spawn a new instance and get back online. Also with that, Markitty had its first down time since the launch.

But it taught me a lesson that we couldn’t really trust AWS infrastructure with our customers data.

We already use Dropbox at Markitty, so I decided to trust it with DB backups. We make use of Postgresql as our main Database on our Django stack.

So, I hacked this python script that would take a regular backup of our main database and upload it to one of our Dropbox folders.

It includes 3 main files: is the shell script that makes use of pg_dump to get the compressed backup of the database. is the Python script that uploads the database to the Dropbox folder.

client_secrets.json stores the credentials including app_key, app_secret, access_key and access_secret.

You need to provide the DB_Username and DB_Name in

Follow these steps to setup the Dropbox app:

  1. You will need to create a Dropbox app, to get the Appkey and AppSecret. You can create it here (select the App Type as Core and select the Permission type as Full Dropbox)

  2. Once the app is successfully created, Dropbox will provide you the app_key and app_secret. Provide this app_key and app_secret in client_secrets.json (please do not share your App_Key and App_Secret publicly).

  3. Then execute the, it will generate an authentication link which you will need to open in your web browser. Press the Allow button, and hit Enter in the shell.

  4. It will then print the access_key and the access_secret, that you will need to provide in the client_secrets.json And you are done with the Dropbox setup. 

After that, you can setup a Cron job that will execute the everyday and get your Database backup in your Dropbox folder. The scripts all yours under Creative Commons License :-)

You can fork it on Github here.