Mongodb database backup and recovery

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

Only one cm database is migrated. The target database is version 2.4.8 and the original database is version 2.4.6. Therefore, hot backup is used for migration.
The official document is very simple:

The code is as follows: Copy code
Mongodump-host mongodb.example.net-port 27017

Mongorestore-portHowever, the main issue is user permissions.

At first, there was only one cm user in the cm Database. Its permissions were readWrite and dbAdmin,
Therefore, when exporting data, you must specify another parameter:-authenticationDatabase cm, indicating that the user is in the cm Library and is not in the admin Library...

This user has the read and write permissions on the data, but does not have the read permission for the db. system. users table. Therefore, the user is prompted to have no permissions when exporting the users table.

Gg: the userAdmin permission is required .. This permission is too high.

Add a dump user:

The code is as follows: Copy code
Use cm;
Db. addUser ({user: "dump", pwd: "123456 & Prime;, roles: [" readWrite "," userAdmin "]})

You can use the following command to quickly export data:

The code is as follows: Copy code
./Bin/mongodump-u dump-p-authenticationDatabase cm-db cm-out/data/dump

What about import?
The target database only has one root user in the admin Database. The permission is userAdminAnyDatabase,

An error occurred while trying to import data with the root user...
Do you also need to create a dump user with readWrite and userAdmin in the cm database?
Will the system. users table of the target database be overwritten during import? It is worth a test.
Therefore, the user dump is created in the target database, and the password is 111111, which is different from the dump password of the original database.
Import:

The code is as follows: Copy code
./Bin/mongorestore-u dump-p-authenticationDatabase cm-db cm/home/zhaokunyao/dump/cm

There will be a prompt:
Tue Nov 19 20:03:10. 213 warning: Restoring to cm. system. users without dropping. Restored data will be inserted without raising errors; check your server log
Server log information related to the user table...

The final result is:
The users table of the target database is merged with the users table of the source database.
All users in the source database are imported to the users table, except the dump user. The target database's dump user password is still 111111.
Note: the db. system. users table has a unique key (user)

Finally, the dump users of the two databases are deleted and closed for 7 minutes.

A small problem was also found during migration:
Follow the normal method to install mongdb, and the following Warning is reported after the connection:

Mon Nov 18 17:36:26. 641 [initandlisten] ** WARNING: You are running on a NUMA machine.
Mon Nov 18 17:36:26. 641 [initandlisten] ** We suggest launching every D like this to avoid performance problems:
Mon Nov 18 17:36:26. 641 [initandlisten] ** numactl-interleave = all other D [other options]

Numactl-interleave = all slave D is required to start mongod.

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.