Use mongodump and mongorestore to back up and restore Data

Source: Internet
Author: User
Tags mongodump mongorestore
Mongodump and mongorestore are two commands used to back up and recover mongodb databases. They are located in the bin folder of the mongodb installation directory. The backup file exported by mongodump is in binary format. Each file has two backup files, file name. bson and file name. metadata. json. Let's take a look at the example of mongodump.

Mongodump and mongorestore are two commands used to back up and recover mongodb databases. They are located in the bin folder of the mongodb installation directory. The backup file exported by mongodump is in binary format. Each file has two backup files, file name. bson and file name. metadata. json. Let's take a look at the example of mongodump.

Mongodump and mongorestore are two commands used to back up and recover mongodb databases. They are located in the bin folder of the mongodb installation directory.

The backup file exported by mongodump is in binary format. Each file has two backup files, file name. bson and file name. metadata. json.

Let's take a look at the example of mongodump:

./Mongodump-d vodlite3-o/mibackup/

This command backs up the vodlite3 database to the/mibackup/directory. We can see the backup structure in the mibackup directory as follows:

Mongodump provides the following options:

-Help
View help information.

-V [-- verbose]
Show more debugging information.

-Version
The command version is displayed.

-H [-- host] arg
The IP address of the host where the mongodb database is located.

-Port arg
The port used when mongodb is started. You can also use the-host: port format to directly specify the host and port.

-Ipv6
Whether ipv6 is supported.

-U [-- username] arg
Specify the login user name.

-P [-- password] arg
Specify the logon password.

-Dbpath arg
Access the mongod database file in the specified path directly from the mongod server. To use this parameter, You need to lock the specified data directory. Therefore, you must first disable the mongod service that uses this directory.

-Directoryperdb
If the dbpath directory is specified, each db is saved to a separate folder.

-Journal
Enable journaling

-D [-- db] arg
Prepare the backup database.

-C [-- collection] arg
Backup set.

-O [-- out] arg
The directory where the exported data is to be saved. If the parameter is "-", the exported data is directly displayed on the console.

-Q [-- query] arg
Json query

-Oplog
Use oplog for point-in-time snapshotting

-Repair
Try to repair the damaged database.

-ForceTableScan
Force table scan.

Mongorestore is used to restore the data exported by mongodump. The syntax format is as follows:

Mongorestore [options] [directory or filename to restore from]

Use this command to restore the data you just backed up:

Mongorestore -- db vodlite3 -- directoryperdb D: \ vodlite3

The available options are as follows:

-Help
Produce help message

-V [-- verbose]
Be more verbose (include multiple times for more verbosity e.g.-vvvvv)

-Version
Print the program's version and exit

-H [-- host] arg
Mongo host to connect to (/s1, s2 for sets)

-Port arg
Server port. Can also use-host hostname: port

-Ipv6
Enable IPv6 support (disabled by default)

-U [-- username] arg
Username

-P [-- password] arg
Password

-Dbpath arg
Directly access your D database files in the given path, instead of connecting to a login D server-needs to lock the data directory, so cannot be used if a login D is currently accessing the same path

-Directoryperdb
If dbpath specified, each db is in a separate directory

-Journal
Enable journaling

-D [-- db] arg
Database to use

-C [-- collection] arg
Collection to use (some commands)

-Objcheck
Validate object before inserting

-Filter arg
Filter to apply before inserting

-Drop
Drop each collection before import

-OplogReplay
Replay oplog for point-in-time restore

-KeepIndexVersion
Don't upgrade indexes to newest version

Reference link:
1. mongodump's official help documentation
2. mongodbde backup and recovery policies

Original article address: Use mongodump and mongorestore to back up and restore data. Thank you for sharing it with me.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.