<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ### Mongodb的導出mongodump和mongorestore導入工具結合使用。可以用于數據庫的備份和還原。 mongodump是用于創建數據庫內容的二進制導出的實用程序。 mongodump可以從mongod或mongos實例中導出數據;即可以從獨立,副本集和分片群集部署中導出數據。 為了避免影響線上的業務,我們才使用mongodup工具時,盡可能在副本集的從節點或者延遲節點執行操作。 >mongodump和mongorestore不能成為正在進行分片事務的4.2分片群集的備份策略的一部分,因為用mongodump創建的備份不能保持跨分片事務的原子性保證。 ``` 官網也強調: 對于具有正在進行的分片事務的4.2分片群集,請使用以下協調的備份和還原過程之一,該過程確實維護了跨分片事務的原子性保證: MongoDB Atlas, MongoDB Cloud Manager, or MongoDB Ops Manager. ``` ### 1、可以使用mongodump --help 查看幫助文檔使用方法。 只要我們安裝了mongodb服務,就能夠使用mongodump命令, #### 1.1、備份整個實例: >mongodump -h IP:Port -o 導出到目錄 ``` [root@VM_6_17_centos ~]# /root/mongodb-4.2.1/bin/mongodump -h 192.168.6.17:27020 -o dump/ 2020-05-27T10:49:21.610+0800 writing admin.system.version to 2020-05-27T10:49:21.610+0800 done dumping admin.system.version (1 document) 2020-05-27T10:49:21.611+0800 writing test_haijiao.user_file to 2020-05-27T10:49:21.611+0800 writing test_jia.user_info to 2020-05-27T10:49:21.611+0800 done dumping test_jia.user_info (2 documents) 2020-05-27T10:49:21.611+0800 done dumping test_haijiao.user_file (1 document) ``` #### 1.2、備份單個數據庫: >mongodump -h IP:Port -d 數據庫名 -o 導出到目錄 ``` [root@VM_6_17_centos conf]# /root/mongodb-4.2.1/bin/mongodump -h 192.168.6.17:27020 -d test_jia -o dump/ 2020-05-27T10:53:11.404+0800 writing test_jia.user_info to 2020-05-27T10:53:11.405+0800 done dumping test_jia.user_info (2 documents) ``` #### 1.3、備份數據庫的一張表: >mongodump -h IP:Port -d 數據庫名 -c 集合名 -o 導出到目錄 ``` [root@VM_6_17_centos conf]# /root/mongodb-4.2.1/bin/mongodump -h 192.168.6.17:27020 -d test_jia -c user_info -o dump/ 2020-05-27T10:53:49.162+0800 writing test_jia.user_info to 2020-05-27T10:53:49.162+0800 done dumping test_jia.user_info (2 documents) ``` #### 1.4、備份數據庫的一張表并且過濾: 查看表里的數據我們過濾年齡大于30歲的數據 > db.user_info.find() { "_id" : ObjectId("5ecdcd0bc6a43453c65e484f"), "name" : "jiahaijiao", "age" : 32 } { "_id" : ObjectId("5ecdcde7c6a43453c65e4850"), "name" : "jiahaijiao", "age" : 32 } { "_id" : ObjectId("5ecdd6f5bf235c4a69f3b672"), "name" : "zhang", "age" : 30 } { "_id" : ObjectId("5ecdd6febf235c4a69f3b673"), "name" : "wang", "age" : 30 } { "_id" : ObjectId("5ecdd780bf235c4a69f3b674"), "name" : "li", "age" : 28 } ``` [root@VM_6_17_centos conf]# /root/mongodb-4.2.1/bin/mongodump -h 192.168.6.17:27020 -d test_jia -c user_info -q '{"age":{"$gt": 30}}' -o dump/ 2020-05-27T11:18:19.103+0800 writing test_jia.user_info to 2020-05-27T11:18:19.103+0800 done dumping test_jia.user_info (2 documents) ``` #### 1.5、導出單個庫的壓縮文件: ``` [root@VM_6_17_centos conf]# /root/mongodb-4.2.1/bin/mongodump -h 192.168.6.17:27020 -d test_jia -o dump/ --gzip 2020-05-27T11:19:33.748+0800 writing test_jia.user_info to 2020-05-27T11:19:33.749+0800 done dumping test_jia.user_info (5 documents) [root@VM_6_17_centos conf]# ll dump/ 總用量 4 drwxr-xr-x 2 root root 4096 5月 27 11:19 test_jia [root@VM_6_17_centos conf]# ll dump/test_jia/ 總用量 16 -rw-r--r-- 1 root root 112 5月 27 11:18 user_info.bson -rw-r--r-- 1 root root 152 5月 27 11:19 user_info.bson.gz -rw-r--r-- 1 root root 166 5月 27 11:18 user_info.metadata.json -rw-r--r-- 1 root root 151 5月 27 11:19 user_info.metadata.json.gz ``` #### 1. 6、設置導出集合并發數,加快導出速度 > -j, --numParallelCollections= number of collections to dump in parallel (4 by default) (default: 4) //默導出文檔并發4個 ``` [root@VM_6_17_centos conf]# /root/mongodb-4.2.1/bin/mongodump -h 192.168.6.17:27020 -d test_jia -o dump/ --gzip -j 6 2020-05-27T11:23:34.568+0800 writing test_jia.user_info to 2020-05-27T11:23:34.569+0800 done dumping test_jia.user_info (5 documents) [root@VM_6_17_centos conf]# ``` #### 1.7、數據認證管理員備份 數據庫開啟認證授權以后需要使用用戶名和密碼,認證數據庫參數進行備份。 ``` [root@VM_6_17_centos ~]# /root/mongodb-4.2.1/bin/mongodump -h 192.168.6.17:27020 -u dba -p12387654 -d test_jia -o dump/ --authenticationDatabase=admin 2020-05-27T15:06:51.049+0800 writing test_jia.user_info to 2020-05-27T15:06:51.050+0800 done dumping test_jia.user_info (5 documents) [root@VM_6_17_centos ~]# ``` ### 2、mongorestore 將mongodump生成的備份還原到正在運行的實例 #### 2.1、還原整個實例 ``` [root@VM_6_17_centos ~]# /root/mongodb-4.2.1/bin/mongorestore -h 192.168.6.17:27030 dump/ 2020-05-27T15:25:52.968+0800 preparing collections to restore from 2020-05-27T15:25:52.970+0800 reading metadata for test_jia.user_info from dump/test_jia/user_info.metadata.json 2020-05-27T15:25:52.973+0800 reading metadata for test_haijiao.user_file from dump/test_haijiao/user_file.metadata.json 2020-05-27T15:25:52.996+0800 restoring test_jia.user_info from dump/test_jia/user_info.bson 2020-05-27T15:25:52.998+0800 no indexes to restore 2020-05-27T15:25:52.998+0800 finished restoring test_jia.user_info (5 documents, 0 failures) 2020-05-27T15:25:53.007+0800 restoring test_haijiao.user_file from dump/test_haijiao/user_file.bson 2020-05-27T15:25:53.011+0800 no indexes to restore 2020-05-27T15:25:53.011+0800 finished restoring test_haijiao.user_file (1 document, 0 failures) 2020-05-27T15:25:53.011+0800 restoring users from dump/admin/system.users.bson 2020-05-27T15:25:53.078+0800 6 document(s) restored successfully. 0 document(s) failed to restore. ``` [root@VM_6_17_centos ~]# #### 2.1、還原單個庫 ``` [root@VM_6_17_centos ~]# /root/mongodb-4.2.1/bin/mongorestore -h 192.168.6.17:27030 --db test_jia dump/test_jia/ 2020-05-27T15:35:06.633+0800 the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead 2020-05-27T15:35:06.634+0800 building a list of collections to restore from dump/test_jia dir 2020-05-27T15:35:06.634+0800 reading metadata for test_jia.user_info from dump/test_jia/user_info.metadata.json 2020-05-27T15:35:06.657+0800 restoring test_jia.user_info from dump/test_jia/user_info.bson 2020-05-27T15:35:06.658+0800 no indexes to restore 2020-05-27T15:35:06.658+0800 finished restoring test_jia.user_info (5 documents, 0 failures) 2020-05-27T15:35:06.658+0800 5 document(s) restored successfully. 0 document(s) failed to restore. ``` #### 2.2、還原庫的單個表 ``` [root@VM_6_17_centos ~]# /root/mongodb-4.2.1/bin/mongorestore -h 192.168.6.17:27030 --db test_jia -c user_info dump/test_jia/user_hobby.bson 2020-05-27T15:47:52.552+0800 checking for collection data in dump/test_jia/user_hobby.bson 2020-05-27T15:47:52.552+0800 restoring to existing collection test_jia.user_info without dropping 2020-05-27T15:47:52.552+0800 reading metadata for test_jia.user_info from dump/test_jia/user_hobby.metadata.json 2020-05-27T15:47:52.552+0800 restoring test_jia.user_info from dump/test_jia/user_hobby.bson 2020-05-27T15:47:52.613+0800 no indexes to restore 2020-05-27T15:47:52.613+0800 finished restoring test_jia.user_info (1 document, 0 failures) 2020-05-27T15:47:52.613+0800 1 document(s) restored successfully. 0 document(s) failed to restore. ``` #### 2.3、壓縮備份文件,還原 ``` [root@VM_6_17_centos ~]# /root/mongodb-4.2.1/bin/mongorestore -h 192.168.6.17:27030 --gzip --db test_jia dump/test_jia/ 2020-05-27T15:54:05.013+0800 the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead 2020-05-27T15:54:05.013+0800 building a list of collections to restore from dump/test_jia dir 2020-05-27T15:54:05.014+0800 reading metadata for test_jia.user_info from dump/test_jia/user_info.metadata.json.gz 2020-05-27T15:54:05.014+0800 reading metadata for test_jia.user_hobby from dump/test_jia/user_hobby.metadata.json.gz 2020-05-27T15:54:05.038+0800 restoring test_jia.user_info from dump/test_jia/user_info.bson.gz 2020-05-27T15:54:05.041+0800 no indexes to restore 2020-05-27T15:54:05.041+0800 finished restoring test_jia.user_info (5 documents, 0 failures) 2020-05-27T15:54:05.063+0800 restoring test_jia.user_hobby from dump/test_jia/user_hobby.bson.gz 2020-05-27T15:54:05.065+0800 no indexes to restore 2020-05-27T15:54:05.065+0800 finished restoring test_jia.user_hobby (1 document, 0 failures) 2020-05-27T15:54:05.065+0800 6 document(s) restored successfully. 0 document(s) failed to restore. ``` #### 2.4、還原時刪除已存在的集合 ``` [root@VM_6_17_centos ~]# /root/mongodb-4.2.1/bin/mongorestore -h 192.168.6.17:27030 --gzip --drop --db test_jia -c user_info dump/test_jia/user_info.bson.gz 2020-05-27T15:57:18.065+0800 checking for collection data in dump/test_jia/user_info.bson.gz 2020-05-27T15:57:18.070+0800 reading metadata for test_jia.user_info from dump/test_jia/user_info.metadata.json.gz 2020-05-27T15:57:18.085+0800 restoring test_jia.user_info from dump/test_jia/user_info.bson.gz 2020-05-27T15:57:18.146+0800 no indexes to restore 2020-05-27T15:57:18.146+0800 finished restoring test_jia.user_info (5 documents, 0 failures) 2020-05-27T15:57:18.146+0800 5 document(s) restored successfully. 0 document(s) failed to restore. ``` #### 2.5、還原設置并行集合數 默認并行集合數為4,我們可以設置該參數 ``` [root@VM_6_17_centos ~]# /root/mongodb-4.2.1/bin/mongorestore -h 192.168.6.17:27030 --gzip --drop dump/ -j 6 2020-05-27T16:15:17.370+0800 preparing collections to restore from 2020-05-27T16:15:17.375+0800 reading metadata for test_jia.user_info from dump/test_jia/user_info.metadata.json.gz 2020-05-27T16:15:17.379+0800 reading metadata for test_jia.user_hobby from dump/test_jia/user_hobby.metadata.json.gz 2020-05-27T16:15:17.404+0800 restoring test_jia.user_info from dump/test_jia/user_info.bson.gz 2020-05-27T16:15:17.407+0800 no indexes to restore 2020-05-27T16:15:17.407+0800 finished restoring test_jia.user_info (5 documents, 0 failures) 2020-05-27T16:15:17.412+0800 restoring test_jia.user_hobby from dump/test_jia/user_hobby.bson.gz 2020-05-27T16:15:17.413+0800 no indexes to restore 2020-05-27T16:15:17.413+0800 finished restoring test_jia.user_hobby (1 document, 0 failures) 2020-05-27T16:15:17.413+0800 6 document(s) restored successfully. 0 document(s) failed to restore. [root@VM_6_17_centos ~]# ``` #### 2.5、開啟認證管理員恢復 ``` [root@VM_6_17_centos ~]# /root/mongodb-4.2.1/bin/mongorestore -h 192.168.6.17:27030 --gzip --drop --dir dump/ -j 6 -u dba -p12387654 --authenticationDatabase=admin 2020-05-27T16:22:23.883+0800 preparing collections to restore from 2020-05-27T16:22:23.899+0800 reading metadata for test_jia.user_hobby from dump/test_jia/user_hobby.metadata.json.gz 2020-05-27T16:22:23.940+0800 restoring test_jia.user_hobby from dump/test_jia/user_hobby.bson.gz 2020-05-27T16:22:23.941+0800 reading metadata for test_jia.user_info from dump/test_jia/user_info.metadata.json.gz 2020-05-27T16:22:23.942+0800 no indexes to restore 2020-05-27T16:22:23.942+0800 finished restoring test_jia.user_hobby (1 document, 0 failures) 2020-05-27T16:22:23.964+0800 restoring test_jia.user_info from dump/test_jia/user_info.bson.gz 2020-05-27T16:22:23.965+0800 no indexes to restore 2020-05-27T16:22:23.966+0800 finished restoring test_jia.user_info (5 documents, 0 failures) 2020-05-27T16:22:23.966+0800 6 document(s) restored successfully. 0 document(s) failed to restore. ``` 在數據量較小的情況下可是使用mongodump進行備份,數據大的情況下可以使用復制集的延遲備份,云服務器的磁盤快照進行備份。 關于增量oplog備份請點擊以下鏈接。 [`Mongodb恢復到任意時間點`](https://blog.51cto.com/jiachen/2486045)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看