I’ve recently moved my Slack bots to Dokku running on DigitalOcean. The bots use local MongoDB database containers provided by the dokku-mongo plugin. Here’s the entire setup, from installation to backup to Dropbox.
Create a Database
This starts a MongoDB instance which is not accessible from the outside world.
Backup with Dropbox
You can certainly rely on DigitalOcean’s weekly system backup or any other backup system. However I wanted a daily backup and a historical archive of the data in each individual MongoDB. I also wanted it to be free or cheap.
~/.dropbox-dist, and you can manually start Dropbox via
Configure First Time
Run Dropbox for the first time.
Dropboxd will tell you “This client is not linked to any account …“ and give you a link copy that and paste it in your local web browser, authenticate and validate the new connection. You can stop the daemon with Ctrl+C.
/etc/init.d/dropbox from this gist, eg.
sudo vi /etc/init.d/dropbox. Edit
DROPBOX_USERS below (eg.
user1 user2). I just use
Set it to automatically start on boot.
Start the service.
Check that it’s running.
If you need selective sync, check out this blog post.
Backup MongoDB Databases
Create an Export Script
Dropbox/bin/dokku-mongo-export.sh. It enumerates Dokku MongoDB databases and runs
mongo:export on them. The archive that mongo:export produces is gzipped archive output of
Notice I just put the script in my Dropbox ;)
The latest version of this script is here as a gist. Make sure to
chmod 700 dokku-mongo-export.sh and run it manually to test.
Run the Script Daily
Note that only executables without an extension run from
/etc.cron.*/, hence the name of the symbolic link is different from the script.
The archive that mongo:export produces is gzipped archive output of
mongodump. To restore in Dokku, use
mongo:import. To restore locally, run
mongorestore --gzip --archive=filename.
This will neatly organize your database backups in Dropbox.