Created
July 13, 2020 08:35
-
-
Save marantz/b092f4c10357138b864191b3c132cbd1 to your computer and use it in GitHub Desktop.
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/sh | |
| export MONGODB_HOME=/opt/mongodb | |
| export MONGODB_BIN=${MONGODB_HOME}/bin | |
| export MONGO="${MONGODB_BIN}/mongo --host centos --port 27018 --quiet" | |
| export MONGODUMP="${MONGODB_BIN}/mongodump --host centos --port 27018" | |
| export BACKUP_DIR=${MONGODB_HOME}/data/backup | |
| echo "BACKUP DATABASE" | |
| _DB_LIST=(`echo "show dbs" | $MONGO | grep -v admin | grep -v config | awk {'print $1'}`) | |
| for _DB in ${_DB_LIST[@]} | |
| do | |
| #################################################### | |
| # FETCH DB LIST FOR COLLECTION | |
| _COL_LIST=(`echo "show collections" | $MONGO $_DB`) | |
| _COL_SIZE=${#_COL_LIST[@]} | |
| #echo "SIZE=$_COL_SIZE" | |
| if [ $_COL_SIZE -eq 0 ] | |
| then | |
| echo "SKIP [$_DB] Collection Empty!" | |
| continue | |
| fi | |
| for _COL_NAME in ${_COL_LIST[@]} | |
| do | |
| ############################################ | |
| # COLLECTION DUMP START | |
| echo "####################################################"; | |
| echo "DUMP [$_DB]@[$_COL_NAME]" | |
| echo "####################################################" | |
| $MONGODUMP \ | |
| -d $_DB \ | |
| -c $_COL_NAME \ | |
| -o $BACKUP_DIR \ | |
| -q='{"_id":-1}' | |
| # COLLECITON DUMP END | |
| ############################################ | |
| done | |
| # END OF DB FETCH LOOP | |
| #################################################### | |
| done | |
| cd $BACKUP_DIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment