Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to back up and restore MongoDB data in Linux system

2025-02-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Today, I will talk to you about how to back up and restore MongoDB data in the Linux system. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

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

Restore 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 enables authenticated login, you need to add the parameter-- authenticationDatabase=admin

Because the mongodb used by the author turns on authentication login, this parameter is used in both backup and restore.

Having checked the relevant information, it is said that enabling authentication (auth=true) will cause the database to slow down, but the author has not encountered it yet. It is speculated that it will only occur when there is a certain amount of data. After all, we have to filter it. If the server is on the public network, it is recommended to enable authentication. If it is in the private network, authentication is not required, but it is necessary to ensure the security of the server. For example, specify IP to connect to the mongodb database.

If you are importing and exporting locally and the port has not been changed, the-h and-- port parameters do not need to be added.

Also, the user name that uses the import and export needs to have database administration permissions.

Explain the commands used.

1.-address of the server where the h:MongoDB is located

2.-d: the database instance to be restored, such as test. Of course, this name can also be different from that of backup, such as test2.

3.-o: the location of the backup data, such as / data/dump. Of course, this directory needs to be established in advance. After the backup is completed, the system automatically establishes a test directory under the dump directory, in which the backup data of the database instance is stored.

4.-- directoryperdb: where the backup data is located, for example: / data/dump/test, why add an extra test here instead of the dump at the time of backup? check the tips for yourself!

5.-- drop: when restoring, delete the current data first, and then restore the backed-up data. That is to say, after recovery, the data added and modified after backup will be deleted, so use it with caution.

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 (/ S1 for sets s2)

-- 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 is 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 combat operation:

Backup of mongodb database:

/ data/mongodb/bin/mongodump-u root-p 123456-d test-o authenticationDatabase=admin

For the recovery of mongodb database, the author's recovery folder path is / mnt/mongodb20160905/:

Refer to the following code:

[root@host1 bin] # / mnt/mongodb/bin/mongorestore-uroot-p123456-d test / mnt/mongodb20160905/-- authenticationDatabase=admin

If there is an error in the import, you can add * at the end of the folder to try:

[root@host1 bin] # / mnt/mongodb/bin/mongorestore-uroot-p123456-d test / mnt/mongodb20160905/*-- authenticationDatabase=admin

After reading the above, do you have any further understanding of how to back up and restore MongoDB data in the Linux system? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report