I have credentials for root user and I am using those credentials to automate db backup. Main aim is to create prototype for Automated DB backup and, for simplicity, I am using root. The script (I borrowed from article) looks like as follows:
#!/bin/bash #Force file syncronization and lock writes mongo admin -u "root" -p "root" --eval "printjson(db.fsyncLock())" MONGODUMP_PATH="/usr/bin/mongodump" MONGO_DATABASE="mydb" #replace with your database name TIMESTAMP=`date +%F-%H%M` S3_BUCKET_NAME="mydb" #replace with your bucket name on Amazon S3 S3_BUCKET_PATH="backup/mongo" # Create backup $MONGODUMP_PATH -d $MONGO_DATABASE # Add timestamp to backup mv dump mongodb-$HOSTNAME-$TIMESTAMP tar cf mongodb-$HOSTNAME-$TIMESTAMP.tar mongodb-$HOSTNAME-$TIMESTAMP # Upload to S3 s3cmd put mongodb-$HOSTNAME-$TIMESTAMP.tar s3://$S3_BUCKET_NAME/$S3_BUCKET_PATH/mongodb-$HOSTNAME-$TIMESTAMP.tar #Unlock database writes mongo admin -u "root" -p "root" --eval "printjson(db.fsyncUnlock())" #Delete local files #rm -rf mongodb-*
I am getting following error:
Failed: error getting collections for database
mydb
: error runninglistCollections
. Database:mydb
Err: not authorized onmydb
to execute command { listCollections: 1, cursor: {} }
Isnt root has all the access over all the databases? I am bit scared that I might run into situation where I am thinking to supersede something with root but It doesnt have the permission. This is the root cause of posting question. I want to avoid surprises like this in the future.
1 Answers
Answers 1
The error mentioned above was misleading for me. But my script was wrong or incomplete.
If you look at following line in my script:
$MONGODUMP_PATH -d $MONGO_DATABASE
I am not providing any user in Mongodump command and hence the error message. If I rewrite that line something as follows:
$MONGODUMP_PATH -d $MONGO_DATABASE --authenticationDatabase "admin" -u "dbowner" -p "pwd"
then error goes away.
0 comments:
Post a Comment