Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Backup MongoDB databases with Dropbox and Dokku
#!/bin/bash
set -e
echo "Backing up MongoDB databases to Dropbox ..."
dt=$(date +"%Y-%m-%d")
echo " today is $dt"
BACKUP_PATH=~/Dropbox/mongo/backup
echo " creating $BACKUP_PATH .."
dbs=$(dokku mongo:list | grep -v ===)
for db in $dbs
do
echo " backing up $db ..."
fp=$BACKUP_PATH/$(date +"%Y")/$db
mkdir -p $fp
f=$fp/$(date +"%Y-%m")-$db.dump.gz
dokku mongo:export $db > $f
echo " written $f"
dp=$BACKUP_PATH/daily/$(date +"%A")
mkdir -p $dp
d=$dp/$db.dump.gz
cp $f $d
done
@dblock
Copy link
Author

dblock commented Jul 3, 2018

The updated version creates a monthly and day of the week version. This saves space and still gives you the last 7 days of backups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment