0

I am trying to backup mongoDB database using mongodump from replicaset. Script I am using works fine to dump db from remote to local. Same script errors out saying authentication failed when I trying to dump from replicaset.

Is there a simple way I can have whole db dump otherwise specific db dump will be preferred.

#!/bin/bash

HOST="mongorep1:27017,mongorep2:27017,mongorep3:27017"
REMOTE_DB="Products"
LOCAL_DB="Products"
USER="AppUser"
PASS="password"

## DUMP THE REMOTE
echo "Dumping '$HOST:$PORT/$REMOTE_DB'..."
mongodump --host $HOST --db $REMOTE_DB -u $USER -p $PASS --out dump/`date +"%m-%d-%y"`

echo "Done."

Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user557657
  • 856
  • 1
  • 12
  • 35

1 Answers1

0

When using replicaset with mongodump, you need to prefix the string pass to --host with the replicaset name. For instance if your replicaset name is myreplicaset_name then it should look like -

HOST="myreplicaset_name/mongorep1:27017,mongorep2:27017,mongorep3:27017"

Abhay PS
  • 4,015
  • 5
  • 25
  • 32
  • Hi @Abhay. I tried with prefix but it is dumping admin db not the Products db. I am using products credential. `#!/bin/bash HOST="rs0/mongorep1:27017,mongorep2:27017,mongorep3:27017" REMOTE_DB="Products" LOCAL_DB="Products" USER="AppUser" PASS="password" ## DUMP THE REMOTE echo "Dumping '$HOST:$PORT/$REMOTE_DB'..." mongodump --host $HOST:$PORT -u $USER -p $PASS -d $REMOTE_DB --out /usr/local/bin/dump/`date +"%m-%d-%y"` echo "Done."` – user557657 Nov 27 '18 at 15:20
  • 1
    If you are able to dump admin with the credentials then you can dump all. Just remove the `-d $REMOTE_DB` part and it will dump all the dbs. – Abhay PS Nov 27 '18 at 15:56