Last active
June 11, 2020 12:20
-
-
Save dblock/acd70c84af3a3531a510 to your computer and use it in GitHub Desktop.
Backup MongoDB databases with Dropbox and Dokku
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.