A couple of weeks ago I stumbled over a Dropbox bash script which makes the task of writing scripts that interact with Dropbox trivial!
What I ended up with was a simple PostgreSQL backup script for a (another) blog that I'm hosting.
To make it work, download the dropbox_uploader.sh and run it. It will prompt you and help you setup your Dropbox account to work with the script.
Then create a new bash script file containing the code below and alter it for your setup:
#!/usr/bin/env bash # Create a dumpfile with todays date (YYYY-MM-DD) FILENAME="NAME_OF_DUMP_$(date +%Y-%m-%d).sql" DATABASE= some_database pg_dump $DATABASE > $FILENAME ./dropbox_uploader.sh upload $FILENAME rm $FILENAME
Finally add the script as a cron entry. I decided to run it every day at 03:00 (AM).
$ sudo nano /etc/cron.allow # Add your username to this file
$ crontab -e
Add something like this to crontab:
0 3 * * 1 /path/to/script >/dev/null 2>&1
>/dev/null 2>&1 parts redirects output from the script to /dev/null or
else crontab will try to e-mail it to you.
This could do with some added finesse like removing old backups or else your Dropbox can get pretty crowded if you have a large database.