Copy / Backup MongoDB

Directly copy db from ip :

1
2
3
mongo <ip>
use admin
db.runCommand({copydb:1, fromdb:"<DB Name>", todb:"<DB Name>", fromhost:"<DB HOST IP>"})

Export / Restore DB

1
2
3
4
5
6
# Export
mongodump --db <dbname>

# Restore
mongorestore --port <port number> <path to backup folder>
# e.g. mongorestore --port 27017 X:\dump

Note :

  1. Run commands in administrator mode
  2. If commands not found, excute commands under mongodb bin folder, windows default path : C:\Program Files\MongoDB\Server\3.2\bin\

Reference :

https://docs.mongodb.com/manual/tutorial/backup-and-restore-tools/