Recently, due to loss of hardware on AWS, we (markitty.com 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:
db_backup.sh
is the shell script that makes use of pg_dump to get the compressed backup of the database.
uploader.py
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 db_backup.sh
.
Follow these steps to setup the Dropbox app:
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 asFull Dropbox
)Once the app is successfully created, Dropbox will provide you the
app_key
andapp_secret
. Provide thisapp_key
andapp_secret
inclient_secrets.json
(please do not share yourApp_Key
andApp_Secret
publicly).Then execute the uploader.py, 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.
It will then print the
access_key
and theaccess_secret
, that you will need to provide in theclient_secrets.json
And you are done with the Dropbox setup.
After that, you can setup a Cron job that will execute the db_backup.sh 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.