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

[Mongo] Mongodump and mongorestore backup and restore mongo

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

Share

Shulou(Shulou.com)06/01 Report--

The mongoexport tool in 1.mongoexport Export and mongoimport Import Mongodb can export a collection to a file in JSON format or CSV format. You can specify exported data items through parameters, or you can export data based on specified criteria. The specific usage of mongoexport is as follows:

Parameter description:

-h: indicates the IP of the database host

-u: indicates the user name of the database

-p: indicates the password of the database

-d: indicates the name of the database

-c: specify the name of collection

-f: indicates which columns to export

-o: indicates the name of the file to be exported

-Q: indicates the filtering criteria for the exported data

P.p1 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 19.0px Font: 13.0px 'Helvetica Neue'} span.s1 {color: # 00a2ff} mongoexport-h 172.31.36.77-- port 27017-u collection-p 78hRdJEnJcHRb4qA-d collection-c redefine-collection-f _ id,country,ctime,deviceId,dpi,event_id,event_info,gaid,isp,locale,mac,model,name,net,os,os_ver,resolution,sdk_ver,session_id,tz,uid,vendor-- type=csv-o. / mongoexport_20180504.csv

Https://www.cnblogs.com/mengyu/p/7718311.html

2 mongodump and mongorestore backup: (specify the directory to which the backup database is backed up)

[root@iZ2ze66bhrbxkc31nljgjnZ backdump] # / usr/local/mongodb/bin/mongodump-d rundb-o / soft/backdump/

[root@iZ2ze66bhrbxkc31nljgjnZ backdump] # ll

Drwxr-xr-x 2 root root 4096 Apr 26 18:10 rundb

Restore: (restore to a database, if it does not exist, it will be created. Delete the-drop parameter before restoring)

[root@iZ2ze66bhrbxkc31nljgjnZ backdump] # / usr/local/mongodb/bin/mongorestore-d rundb2 / soft/backdump/rundb/

Back up all databases:

[root@iZ2ze66bhrbxkc31nljgjnZ backdump] # / usr/local/mongodb/bin/mongodump-o / soft/backdump/

Restore all databases:

[root@iZ2ze66bhrbxkc31nljgjnZ backdump] # / usr/local/mongodb/bin/mongorestore-- drop-- dir / soft/backdump/

Backup does not specify a directory:

[root@iZ2ze66bhrbxkc31nljgjnZ backdump] # / usr/local/mongodb/bin/mongodump (a dump directory is generated under the current directory)

Restore: (default dump directory will be used)

[root@iZ2ze66bhrbxkc31nljgjnZ backdump] # / usr/local/mongodb/bin/mongorestore-- drop

2018-04-27T11:48:26.102+0800 using default 'dump' directory

2018-04-27T11:48:26.105+0800 building a list of dbs and collections to restore from dump dir

Back up a single collection

[root@iZ2ze66bhrbxkc31nljgjnZ soft] # / usr/local/mongodb/bin/mongodump-d rundb-c col-o. /

Restore a collection

[root@iZ2ze66bhrbxkc31nljgjnZ rundb] # / usr/local/mongodb/bin/mongorestore-d rundb-drop-dir / soft/rundb/col.bson

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