Home > AI > Database > MongoDB >

backup MongoDB

Step 1

$ mongodump 
--username {username} 
--password {password} 
--authenticationDatabase admin 
--db {dbname} // has to be specified or it will throw authentication error since not every db has the same authentication

Then, you can get the backup files in ~/dump/{dbname}

Step 2, how to convert bson to human-readable json

$ bsondump --pretty 
--outFile collection.json collection.bson

Step 3, restore backup data

$ mongorestore

rsync -avz root@cowpte.com:/root/dump/mnpte_test /Users/workmac/documents/work-web-nginx/sample-reactjs/mnpte_test

Leave a Reply