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

What backup and restore commands are available in mongodb

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article introduces what backup and restore commands are available in mongodb, the content is very detailed, interested friends can refer to, I hope it can be helpful to you.

Backup:

Mongodump-uroot-ppassword-- port=27017-- authenticationDatabase=admin-h hostname-d databasename-o / data/backup/mongodump/

-the address of the server where the h:MongDB is located, for example: 127.0.0.1. Of course, you can also specify the port number: 127.0.0.1 27017.

-d: database instance that needs to be backed up, for example: database_name

-o: where the backup data is stored

Mongo full database recovery

$mongorestore-h host-d database_name-directoryperdb / mg_data/backup/mongodump/database_name

Single collection backup

Mongos > mongoexport-h dbhost-d dbname-c collectionname-f collectionKey-o dbdirectory

-h: address of the server where MongoDB is located

-d: database instance to be restored

-c: collection to be restored

-f: fields to be exported (omitted to all fields)

-o: indicates the name of the exported file

Single collection recovery

Mongos > mongoimport-d dbhost-c collectionname-type csv-headerline-file

-type: indicates the file format to import

-headerline: specify that the first row is not imported, because the first row is the column name

-file: indicates the path of the file to be imported

At the same time, you need to make a physical backup of the library, usually a snapshot

Lvcreate-L10G-s-n data_snapshot / dev/vg01/lv01

After the project team has finished, then remove this snapshot and ok it.

# lvremove / dev/vg01/data_snapshot

If you need to restore, the steps are as follows

Mkdir / snapshort

Mount / dev/datavg01/vg01 / snapshort/

Stop the mongodb, and the backup files of the cp snapshot go to the corresponding data directory of mongo.

Start mongo, and you can.

# mongodb bulk insert data drill Test #

For (var iTuno Bandi)

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

Database

Wechat

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

12
Report