Reputation: 122240
If i want to do a generic backup for all databases in mongodb, is it that all i have to do is:
$ mongodump
And if i want to restore the latest dump i've created, all i need to do is:
$ mongorestore
Upvotes: 6
Views: 11282
Reputation: 29
restore all
mongorestore --host=<host> --port=<port> --username=<username> --authenticationDatabase=<authenticationdatabase> --nsInclude "*.*" <path to dump>
backup all
mongodump --ssl --host <domain> --port <port> -p <password> --authenticationDatabase <authenticationdatabase> -u <username> -p <password> --out <dir path>
If you want to backup databases use:
mongodump --ssl --host <domain> --port <port> -p <password> --authenticationDatabase <authenticationdatabase> -u <username> -p <password> --out <dir path>
if the database has ssl enabled include the --ssl
flag
if you don't include the --out
mongodump
will create a "/dump" directory.
Inside the dump or specified backup directory you'll find directories with the names of your databases, inside each of them, you'll find the backups files, for each collection you'll find a ".bson" and a ".metadata.json"
To restore all the databases use:
mongorestore --ssl --host=<host> --port=<port> --username=<username> --authenticationDatabase=<authenticationdatabase> --nsInclude "*.*" <path to dump>
Again if the database has ssl enabled include the --ssl
flag if not just remove it.
the --nsInclude
flag tell mongorestore
which databases or collections you want to restore.
Examples:
--nsInclude=test.users
this will backup the users collection of the database test, and therefore will fail if the path to the dump is anything but the path to the users.bson of that particula database
To include all the database and all the collections use --nsInclude=*.*
or --nsInclude *.*
then define the path to all the collection directories of your backup
Upvotes: 2
Reputation: 3150
The backups are stored in the directory that you have specified with the --out option in command line. If you do not specify any output dir the backup will be placed to ./dump directory. With the mongorestore you have to specify the directory where you have dumped before as a command line argument.
On sharded environment the backup will be flattened if you use mongodump through a mongos. After restore you will have to re-shard the collections. so restoring not always effortless. See documentation: http://docs.mongodb.org/manual/tutorial/backup-small-sharded-cluster-with-mongodump/
You can dump directly the db folders too, check the cli options.
For sharded clusters you can check the possibilities here: http://docs.mongodb.org/manual/administration/backups/#sharded-cluster-backups
Upvotes: 8