MongoDB - Dump Restore

Dump DB from mLAB:

mongodump -h x.mlab.com:15799 -u mongo-admin -p root --authenticationDatabase admin -d db -o /x/dumps

Dump DB from Docker host:

mongodump -h 127.0.0.1:27017 -u root -p x --authenticationDatabase admin -d db -o dump/

Restore locally no auth:

mongorestore --db db /root/dumps/db/

Restore locally with auth:

mongorestore --username root --password 'x' --authenticationDatabase admin --db db /x/dumps/db/

Restore in mLAB:

mongorestore -h x.mlab.com:15799 -u mongo-admin -p root --authenticationDatabase admin -d db /x/dumps

Restore productions in staging:

rm -R /var/lib/docker/volumes/x/_data/dump/x/
cp -R /var/lib/docker/volumes/xxx/_data/dump/x /var/lib/docker/volumes/x/_data/dump/x/
mongorestore --drop --username root --password 'x' --authenticationDatabase admin --db db /data/db/dump/x/

Dump DB from container:

45 */1 * * * root /usr/bin/docker exec x sh -c "mongodump -h 127.0.0.1:27017 -u root -p x --authenticationDatabase admin -d x -o /x/x/x/" > /dev/null 2>&1

Dump collection as JSON from container:

45 */1 * * * root /usr/bin/docker exec x sh -c "mongoexport -h 127.0.0.1:27017 -u root -p x -c x --authenticationDatabase admin -d x -o /x/x/x/x.json" > /dev/null 2>&1

Restore DB from container:

5 0 * * 0 root /usr/bin/docker exec x sh -c "mongorestore -h 127.0.0.1:27017 --drop --username root --password 'x' --authenticationDatabase admin --db x /x/db/dump/x/" > /dev/null 2>&1