Created
August 11, 2010 20:58
-
-
Save freegenie/519750 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# This script is supposed to be executed on the | |
# machine which hosts the database. | |
# | |
# What it does is to dump the entire database in | |
# separate directories, and then tgzip each single | |
# database. | |
# Example: | |
# ./mongobackup.sh /var/backup/zipped_mongodb | |
# | |
# Store username and password to access the mongodb | |
# instance as admin | |
USERNAME="" | |
PASSWORD="" | |
if test -n "$PASSWORD" ; then | |
PASSWORD_OPTION=" -p $PASSWORD" | |
fi | |
if test -n "$USERNAME" ; then | |
USERNAME_OPTION=" -u $USERNAME " | |
fi | |
if test -n "$1" ; then | |
DESTINATION_PATH="$1" | |
DESTINATION_OPTION=" -o $DESTINATION_PATH" | |
else | |
DESTINATION_PATH='dump' # mongodb's defautl | |
fi | |
COMMAND="mongodump --directoryperdb $USERNAME_OPTION $PASSWORD_OPTION $DESTINATION_OPTION" | |
echo $COMMAND | |
# Execute | |
$COMMAND | |
if test $? != 0 ; then | |
echo "mongodump command did not complete. Exiting." | |
exit 130 | |
fi | |
# move to destination path, zip and clean | |
cd $DESTINATION_PATH | |
for i in $(ls) ; do | |
tar zcvf $i.tar.gz $i | |
rm -rf $i | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment