MongoDB Database Backup

Source: Internet
Author: User
Tags mongodb server server port mongodump mongorestore

1. Exporting data

mongoexport-d my_mongodb-c Choice-o Choice.dat

Parameter description:

-d indicates which library to use, in this case "My_mongodb"


-C indicates the table to be exported, in this case "choice"


-O indicates the name of the file to be exported, in this case "choice. Dat"


-H Server Address


2. Import data
mongoimport-d my_mongodb-c choice choice. dat


Parameter description:


-d indicates which library to use, in this case "My_mongodb"


-C indicates the table to be imported, in this case "choice"


3. Backup of the whole library:
Mongodump-h dbhost-d Dbname-o dbdirectory


-H:MONGDB the server address, for example: 127.0.0.1, you can also specify a port number: 127.0.0.1:27017
-D: The database instance that needs to be backed up, for example: test
-O: The data storage location of the backup, for example: C:\data\dump, of course, the directory needs to be established in advance, after the backup is completed, the system automatically establishes a test directory under the Dump directory, which holds the backup data of the database instance.


See the detailed help information below
D:\tool\mongodb\bin>mongodump--helpexport MongoDB data to BSON files.options:--help p                                        Roduce help Message-v [--verbose] is more verbose (include multiple times For more verbosity e.g-VVVVV)--version print the program ' s version and Exi t-h [--host] arg MONGO host to connect to (<set Name&gt ;/s1,s2 for sets)--port ARG server port. Can also use--host hostname:port--ipv6 enable IPv  6 Support (disabled by default)-U [--username] arg username-p [--password] arg password--authenticationdatabase arg user source (defaults to dbname)--au                                     Thenticationmechanism Arg (=MONGODB-CR)   Authentication mechanism--dbpath arg directly access Mongod database files In the given path, instead of connecting to a Mongod server                                        -Needs to lock the data directory, so cannot                      be used if a mongod is currently accessing the same path--directoryperdb Each db are in a separate directly (relevant only if dbpath specified  )--journal enable journaling (relevant only if DBPath specified)-d [--DB] arg database to use-c [--collection] arg collection to us                    E (some commands)-o [--out] arg (=dump) output directory or "-" for Stdout-q [--query] Arg JSON query--oPlog use Oplog for point-in-time snapshotting--repa IR try to recover a crashed database--forcetablescan force a table SCA N (do not use $snapshot)



4. Recovery of the whole library:
Mongorestore-h dbhost-d Dbname–directoryperdb dbdirectory


-h:mongodb server Address
-D: The database instance that needs to be restored, for example: Test, this name can be different from the time of backup, such as Test2
–directoryperdb: Where to back up data, for example: C:\data\dump\test, why add a test instead of a dump at backup time
–drop: When recovering, delete the current data and then restore the backed up data. That is, after the restore, the added modified data after the backup will be deleted


See the detailed help information below
D:\tool\mongodb\bin>mongorestore--helpimport BSON files into MongoDB.usage:mongorestore [options] [directory or                      FileName to restore from]options:--help produce help message-v [--verbose]  Be + verbose (include multiple times for more verbosity e.g.-VVVVV) --version Print the program ' s version and exit-h [--host] arg MONGO h                            OST to connect to (<set name>/s1,s2 for sets)--port arg Server port. Can also use--host hostname:port--ipv6 enable IPv  6 Support (disabled by default)-U [--username] arg username-p [--password] arg password--authenticationdatabase arg user source (defaults to dbname)--au ThenticAtionmechanism Arg (=MONGODB-CR) authentication mechanism--dbpath arg                                        Directly access Mongod database files in the given path, instead of Connecting to a Mongod server-needs to Loc                                        K The data directory, so cannot being used if a mongod is currently                                        Accessing the same path--DIRECTORYPERDB each db are in a separate directly (relevant only if dbpath specified)--journal enable Journ Aling (relevant only if dbpath specified)-d [--db] Arg da                            Tabase to Use-c [--collection] arg collection to use (some commands)--objcheck Validate Object BefoRe inserting (default)--noobjcheck don ' t 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- -oploglimit arg include Oplog entries before the provided time Stamp (Seconds[:ordinal]) during the Oplog replay; The ordinal value is optional--keepindexversion don ' t upgrade                      Indexes to newest version--nooptionsrestore don ' t restore collection options--noindexrestore Don ' t restore indexes--w ARG (=0) minimum number of replicas per write















MongoDB Database Backup

Related Article

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.