Source

scripts / backup-mongodb.sh

#!/bin/sh

DATABASES='default'  # space-separated


echo "Making backups of MongoDB databases ($DATABASES)..."
echo
for DBNAME in $DATABASES; do
    BACKUP_DIR="$HOME/backup/mongodb"
    cd $BACKUP_DIR
    FILENAME="$DBNAME-`date +%Y-%m-%d-%H%M`"
    echo "  dumping database \"$DBNAME\" as \"$BACKUP_DIR/$FILENAME\""
    mongodump -o $FILENAME -d $DBNAME
    tar jcf $FILENAME.tar.bz2 $FILENAME
    rm -rf $FILENAME
    echo '---'
done
echo "...done."