In today’s article, we will talk about MongoDB Logical Backup Restore Mongodump And Mongorestore.
Taking MongoDB Instance Backup
| 
					 1  | 
						$ mongodump  | 
					
MongoDB Instance Restore
| 
					 1  | 
						$ mongorestore  | 
					
Backup and Restore a Single Database
1. We take backup of testdb database.
| 
					 1  | 
						$ mongodump --db testdb -o /mongodb/backup  | 
					
2. After the backup is taken, we drop testdb.
| 
					 1 2 3 4 5 6 7 8 9  | 
						> use testdb switched to db testdb > db.dropDatabase() { "ok" : 1 } > show dbs admin       0.000GB config      0.000GB journaldev  0.000GB local       0.000GB  | 
					
3. We restore testdb and check.
| 
					 1 2 3 4 5 6 7  | 
						$ mongorestore --db testdb /mongodb/backup/testdb > show dbs admin       0.000GB config      0.000GB journaldev  0.000GB local       0.000GB testdb      0.000GB  | 
					
Collection Backup and Restore
1. We take backup of test collection.
| 
					 1  | 
						$ mongodump -d testdb -o /mongodb/backup --collection test  | 
					
2. We drop the test collection.
| 
					 1 2 3 4 5 6 7 8  | 
						2. test collection’ ı drop edilir. > use testdb switched to db testdb > db.test.drop() true > show collections musteriler  | 
					
3. We restore the test collection and make a check.
| 
					 1 2 3 4 5 6 7  | 
						$ mongorestore -d testdb -c test /mongodb/backup/testdb/test.bson > use testdb switched to db testdb > show collections musteriler test  | 
					
 
