[Mongo] Mongodump and mongorestore backup and restore mongo
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