欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

mongodb之備份和恢復(fù)介紹-創(chuàng)新互聯(lián)

一、安裝環(huán)境介紹:

演示的mongo的安裝環(huán)境:
二進(jìn)制安裝包mongoDB3.6.16
給mongodb授權(quán)超級(jí)管理員賬戶

站在用戶的角度思考問題,與客戶深入溝通,找到西平網(wǎng)站設(shè)計(jì)與西平網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:做網(wǎng)站、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、主機(jī)域名、虛擬主機(jī)、企業(yè)郵箱。業(yè)務(wù)覆蓋西平地區(qū)。
mongo --host 127.0.0.1 --port 6068
db.createUser({user: 'root', pwd:'TdLLQ6689', roles:[{role: 'root', db: 'admin'}]});
use admin
db.auth("root","TdLLQ6689")

建庫(kù)建表模擬數(shù)據(jù)

use dbtest001
db.chenji.insert({"name":"小花","年級(jí)":"二年級(jí)","性別":"男","愛好":"學(xué)習(xí)"})
use dbtest002
db.xiangmu.insert({"name":"小花","年級(jí)":"二年級(jí)","性別":"男","愛好":"學(xué)習(xí)"})
db.mumu.insert({"name":"小花","年級(jí)":"二年級(jí)","性別":"男","愛好":"學(xué)習(xí)"})

提示:此次演示備份和恢復(fù)主要采用超級(jí)賬戶root來進(jìn)行演示

二、mongodump備份命令介紹:

2.1語法和參數(shù)說明:

mongodump -h dbhost -u xxx -p xxx -d dbname -o dbdirectory
參數(shù)介紹:
-h 指明數(shù)據(jù)庫(kù)宿主機(jī)的IP
--port 指明數(shù)據(jù)庫(kù)的端口
-u 指明數(shù)據(jù)庫(kù)的用戶名
-p 指明數(shù)據(jù)庫(kù)的密碼
-d 指明數(shù)據(jù)庫(kù)的名字
-c 指明collection的名字
-o 指明到要導(dǎo)出的文件名
-q 指明導(dǎo)出數(shù)據(jù)的過濾條件
--authenticationDatabase 驗(yàn)證數(shù)據(jù)的名稱
--gzip 備份時(shí)壓縮
--oplog use oplog for taking a point-in-time snapshot

提前創(chuàng)建好演示的備份目錄:
mkdir full # 全量備份
mkdir single_db # 單庫(kù)備份
mkdir single_db_col # 庫(kù)中表備份
mkdir single_db.gzip # 庫(kù)備份壓縮
mkdir single_db_col.gzip # 庫(kù)中表備份壓縮

2.2全量備份:

[root@localhost ~]# mongodump -h 127.0.0.1:6068 -u root -p TdLLQ6689  -o /root/full
2020-01-04T18:13:18.271+0800    writing admin.system.users to 
2020-01-04T18:13:18.272+0800    done dumping admin.system.users (7 documents)
2020-01-04T18:13:18.272+0800    writing admin.system.version to 
2020-01-04T18:13:18.273+0800    done dumping admin.system.version (2 documents)
2020-01-04T18:13:18.273+0800    writing dbtest001.chenji to 
2020-01-04T18:13:18.273+0800    writing dbtest002.mumu to 
2020-01-04T18:13:18.273+0800    writing dbtest002.xiangmu to 
2020-01-04T18:13:18.274+0800    done dumping dbtest002.mumu (1 document)
2020-01-04T18:13:18.274+0800    done dumping dbtest001.chenji (2 documents)
2020-01-04T18:13:18.290+0800    done dumping dbtest002.xiangmu (2 documents)
[root@localhost ~]# cd full/
[root@localhost full]# ls
admin  dbtest001  dbtest002

2.3單庫(kù)備份:

采用超級(jí)賬戶root備份備份失?。?/strong>

[root@localhost ~]# mongodump -h 127.0.0.1:6068 -u root -p TdLLQ6689 -d dbtest001 -o /root/single_db
2020-01-04T18:22:20.087+0800    Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.

解決辦法如下:

第一種方法:添加--authenticationDatabase admin

[root@localhost ~]# mongodump -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin  -d dbtest001 -o /root/single_db
2020-01-04T18:37:46.926+0800    writing dbtest001.chenji to 
2020-01-04T18:37:46.927+0800    done dumping dbtest001.chenji (2 documents)
[root@localhost ~]# mongodump -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin  -d dbtest002 -o /root/single_db
2020-01-04T18:37:54.253+0800    writing dbtest002.xiangmu to 
2020-01-04T18:37:54.253+0800    writing dbtest002.mumu to 
2020-01-04T18:37:54.254+0800    done dumping dbtest002.xiangmu (2 documents)
2020-01-04T18:37:54.254+0800    done dumping dbtest002.mumu (1 document)

[root@localhost ~]# tree /root/single_db
/root/single_db
├── dbtest001
│?? ├── chenji.bson
│?? └── chenji.metadata.json
└── dbtest002
    ├── mumu.bson
    ├── mumu.metadata.json
    ├── xiangmu.bson
    └── xiangmu.metadata.json

2 directories, 6 files

第二種方法:針對(duì)單獨(dú)的庫(kù)授權(quán)讀寫權(quán)限進(jìn)行備份

[root@localhost ~]# mongo --host 127.0.0.1 --port 6068
MongoDB shell version v3.6.16
connecting to: mongodb://127.0.0.1:6068/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("93f83e64-71ca-4b1d-b599-508b7fba8722") }
MongoDB server version: 3.6.16
> use dbtest001
>db.auth("root","TdLLQ6689")

> use dbtest001
>db.createUser({user: 'backupuser', pwd:'TdLLQ6689', roles:[{role: 'readWrite', db: 'dbtest001'}]});
> use dbtest002
>db.createUser({user: 'backupuser', pwd:'TdLLQ6689', roles:[{role: 'readWrite', db: 'dbtest002'}]});
[root@localhost ~]# mongodump -h 127.0.0.1:6068 -u backupuser -p TdLLQ6689  -d dbtest001 -o /root/single_db
2020-01-04T18:24:15.243+0800    writing dbtest001.chenji to 
2020-01-04T18:24:15.244+0800    done dumping dbtest001.chenji (2 documents)
[root@localhost ~]# ll /root/single_db/dbtest001/chenji.*
-rw-r--r-- 1 root root 192 1月   4 18:24 /root/single_db/dbtest001/chenji.bson
-rw-r--r-- 1 root root 130 1月   4 18:24 /root/single_db/dbtest001/chenji.metadata.json
[root@localhost ~]# mongodump -h 127.0.0.1:6068 -u backupuser -p TdLLQ6689  -d dbtest002 -o /root/single_db
2020-01-04T18:28:39.523+0800    writing dbtest002.xiangmu to 
2020-01-04T18:28:39.523+0800    writing dbtest002.mumu to 
2020-01-04T18:28:39.524+0800    done dumping dbtest002.xiangmu (2 documents)
2020-01-04T18:28:39.524+0800    done dumping dbtest002.mumu (1 document)
[root@localhost ~]# cd  /root/single_db
[root@localhost single_db]# ls
dbtest001  dbtest002

2.4備份單庫(kù)中指定的單表:

[root@localhost ~]# mongodump -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin  -d dbtest002 -c xiangmu -o /root/single_db_col
2020-01-04T18:34:30.260+0800    writing dbtest002.xiangmu to 
2020-01-04T18:34:30.261+0800    done dumping dbtest002.xiangmu (2 documents)
[root@localhost ~]# ll /root/single_db_col/dbtest002/
總用量 8
-rw-r--r-- 1 root root 192 1月   4 18:34 xiangmu.bson
-rw-r--r-- 1 root root 131 1月   4 18:34 xiangmu.metadata.json

2.5庫(kù)表備份壓縮:

2.5.1庫(kù)備份壓縮:

 [root@localhost ~]# mongodump -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin  -d dbtest002 -o /root/single_db --gzip
2020-01-04T18:44:28.558+0800    writing dbtest002.xiangmu to 
2020-01-04T18:44:28.559+0800    writing dbtest002.mumu to 
2020-01-04T18:44:28.560+0800    done dumping dbtest002.xiangmu (2 documents)
2020-01-04T18:44:28.561+0800    done dumping dbtest002.mumu (1 document)
[root@localhost ~]# tree single_db
single_db
└── dbtest002
    ├── mumu.bson.gz
    ├── mumu.metadata.json.gz
    ├── xiangmu.bson.gz
    └── xiangmu.metadata.json.gz

1 directory, 4 files

2.5.2庫(kù)中表備份壓縮:

[root@localhost ~]# mongodump -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin  -d dbtest001 -o /root/single_db_col.gzip  --gzip
2020-01-04T18:41:08.459+0800    writing dbtest001.chenji to 
2020-01-04T18:41:08.460+0800    done dumping dbtest001.chenji (2 documents)
[root@localhost dbtest001]# ll /root/single_db_col.gzip/dbtest001
總用量 8
-rw-r--r-- 1 root root 124 1月   4 18:41 chenji.bson.gz
-rw-r--r-- 1 root root 132 1月   4 18:41 chenji.metadata.json.gz

三、mongorestore恢復(fù)備份數(shù)據(jù)命令介紹

3.1語法和參數(shù)介紹:

mongorestore -h <hostname><:port> -d dbname <path>

--host <:port>, -h <:port>:mongoDB所在服務(wù)器地址,默認(rèn)為: localhost:27017
-h 指明數(shù)據(jù)庫(kù)宿主機(jī)的IP
-u 指明數(shù)據(jù)庫(kù)的用戶名
-p 指明數(shù)據(jù)庫(kù)的密碼
-d 指明數(shù)據(jù)庫(kù)的名字 ## database to use when restoring from a BSON file
-c 指明collection的名字 ##collection to use when restoring from a BSON file
-o 指明到要導(dǎo)出的文件名
-q 指明導(dǎo)出數(shù)據(jù)的過濾條件
--authenticationDatabase 驗(yàn)證數(shù)據(jù)的名稱
--gzip 備份時(shí)壓縮
--oplog use oplog for taking a point-in-time snapshot
--drop 恢復(fù)的時(shí)候把之前的集合drop掉

3.2利用全備份恢復(fù)到庫(kù)里:

提示:利用全備份直接恢復(fù)到線上的庫(kù)中會(huì)提示key沖突,恢復(fù)時(shí)要采用參數(shù)--drop 把之前的集合drop掉


[root@localhost ~]# mongorestore -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin   ./full/
2020-01-04T18:55:43.409+0800    preparing collections to restore from
2020-01-04T18:55:43.414+0800    reading metadata for dbtest001.chenji from full/dbtest001/chenji.metadata.json
2020-01-04T18:55:43.414+0800    restoring dbtest001.chenji from full/dbtest001/chenji.bson
2020-01-04T18:55:43.415+0800    reading metadata for dbtest002.xiangmu from full/dbtest002/xiangmu.metadata.json
2020-01-04T18:55:43.415+0800    reading metadata for dbtest002.mumu from full/dbtest002/mumu.metadata.json
2020-01-04T18:55:43.415+0800    restoring dbtest002.xiangmu from full/dbtest002/xiangmu.bson
2020-01-04T18:55:43.416+0800    restoring dbtest002.mumu from full/dbtest002/mumu.bson
2020-01-04T18:55:43.418+0800    error: multiple errors in bulk operation:
  - E11000 duplicate key error collection: dbtest002.xiangmu index: _id_ dup key: { : ObjectId('5e0f16191083b09e85237cb2') }
  - E11000 duplicate key error collection: dbtest002.xiangmu index: _id_ dup key: { : ObjectId('5e0f161d1083b09e85237cb3') }

2020-01-04T18:55:43.418+0800    no indexes to restore
2020-01-04T18:55:43.418+0800    finished restoring dbtest002.xiangmu (2 documents)
2020-01-04T18:55:43.436+0800    error: multiple errors in bulk operation:
  - E11000 duplicate key error collection: dbtest001.chenji index: _id_ dup key: { : ObjectId('5e0f150150fe973d9e9051f4') }
  - E11000 duplicate key error collection: dbtest001.chenji index: _id_ dup key: { : ObjectId('5e0f150750fe973d9e9051f5') }

2020-01-04T18:55:43.436+0800    no indexes to restore
2020-01-04T18:55:43.436+0800    finished restoring dbtest001.chenji (2 documents)
2020-01-04T18:55:43.436+0800    error: E11000 duplicate key error collection: dbtest002.mumu index: _id_ dup key: { : ObjectId('5e0f162d1083b09e85237cb4') }
2020-01-04T18:55:43.436+0800    no indexes to restore
2020-01-04T18:55:43.436+0800    finished restoring dbtest002.mumu (1 document)
2020-01-04T18:55:43.436+0800    restoring users from full/admin/system.users.bson
2020-01-04T18:55:43.447+0800    done

刪除數(shù)據(jù)庫(kù)然后進(jìn)行恢復(fù):

> use dbtest001
switched to db dbtest001
> db.dropDatabase()
{ "dropped" : "dbtest001", "ok" : 1 }
> use dbtest002
switched to db dbtest002
> db.dropDatabase()
{ "dropped" : "dbtest002", "ok" : 1 }

[root@localhost ~]# mongorestore -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin  ./full/
2020-01-04T18:59:29.633+0800    preparing collections to restore from
2020-01-04T18:59:29.639+0800    reading metadata for dbtest001.chenji from full/dbtest001/chenji.metadata.json
2020-01-04T18:59:29.639+0800    reading metadata for dbtest002.mumu from full/dbtest002/mumu.metadata.json
2020-01-04T18:59:29.640+0800    reading metadata for dbtest002.xiangmu from full/dbtest002/xiangmu.metadata.json
2020-01-04T18:59:29.646+0800    restoring dbtest002.xiangmu from full/dbtest002/xiangmu.bson
2020-01-04T18:59:29.648+0800    no indexes to restore
2020-01-04T18:59:29.648+0800    finished restoring dbtest002.xiangmu (2 documents)
2020-01-04T18:59:29.664+0800    restoring dbtest001.chenji from full/dbtest001/chenji.bson
2020-01-04T18:59:29.677+0800    restoring dbtest002.mumu from full/dbtest002/mumu.bson
2020-01-04T18:59:29.690+0800    no indexes to restore
2020-01-04T18:59:29.690+0800    finished restoring dbtest001.chenji (2 documents)
2020-01-04T18:59:29.690+0800    no indexes to restore
2020-01-04T18:59:29.690+0800    finished restoring dbtest002.mumu (1 document)
2020-01-04T18:59:29.690+0800    restoring users from full/admin/system.users.bson
2020-01-04T18:59:29.701+0800    done

添加參數(shù)--drop進(jìn)行恢復(fù):

[root@localhost ~]# mongorestore -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin --drop ./full/
2020-01-04T19:03:04.854+0800    preparing collections to restore from
2020-01-04T19:03:04.859+0800    reading metadata for dbtest001.chenji from full/dbtest001/chenji.metadata.json
2020-01-04T19:03:04.864+0800    restoring dbtest001.chenji from full/dbtest001/chenji.bson
2020-01-04T19:03:04.866+0800    no indexes to restore
2020-01-04T19:03:04.866+0800    finished restoring dbtest001.chenji (2 documents)
2020-01-04T19:03:04.879+0800    reading metadata for dbtest002.xiangmu from full/dbtest002/xiangmu.metadata.json
2020-01-04T19:03:04.880+0800    reading metadata for dbtest002.mumu from full/dbtest002/mumu.metadata.json
2020-01-04T19:03:04.884+0800    restoring dbtest002.xiangmu from full/dbtest002/xiangmu.bson
2020-01-04T19:03:04.898+0800    restoring dbtest002.mumu from full/dbtest002/mumu.bson
2020-01-04T19:03:04.899+0800    no indexes to restore
2020-01-04T19:03:04.899+0800    finished restoring dbtest002.xiangmu (2 documents)
2020-01-04T19:03:04.915+0800    no indexes to restore
2020-01-04T19:03:04.915+0800    finished restoring dbtest002.mumu (1 document)
2020-01-04T19:03:04.915+0800    restoring users from full/admin/system.users.bson
2020-01-04T19:03:04.928+0800    done

3.3把備份的庫(kù)表文件恢復(fù)到指定庫(kù)表中:

-d 指明數(shù)據(jù)庫(kù)的名字 而且備份的數(shù)據(jù)庫(kù)的數(shù)據(jù)文件必須是BSON格式的文件

[root@localhost ~]# mongorestore -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin -d dbtest002 ./full/dbtest002/
2020-01-05T07:36:24.293+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-01-05T07:36:24.293+0800    building a list of collections to restore from full/dbtest002 dir
2020-01-05T07:36:24.294+0800    reading metadata for dbtest002.xiangmu from full/dbtest002/xiangmu.metadata.json
2020-01-05T07:36:24.295+0800    reading metadata for dbtest002.mumu from full/dbtest002/mumu.metadata.json
2020-01-05T07:36:24.299+0800    restoring dbtest002.mumu from full/dbtest002/mumu.bson
2020-01-05T07:36:24.303+0800    no indexes to restore
2020-01-05T07:36:24.303+0800    finished restoring dbtest002.mumu (1 document)
2020-01-05T07:36:24.319+0800    restoring dbtest002.xiangmu from full/dbtest002/xiangmu.bson
2020-01-05T07:36:24.321+0800    no indexes to restore
2020-01-05T07:36:24.321+0800    finished restoring dbtest002.xiangmu (2 documents)
2020-01-05T07:36:24.321+0800    done

-c 指明集合的名字 而且備份的數(shù)據(jù)庫(kù)的集合數(shù)據(jù)文件必須是BSON格式的文件

[root@localhost ~]# mongorestore -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin -d dbtest002 -c mumu  ./full/dbtest002/mumu.bson 
2020-01-05T07:45:53.367+0800    checking for collection data in full/dbtest002/mumu.bson
2020-01-05T07:45:53.368+0800    reading metadata for dbtest002.mumu from full/dbtest002/mumu.metadata.json
2020-01-05T07:45:53.373+0800    restoring dbtest002.mumu from full/dbtest002/mumu.bson
2020-01-05T07:45:53.436+0800    no indexes to restore
2020-01-05T07:45:53.436+0800    finished restoring dbtest002.mumu (1 document)
2020-01-05T07:45:53.436+0800    done
[root@localhost ~]# 
[root@localhost ~]# mongorestore -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin -d dbtest002 -c mumu  ./full/dbtest002/xiangmu.bson 
2020-01-05T07:46:35.517+0800    checking for collection data in full/dbtest002/xiangmu.bson
2020-01-05T07:46:35.519+0800    reading metadata for dbtest002.mumu from full/dbtest002/xiangmu.metadata.json
2020-01-05T07:46:35.519+0800    restoring dbtest002.mumu from full/dbtest002/xiangmu.bson
2020-01-05T07:46:35.582+0800    no indexes to restore
2020-01-05T07:46:35.582+0800    finished restoring dbtest002.mumu (2 documents)
2020-01-05T07:46:35.582+0800    done

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

新聞名稱:mongodb之備份和恢復(fù)介紹-創(chuàng)新互聯(lián)
鏈接分享:http://aaarwkj.com/article36/gjppg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、網(wǎng)站導(dǎo)航、服務(wù)器托管、做網(wǎng)站、動(dòng)態(tài)網(wǎng)站定制網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成人激情视频在线网页| 国内精品亚洲成av人片麻豆| 成人av在线免费播放| 亚洲精品在线观看av| 成熟女人毛茸茸的视频| 中文字幕日韩欧美一区| 亚洲男人天堂中文字幕| 色综合色综合色综合色| 成年人免费国产视频网站| 五月天亚洲综合小说网| 伊人亚洲一区二区三区| 亚洲香蕉视频免费在线观看| 欧美日韩免费高清视视频| 日韩欧美亚洲视频另类| 哪里可以看黄色片日韩| 亚州精品少妇久久久久久| 中文字幕一区侵犯人妻| 日韩不卡在线免费播放| 偷拍大神女厕偷拍作品| 九九re久久这里有精品| 亚洲天堂免费在线播放| 亚洲综合av一区二区三区四区| 黄色日韩欧美在线观看| 国产一区二区在线不卡播放| 亚洲性感美女男人的天堂| 日操夜操天天操夜夜操| 成年人网站一级黄色免费| 久久亚洲一区二区内射| 日韩不卡在线免费观看视频| 97视频在线观看网站| 老汉av免费在线观看| 涩五月婷婷开心中文字幕| 精品久久久久久蜜臀av| 国产b片免费在线观看| 亚洲一区二区三区在线播| 日本高清不卡在线一区二区| 色哟哟网站在线精品视频| 女同同性av观看免费| 在线免费观看日韩黄片| 久久亚洲中文字幕精品一区四区| 欧美老熟妇一区三区精品|