1. 程式人生 > >MongoDB 4.0 備份恢復工具引數介紹

MongoDB 4.0 備份恢復工具引數介紹

# ./mongo --version
MongoDB shell version v4.0.2
git version: fc1573ba18aee42f97a3bb13b67af7d837826b47
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
    distmod: rhel70
    distarch: x86_64
    target_arch: x86_64

# ./mongodump --help
Usage:
  mongodump <options>

Export the content of a running server into .bson files.

Specify a database with -d and a collection with -c to only dump that database or collection.

See http://docs.mongodb.org/manual/reference/program/mongodump/ for more information.

general options:
      --help                                               列印工具的幫助資訊
      --version                                            列印工具的版本並退出

verbosity options:
  -v, --verbose=<level>                                     更詳細的日誌輸出(包括多次以獲得更多詳細資訊,例如-vvvvv,或指定數值,例如--verbose = N)
      --quiet                                               隱藏所有日誌輸出

connection options:
  -h, --host=<hostname>                                     連線mongodb的主機,針對複製集的格式如下setname/host1,host2
      --port=<port>                                         mongodb伺服器的埠 (也可以使用 --host hostname:port)

ssl options:
      --ssl                                                 連線到啟用了ssl的mongod或mongos
      --sslCAFile=<filename>                                包含證書頒發機構的根證書鏈的.pem檔案
      --sslPEMKeyFile=<filename>                            包含證書和金鑰的.pem檔案
      --sslPEMKeyPassword=<password>                        必要時,用於解密sslPEMKeyFile的密碼
      --sslCRLFile=<filename>                               包含證書吊銷列表的.pem檔案
      --sslAllowInvalidCertificates                         繞過伺服器證書的驗證
      --sslAllowInvalidHostnames                            繞過伺服器名稱的驗證
      --sslFIPSMode                                         使用已安裝的openssl庫的FIPS模式


authentication options:
  -u, --username=<username>                                 用於身份驗證
  -p, --password=<password>                                 用於驗證的密碼
      --authenticationDatabase=<database-name>              儲存使用者憑據的資料庫
      --authenticationMechanism=<mechanism>                 使用的身份驗證機制

namespace options:
  -d, --db=<database-name>                                  使用的資料庫
  -c, --collection=<collection-name>                        使用的集合

uri options:
      --uri=mongodb-uri                                     mongodb uri 連線串

query options:
  -q, --query=                                              查詢過濾器,作為JSON字串,比如 '{x:{$gt:1}}'
      --queryFile=                                          包含查詢過濾器檔案的路徑(JSON)
      --readPreference=<string>|<json>                      指定首選項名稱或首選項json物件
      --forceTableScan                                      強制進行表掃描

output options:
  -o, --out=<directory-path>                                輸出目錄,或' - '表示stdout(預設為'dump')
      --gzip                                                使用Gzip壓縮歸檔我們的集合輸出
      --repair                                              嘗試從損壞的資料檔案中恢復文件(並非所有儲存引擎都支援)
      --oplog                                               使用oplog獲取時間點(point-in-time)快照
      --archive=<file-path>                                 轉儲為指定路徑的存檔。 如果指定了flag而沒有值,則將歸檔儲存到stdout
      --dumpDbUsersAndRoles                                 備份資料庫中的使用者名稱和資料庫角色
      --excludeCollection=<collection-name>                 從轉儲中排除的集合(可以多次指定以排除其他集合)
      --excludeCollectionsWithPrefix=<collection-prefix>    轉儲中排除具有給定字首的所有集合(可以多次指定以排除其他字首)
  -j, --numParallelCollections=                             並行備份的執行緒數預設是4 (default: 4)
      --viewsAsCollections                                  將檢視轉儲為普通集合,省略標準集合
	  

# ./mongorestore --help
Usage:
  mongorestore <options> <directory or file to restore>

Restore backups generated with mongodump to a running server.

Specify a database with -d to restore a single database from the target directory,
or use -d and -c to restore a single collection from a single .bson file.

See http://docs.mongodb.org/manual/reference/program/mongorestore/ for more information.

general options:
      --help                                                print usage
      --version                                             print the tool version and exit

verbosity options:
  -v, --verbose=<level>                                     more detailed log output (include multiple times for more verbosity, e.g. -vvvvv, or specify a numeric value,
                                                            e.g. --verbose=N)
      --quiet                                               hide all log output

connection options:
  -h, --host=<hostname>                                     mongodb host to connect to (setname/host1,host2 for replica sets)
      --port=<port>                                         server port (can also use --host hostname:port)

ssl options:
      --ssl                                                 connect to a mongod or mongos that has ssl enabled
      --sslCAFile=<filename>                                the .pem file containing the root certificate chain from the certificate authority
      --sslPEMKeyFile=<filename>                            the .pem file containing the certificate and key
      --sslPEMKeyPassword=<password>                        the password to decrypt the sslPEMKeyFile, if necessary
      --sslCRLFile=<filename>                               the .pem file containing the certificate revocation list
      --sslAllowInvalidCertificates                         bypass the validation for server certificates
      --sslAllowInvalidHostnames                            bypass the validation for server name
      --sslFIPSMode                                         use FIPS mode of the installed openssl library

authentication options:
  -u, --username=<username>                                 username for authentication
  -p, --password=<password>                                 password for authentication
      --authenticationDatabase=<database-name>              database that holds the user's credentials
      --authenticationMechanism=<mechanism>                 authentication mechanism to use

uri options:
      --uri=mongodb-uri                                     mongodb uri connection string

namespace options:
  -d, --db=<database-name>                                  從BSON檔案恢復時指定的資料庫
  -c, --collection=<collection-name>                        從BSON檔案恢復的集合
      --excludeCollection=<collection-name>                 過時的引數.在恢復期間跳過的集合(可以多次指定以排除其他集合).
      --excludeCollectionsWithPrefix=<collection-prefix>    過時的引數.在恢復期間跳過具有給定字首的集合(可以多次指定以排除其他字首).
      --nsExclude=<namespace-pattern>                       排除匹配的名稱空間
      --nsInclude=<namespace-pattern>                       包括匹配的名稱空間
      --nsFrom=<namespace-pattern>                          重新命名匹配的名稱空間,必須具有匹配的nsTo
      --nsTo=<namespace-pattern>                            重新命名匹配的名稱空間,必須具有匹配的nsFrom

input options:
      --objcheck                                            插入前驗證所有物件
      --oplogReplay                                         重放oplog以進行時間點恢復
      --oplogLimit=<seconds>[:ordinal]                      僅在提供的時間戳之前包含oplog條目
      --oplogFile=<filename>                                用於重放oplog的oplog檔案
      --archive=<filename>                                  從指定的歸檔檔案恢復轉儲;若指定了flag而沒有值,則從stdin讀取歸檔檔案
      --restoreDbUsersAndRoles                              恢復給定資料庫的使用者和角色定義
      --dir=<directory-name>                                輸入目錄,對stdin使用' - '
      --gzip                                                解壓縮gzip壓縮輸入

restore options:
      --drop                                                在匯入之前刪除每個集合
      --dryRun                                              檢視摘要而不匯入任何內容 建議詳細說明
      --writeConcern=<write-concern>                        寫關注選項比如 --writeConcern majority, --writeConcern '{w: 3, wtimeout: 500, fsync: true, j: true}'
      --noIndexRestore                                      不要恢復索引
      --noOptionsRestore                                    不恢復收集選項
      --keepIndexVersion                                    不要更新索引版本
      --maintainInsertionOrder                              在恢復期間保留檔案的順序
  -j, --numParallelCollections=                             要並行恢復的集合數預設為4
      --numInsertionWorkersPerCollection=                   每個集合併發執行的插入運算元(預設為1)
      --stopOnError                                         如果在插入時遇到錯誤則停止恢復(預設情況下關閉)
      --bypassDocumentValidation                            繞過文件驗證
      --preserveUUID                                        保留原始集合UUID(預設情況下關閉,需要刪除)
	  
# ./mongoimport --help
Usage:
  mongoimport <options> <file>

Import CSV, TSV or JSON data into MongoDB. If no file is provided, mongoimport reads from stdin.

See http://docs.mongodb.org/manual/reference/program/mongoimport/ for more information.

general options:
      --help                                      print usage
      --version                                   print the tool version and exit

verbosity options:
  -v, --verbose=<level>                           more detailed log output (include multiple times for more verbosity, e.g. -vvvvv, or specify a numeric value, e.g.
                                                  --verbose=N)
      --quiet                                     hide all log output

connection options:
  -h, --host=<hostname>                           mongodb host to connect to (setname/host1,host2 for replica sets)
      --port=<port>                               server port (can also use --host hostname:port)

ssl options:
      --ssl                                       connect to a mongod or mongos that has ssl enabled
      --sslCAFile=<filename>                      the .pem file containing the root certificate chain from the certificate authority
      --sslPEMKeyFile=<filename>                  the .pem file containing the certificate and key
      --sslPEMKeyPassword=<password>              the password to decrypt the sslPEMKeyFile, if necessary
      --sslCRLFile=<filename>                     the .pem file containing the certificate revocation list
      --sslAllowInvalidCertificates               bypass the validation for server certificates
      --sslAllowInvalidHostnames                  bypass the validation for server name
      --sslFIPSMode                               use FIPS mode of the installed openssl library

authentication options:
  -u, --username=<username>                       username for authentication
  -p, --password=<password>                       password for authentication
      --authenticationDatabase=<database-name>    database that holds the user's credentials
      --authenticationMechanism=<mechanism>       authentication mechanism to use

namespace options:
  -d, --db=<database-name>                        database to use
  -c, --collection=<collection-name>              collection to use

uri options:
      --uri=mongodb-uri                           mongodb uri connection string

input options:
  -f, --fields=<field>[,<field>]*                 逗號分隔的欄位列表, e.g. -f name,age
      --fieldFile=<filename>                      帶有欄位名稱的檔案 - 每行1個
      --file=<filename>                           要匯入的檔案; 如果未指定,則使用stdin
      --headerline                                使用輸入源中的第一行作為欄位列表(僅限CSV和TSV)
      --jsonArray                                 將輸入源視為JSON陣列
      --parseGrace=<grace>                        當型別強制失敗時控制行為,可選項有: autoCast, skipField, skipRow, stop (defaults to 'stop') 
      --type=<type>                               要匯入的輸入格式:json, csv, or tsv (defaults to 'json') 
      --columnsHaveTypes                          表明欄位列表(來自--fields,--fieldsFile或--headerline)指定型別; 它們必須採用'<colName>.<type>(<arg>)'的形式. 型別可以是以下之一:auto,binary,bool,date,date_go,date_ms,date_oracle,double,int32,int64,string。
                                                   對於每種日期型別,引數是日期時間佈局字串;對於二進位制型別,引數可以是以下之一:base32,base64,hex. 所有其他型別都採用空引數;僅對CSV和TSV匯入有效,例如zipcode.string(), thumbnail.binary(base64)
                                                  

ingest options:
      --drop                                      在插入文件之前刪除集合
      --ignoreBlanks                              忽略CSV和TSV中具有空值的欄位
      --maintainInsertionOrder                    按照輸出出現的順序插入文件
  -j, --numInsertionWorkers=<number>              併發執行的插入運算元,預設為1
      --stopOnError                               在第一次insert/ upsert錯誤時停止匯入
      --mode=[insert|upsert|merge]                insert:僅插入;upsert:插入或替換現有文件;merge:插入或修改現有文件。 預設為insert
      --upsertFields=<field>[,<field>]*           當--mode設定為upsert或merge時,查詢部分的逗號分隔欄位
      --writeConcern=<write-concern-specifier>    寫關注選項e.g. --writeConcern majority, --writeConcern '{w: 3, wtimeout: 500, fsync: true, j: true}'
      --bypassDocumentValidation                  繞過文件驗證

# ./mongoexport --help
Usage:
  mongoexport <options>

Export data from MongoDB in CSV or JSON format.

See http://docs.mongodb.org/manual/reference/program/mongoexport/ for more information.

general options:
      --help                                      print usage
      --version                                   print the tool version and exit

verbosity options:
  -v, --verbose=<level>                           more detailed log output (include multiple times for more verbosity, e.g. -vvvvv, or specify a numeric value, e.g.
                                                  --verbose=N)
      --quiet                                     hide all log output

connection options:
  -h, --host=<hostname>                           mongodb host to connect to (setname/host1,host2 for replica sets)
      --port=<port>                               server port (can also use --host hostname:port)

ssl options:
      --ssl                                       connect to a mongod or mongos that has ssl enabled
      --sslCAFile=<filename>                      the .pem file containing the root certificate chain from the certificate authority
      --sslPEMKeyFile=<filename>                  the .pem file containing the certificate and key
      --sslPEMKeyPassword=<password>              the password to decrypt the sslPEMKeyFile, if necessary
      --sslCRLFile=<filename>                     the .pem file containing the certificate revocation list
      --sslAllowInvalidCertificates               bypass the validation for server certificates
      --sslAllowInvalidHostnames                  bypass the validation for server name
      --sslFIPSMode                               use FIPS mode of the installed openssl library

authentication options:
  -u, --username=<username>                       username for authentication
  -p, --password=<password>                       password for authentication
      --authenticationDatabase=<database-name>    database that holds the user's credentials
      --authenticationMechanism=<mechanism>       authentication mechanism to use

namespace options:
  -d, --db=<database-name>                        database to use
  -c, --collection=<collection-name>              collection to use

uri options:
      --uri=mongodb-uri                           mongodb uri connection string

output options:
  -f, --fields=<field>[,<field>]*                 逗號分隔的欄位名稱列表(匯出CSV時需要) e.g. -f "name,age"
      --fieldFile=<filename>                      帶有欄位名稱的檔案 - 每行1個
      --type=<type>                               輸出格式,json或csv(預設為'json')
  -o, --out=<filename>                            輸出檔案; 如果未指定,則使用stdout
      --jsonArray                                 輸出到JSON陣列而不是每行一個物件
      --pretty                                    輸出為易於閱讀的JSON格式
      --noHeaderLine                              匯出第一行沒有欄位名稱列表的CSV資料

querying options:
  -q, --query=<json>                              查詢過濾器,作為JSON字串,例如'{x:{$ gt:1}}'
      --queryFile=<filename>                      包含查詢過濾器(JSON)的檔案的路徑
  -k, --slaveOk                                   允許第二次讀取
      --readPreference=<string>|<json>            指定首選項名稱或首選項json物件
      --forceTableScan                            強制表掃描(不使用$snapshot)
      --skip=<count>                              要跳過的檔案數量
      --limit=<count>                             限制要匯出的文件數
      --sort=<json>                               作為json字串用於排序,比如'{x:1}'
      --assertExists                              預設false,若指定若集合不存在將匯出失敗.
# ./bsondump --help
Usage:
  bsondump <options> <file>

View and debug .bson files.

See http://docs.mongodb.org/manual/reference/program/bsondump/ for more information.

general options:
      --help               print usage
      --version            print the tool version and exit

verbosity options:
  -v, --verbose=<level>    more detailed log output (include multiple times for more verbosity, e.g. -vvvvv, or specify a numeric value, e.g. --verbose=N)
      --quiet              hide all log output

output options:
      --type=<type>        輸出型別:debug, json(預設值)
      --objcheck           在處理的過程中驗證BSON.
      --pretty             美化輸出JSON,便於閱讀.
      --bsonFile=          轉儲到JSON的BSON檔案的路徑;預設值為stdin
      --outFile=           檔案的路徑轉儲到BSON;預設值為stdout