Version: mongodb3.2.6
Backup format:
/data/mongodb/bin/mongodump-h IP--port Port number-U User-p password-d database name-O storage path
Recovery format:
/mnt/mongodb/bin/mongorestore -H IP--port port number- u User name-p password-d database name backup folder name/*
Note that if MongoDB is turned on for authentication login, you need to add parameter--authenticationdatabase=admin,
This parameter is used in both backup and restore because the author uses MongoDB to turn on the authentication login.
Read the relevant information, said to be open authentication (auth=true) will cause the database to become slow, the author has not encountered, presumably should be in a certain amount of data in the case will appear. After all, to filter it down. If the server is in the public network, the proposal or to open the certification, if the real intranet, do not have authentication, but to ensure that the server security oh, such as the designated IP can be connected to the MongoDB database
If you import the export locally and the port is not changed, the-H and--port parameters are not added.
There is also a user name that is exported using import needs to have database administration permissions Oh.
Explain the command you used.
1. - H : MongoDB server address
2. - D : A database instance that needs to be restored, for example: Test, which can also be different from the backup time, such as Test2
3. - o : Backup data storage location, for example:/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.
4. --directoryperdb : The location of the backup data, for example:/data/dump/test, why do you want to add a test, instead of the backup time dump, the reader to check their own tips!
5. --drop : When recovering, delete the current data and then restore the backed up data. That is, after the recovery, add the modified data after the backup will be deleted, use with caution Oh!
Original explanation:
?
- 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 (<set name>/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 --authenticationdatabase Arg User Source (defaults to dbname) --authenticationmechanism 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 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 Timestamp (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 |
Actual operation:
MongoDB Backup of the database:
/data/mongodb/bin/mongodump-u root-p 123456-d test-o/data/mongodb_$ (date +%f)--authenticationdatabase=admin
MongoDB recovery of the database, the author's Recovery folder path is/mnt/mongodb20160905/:
Refer to the following code:
[Email protected] bin]#/mnt/mongodb/bin/mongorestore-uroot–p123456-d test/mnt/mongodb20160905/ -- Authenticationdatabase=admin
If the import has an error: you can add * to the folder after:
[email protected] bin]#/mnt/mongodb/bin/mongorestore-uroot–p123456-d test/mnt/mongodb20160905/* --authenticationdatabase=admin
A tutorial on backing up and recovering MongoDB data in a Linux system