12345678910111213141516171819202122232425262728293031323334 |
- #!/usr/bin/env bash
- for rs in "$@"; do
- mongo --host $rs --eval 'db'
- while [ $? -ne 0 ]; do
- echo "Waiting for $rs to become available"
- sleep 3
- mongo --host $rs --eval 'db'
- done
- done
- mongo --host rs0/$1 --eval 'db.accounts.find( { "username" : "admin" } )' prod | grep ADMIN_GLOBAL > /dev/null
- if [ $? -eq 0 ]; then
- echo "Replset with database exists"
- exit 0
- fi
- i=0
- for rs in "$@"; do
- if [ "$rs" != "$1" ]; then
- MEMBERS="$MEMBERS ,"
- fi
- MEMBERS="$MEMBERS {_id: $i, host: \"$rs\" }"
- i=$((i+1))
- done
- mongo --host $1 --eval "rs.initiate({_id: \"rs0\", version: 1, members: [$MEMBERS]})"
- sleep 3
- mongo --host $1 --eval 'rs.status()'
- sleep 10
- sleep 30
- cd /restore
- mongorestore --host rs0/$1 .
|