成人性生交大片免费看视频r_亚洲综合极品香蕉久久网_在线视频免费观看一区_亚洲精品亚洲人成人网在线播放_国产精品毛片av_久久久久国产精品www_亚洲国产一区二区三区在线播_日韩一区二区三区四区区区_亚洲精品国产无套在线观_国产免费www

主頁 > 知識庫 > 分布式文檔存儲數(shù)據(jù)庫之MongoDB備份與恢復(fù)的實踐詳解

分布式文檔存儲數(shù)據(jù)庫之MongoDB備份與恢復(fù)的實踐詳解

熱門標(biāo)簽:外呼線路資源屬于電信業(yè)務(wù)嗎 青白江400企業(yè)電話申請 河南電話外呼系統(tǒng)招商 小裙科技電銷機(jī)器人怎樣 呼和浩特外呼系統(tǒng)原理是什么 crm外呼系統(tǒng)聯(lián)系方式 長沙電銷外呼防封卡是什么 內(nèi)蒙古營銷智能外呼系統(tǒng)哪個好 智能外呼系統(tǒng)官網(wǎng)

  前文我們聊了下分布式文檔存儲數(shù)據(jù)庫之MongoDB訪問控制,回顧請參考https://www.jb51.net/article/199848.htm;今天我們來了解下mongodb的備份與恢復(fù)

  為什么要備份?

  備份的目的是對數(shù)據(jù)做冗余的一種方式,它能夠讓我們在某種情況下保證最少數(shù)據(jù)的丟失;之前我們對mongodb做副本集也是對數(shù)據(jù)做冗余,但是這種在副本集上做數(shù)據(jù)冗余僅僅是針對系統(tǒng)故障或服務(wù)異常等一些非人為的故障發(fā)生時,保證數(shù)據(jù)服務(wù)的可用性;它不能夠避免人為的誤操作;為了使得數(shù)據(jù)的安全,將數(shù)據(jù)損失降低到最小,我們必須對數(shù)據(jù)庫周期性的做備份;

  常用備份方法

  提示:上圖主要描述了mongodb數(shù)據(jù)庫上常用備份策略,我們可以邏輯備份,邏輯備份是將數(shù)據(jù)庫中的數(shù)據(jù)導(dǎo)出成語句,通常使用專用工具導(dǎo)出和導(dǎo)入來完成一次備份與恢復(fù);其次我們也可以物理備份,簡單講物理備份就是把數(shù)據(jù)庫文件打包,備份;恢復(fù)時直接將對應(yīng)的數(shù)據(jù)庫文件解壓恢復(fù)即可;另外一種快速物理備份的方式就是給數(shù)據(jù)拍快照,拍快照可以將數(shù)據(jù)保存為當(dāng)前拍快照時的狀態(tài);如果我們要進(jìn)行恢復(fù)直接恢復(fù)快照即可;

  mongodb邏輯備份和物理備份比較

  提示:從上圖描述可以看出總體上來看物理備份效率和恢復(fù)效率要高于邏輯;物理備份效率高于邏輯備份,其主要原因是邏輯備份是通過數(shù)據(jù)庫接口將數(shù)據(jù)讀取出來,然后保存為對應(yīng)格式的文件,而物理備份只需要將數(shù)據(jù)文件直接打包備份,不需要一條一條的讀取數(shù)據(jù),然后寫入到其他文件,這中間就省去了讀寫過程,所以物理備份效率高;恢復(fù)也是類似的過程,物理恢復(fù)也是省去了讀寫的過程;

  mongodb邏輯備份工具

  在mongodb中使用邏輯備份的工具有兩組,第一組是mongodump/mongorestore,使用mongodump/mongorestore這組工具來邏輯的備份數(shù)據(jù),它備份出來的數(shù)據(jù)是BSON格式,BSON是一種二進(jìn)制格式,通常無法使用文本編輯器直接打開查看其內(nèi)容,對人類的可讀性較差,但它的優(yōu)點是保存的文件體積要?。皇褂眠@組命令導(dǎo)出的數(shù)據(jù),在恢復(fù)是依賴mongodb版本,不同版本導(dǎo)出的BSON格式略有不同,所以恢復(fù)時,可能存在版本不同而導(dǎo)致恢復(fù)數(shù)據(jù)失敗的情況;另外一組是mongoexport/mongoimport,這組工具導(dǎo)出的數(shù)據(jù)是json格式的數(shù)據(jù),通常我們可以使用文本編輯器打開直接查看,對人類的可讀性較好,但體積相對BSON格式的數(shù)據(jù)要大,恢復(fù)時不依賴版本;所以跨版本備份要先查看下對應(yīng)版本的兼容性,如果兼容使用mongodump/mongorestore,不兼容的話建議使用mongoexport/mongoimport;這里需要注意一點,JSON格式雖然可讀性很好,也很通用,但是它只是保留了數(shù)據(jù)部分,而沒有保留索引,賬戶等基礎(chǔ)信息,在使用是應(yīng)該注意;

  使用mongodump備份數(shù)據(jù)

  插入數(shù)據(jù)

> use testdb
switched to db testdb
> for(i=1;i=1000;i++) db.test.insert({id:i,name:"test"+i,age:(i%120),classes:(i%25)})
WriteResult({ "nInserted" : 1 })
> show tables
test
> db.test.findOne()
{
 "_id" : ObjectId("5fb130da012870b3c8e3c4ad"),
 "id" : 1,
 "name" : "test1",
 "age" : 1,
 "classes" : 1
}
> db.test.count()
1000
>

  備份所有數(shù)據(jù)庫

[root@node11 ~]# mongodump -utom -p123456 -h 192.168.0.52:27017 --authenticationDatabase admin -o ./node12_mongodb_full_backup
2020-11-15T21:47:45.439+0800 writing admin.system.users to node12_mongodb_full_backup/admin/system.users.bson
2020-11-15T21:47:45.442+0800 done dumping admin.system.users (4 documents)
2020-11-15T21:47:45.443+0800 writing admin.system.version to node12_mongodb_full_backup/admin/system.version.bson
2020-11-15T21:47:45.447+0800 done dumping admin.system.version (2 documents)
2020-11-15T21:47:45.448+0800 writing testdb.test to node12_mongodb_full_backup/testdb/test.bson
2020-11-15T21:47:45.454+0800 done dumping testdb.test (1000 documents)
[root@node11 ~]# ls
node12_mongodb_full_backup
[root@node11 ~]# ll node12_mongodb_full_backup/
total 0
drwxr-xr-x 2 root root 128 Nov 15 21:47 admin
drwxr-xr-x 2 root root 49 Nov 15 21:47 testdb
[root@node11 ~]# tree node12_mongodb_full_backup/
node12_mongodb_full_backup/
├── admin
│ ├── system.users.bson
│ ├── system.users.metadata.json
│ ├── system.version.bson
│ └── system.version.metadata.json
└── testdb
 ├── test.bson
 └── test.metadata.json
 
2 directories, 6 files
[root@node11 ~]#

  提示:-u用于指定用戶,-p指定對應(yīng)用戶的密碼,-h指定數(shù)據(jù)庫地址,--authenticationDatabase 指定驗證用戶和密碼對應(yīng)的數(shù)據(jù)庫 -o指定要存放備份文件的目錄名稱;

  只備份單個testdb數(shù)據(jù)庫

[root@node11 ~]# mongodump -utom -p123456 -h 192.168.0.52:27017 --authenticationDatabase admin -d testdb -o ./node12_testdb
2020-11-15T21:53:36.523+0800 writing testdb.test to node12_testdb/testdb/test.bson
2020-11-15T21:53:36.526+0800 done dumping testdb.test (1000 documents)
[root@node11 ~]# tree ./node12_testdb
./node12_testdb
└── testdb
 ├── test.bson
 └── test.metadata.json
 
1 directory, 2 files
[root@node11 ~]#

  提示:-d用戶指定要備份的數(shù)據(jù)庫名稱;

  只備份testdb下的test集合

[root@node11 ~]# mongodump -utom -p123456 -h 192.168.0.52:27017 --authenticationDatabase admin -d testdb -c test -o ./node12_testdb_test-collection
2020-11-15T21:55:48.217+0800 writing testdb.test to node12_testdb_test-collection/testdb/test.bson
2020-11-15T21:55:48.219+0800 done dumping testdb.test (1000 documents)
[root@node11 ~]# tree ./node12_testdb_test-collection
./node12_testdb_test-collection
└── testdb
 ├── test.bson
 └── test.metadata.json
 
1 directory, 2 files
[root@node11 ~]#

  提示:-c用于指定要備份的集合(collection)名稱;

  壓縮備份testdb庫

[root@node11 ~]# mongodump -utom -p123456 -h 192.168.0.52:27017 --authenticationDatabase admin -d testdb --gzip -o ./node12_mongodb_testdb-gzip
2020-11-15T22:00:52.268+0800 writing testdb.test to node12_mongodb_testdb-gzip/testdb/test.bson.gz
2020-11-15T22:00:52.273+0800 done dumping testdb.test (1000 documents)
[root@node11 ~]# tree ./node12_mongodb_testdb-gzip
./node12_mongodb_testdb-gzip
└── testdb
 ├── test.bson.gz
 └── test.metadata.json.gz
 
1 directory, 2 files
[root@node11 ~]#

  提示:可以看到使用壓縮,只需要加上--gzip選項即可,備份出來的數(shù)據(jù)就是.gz后綴結(jié)尾的壓縮文件;

  壓縮備份testdb庫下的test集合

[root@node11 ~]# mongodump -utom -p123456 -h 192.168.0.52:27017 --authenticationDatabase admin -d testdb -c test --gzip -o ./node12_mongodb_testdb-test-gzip
2020-11-15T22:01:31.492+0800 writing testdb.test to node12_mongodb_testdb-test-gzip/testdb/test.bson.gz
2020-11-15T22:01:31.500+0800 done dumping testdb.test (1000 documents)
[root@node11 ~]# tree ./node12_mongodb_testdb-test-gzip
./node12_mongodb_testdb-test-gzip
└── testdb
 ├── test.bson.gz
 └── test.metadata.json.gz
 
1 directory, 2 files
[root@node11 ~]#

  使用mongorestore恢復(fù)數(shù)據(jù)

  在node12上刪除testdb

> db
testdb
> db.dropDatabase()
{ "dropped" : "testdb", "ok" : 1 }
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
>

  全量恢復(fù)所有數(shù)據(jù)庫

[root@node11 ~]# mongorestore -utom -p123456 -h 192.168.0.52:27017 --authenticationDatabase admin --drop ./node12_mongodb_full_backup
2020-11-15T22:07:35.465+0800 preparing collections to restore from
2020-11-15T22:07:35.467+0800 reading metadata for testdb.test from node12_mongodb_full_backup/testdb/test.metadata.json
2020-11-15T22:07:35.475+0800 restoring testdb.test from node12_mongodb_full_backup/testdb/test.bson
2020-11-15T22:07:35.486+0800 no indexes to restore
2020-11-15T22:07:35.486+0800 finished restoring testdb.test (1000 documents, 0 failures)
2020-11-15T22:07:35.486+0800 restoring users from node12_mongodb_full_backup/admin/system.users.bson
2020-11-15T22:07:35.528+0800 1000 document(s) restored successfully. 0 document(s) failed to restore.
[root@node11 ~]#

 提示:--drop用于指定,恢復(fù)是如果對應(yīng)數(shù)據(jù)庫或者colleciton存在,則先刪除然后在恢復(fù),這樣做的目的是保證恢復(fù)的數(shù)據(jù)和備份的數(shù)據(jù)一致;

  驗證:登錄192.168.0.52:27017查看對應(yīng)testdb數(shù)據(jù)庫是否恢復(fù)?

[root@node11 ~]# mongo -utom -p123456 192.168.0.52:27017/admin
MongoDB shell version v4.4.1
connecting to: mongodb://192.168.0.52:27017/admin?compressors=disabledgssapiServiceName=mongodb
Implicit session: session { "id" : UUID("af96cb64-a2a4-4d59-b60a-86ccbbe77e3e") }
MongoDB server version: 4.4.1
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
 https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
 https://community.mongodb.com
---
The server generated these startup warnings when booting:
 2020-11-15T20:42:23.774+08:00: ***** SERVER RESTARTED *****
 2020-11-15T20:42:29.198+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
 2020-11-15T20:42:29.198+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
---
---
 Enable MongoDB's free cloud-based monitoring service, which will then receive and display
 metrics about your deployment (disk utilization, CPU, operation statistics, etc).
 
 The monitoring data will be available on a MongoDB website with a unique URL accessible to you
 and anyone you share the URL with. MongoDB may use this information to make product
 improvements and to suggest MongoDB products and deployment options to you.
 
 To enable free monitoring, run the following command: db.enableFreeMonitoring()
 To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
testdb 0.000GB
> use testdb
switched to db testdb
> show collections
test
> db.test.count()
1000
> db.test.findOne()
{
 "_id" : ObjectId("5fb130da012870b3c8e3c4ad"),
 "id" : 1,
 "name" : "test1",
 "age" : 1,
 "classes" : 1
}
>

  恢復(fù)單個庫

  刪除testdb庫

> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
testdb 0.000GB
> use testdb
switched to db testdb
> db.dropDatabase()
{ "dropped" : "testdb", "ok" : 1 }
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
>

 使用mongorestore恢復(fù)testdb庫

[root@node11 ~]# mongorestore -utom -p123456 -h 192.168.0.52:27017 --authenticationDatabase admin -d testdb --drop ./node12_testdb/testdb/
2020-11-15T22:29:03.718+0800 The --db and --collection flags are deprecated for this use-case; please use --nsInclude instead, i.e. with --nsInclude=${DATABASE}.${COLLECTION}
2020-11-15T22:29:03.718+0800 building a list of collections to restore from node12_testdb/testdb dir
2020-11-15T22:29:03.719+0800 reading metadata for testdb.test from node12_testdb/testdb/test.metadata.json
2020-11-15T22:29:03.736+0800 restoring testdb.test from node12_testdb/testdb/test.bson
2020-11-15T22:29:03.755+0800 no indexes to restore
2020-11-15T22:29:03.755+0800 finished restoring testdb.test (1000 documents, 0 failures)
2020-11-15T22:29:03.755+0800 1000 document(s) restored successfully. 0 document(s) failed to restore.
[root@node11 ~]# mongo -utom -p123456 192.168.0.52:27017/admin
MongoDB shell version v4.4.1
connecting to: mongodb://192.168.0.52:27017/admin?compressors=disabledgssapiServiceName=mongodb
Implicit session: session { "id" : UUID("f5e73939-bb87-4d45-bf80-9ff1e7f6f15d") }
MongoDB server version: 4.4.1
---
The server generated these startup warnings when booting:
 2020-11-15T20:42:23.774+08:00: ***** SERVER RESTARTED *****
 2020-11-15T20:42:29.198+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
 2020-11-15T20:42:29.198+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
---
---
 Enable MongoDB's free cloud-based monitoring service, which will then receive and display
 metrics about your deployment (disk utilization, CPU, operation statistics, etc).
 
 The monitoring data will be available on a MongoDB website with a unique URL accessible to you
 and anyone you share the URL with. MongoDB may use this information to make product
 improvements and to suggest MongoDB products and deployment options to you.
 
 To enable free monitoring, run the following command: db.enableFreeMonitoring()
 To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
testdb 0.000GB
> use testdb
switched to db testdb
> show tables
test
> db.test.count()
1000
> db.test.findOne()
{
 "_id" : ObjectId("5fb130da012870b3c8e3c4ad"),
 "id" : 1,
 "name" : "test1",
 "age" : 1,
 "classes" : 1
}
>

  恢復(fù)單個集合

  刪除testdb下的test集合

> db
testdb
> show collections
test
> db.test.drop()
true
> show collections
>

  使用mongorestore恢復(fù)testdb下的test集合

[root@node11 ~]# mongorestore -utom -p123456 -h 192.168.0.52:27017 --authenticationDatabase admin -d testdb -c test --drop ./node12_testdb_test-collection/testdb/test.bson
2020-11-15T22:36:15.615+0800 checking for collection data in node12_testdb_test-collection/testdb/test.bson
2020-11-15T22:36:15.616+0800 reading metadata for testdb.test from node12_testdb_test-collection/testdb/test.metadata.json
2020-11-15T22:36:15.625+0800 restoring testdb.test from node12_testdb_test-collection/testdb/test.bson
2020-11-15T22:36:15.669+0800 no indexes to restore
2020-11-15T22:36:15.669+0800 finished restoring testdb.test (1000 documents, 0 failures)
2020-11-15T22:36:15.669+0800 1000 document(s) restored successfully. 0 document(s) failed to restore.
[root@node11 ~]# mongo -utom -p123456 192.168.0.52:27017/admin      MongoDB shell version v4.4.1
connecting to: mongodb://192.168.0.52:27017/admin?compressors=disabledgssapiServiceName=mongodb
Implicit session: session { "id" : UUID("27d15d9e-3fdf-4efc-b871-1ec6716e51e3") }
MongoDB server version: 4.4.1
---
The server generated these startup warnings when booting:
 2020-11-15T20:42:23.774+08:00: ***** SERVER RESTARTED *****
 2020-11-15T20:42:29.198+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
 2020-11-15T20:42:29.198+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
---
---
 Enable MongoDB's free cloud-based monitoring service, which will then receive and display
 metrics about your deployment (disk utilization, CPU, operation statistics, etc).
 
 The monitoring data will be available on a MongoDB website with a unique URL accessible to you
 and anyone you share the URL with. MongoDB may use this information to make product
 improvements and to suggest MongoDB products and deployment options to you.
 
 To enable free monitoring, run the following command: db.enableFreeMonitoring()
 To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
testdb 0.000GB
> use testdb
switched to db testdb
> show collections
test
> db.test.count()
1000
> db.test.findOne()
{
 "_id" : ObjectId("5fb130da012870b3c8e3c4ad"),
 "id" : 1,
 "name" : "test1",
 "age" : 1,
 "classes" : 1
}
>

 使用壓縮文件恢復(fù)數(shù)據(jù)庫

  刪除testdb數(shù)據(jù)庫

> db
testdb
> db.dropDatabase()
{ "dropped" : "testdb", "ok" : 1 }
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
>

  使用mongorestore工具加載壓縮文件恢復(fù)數(shù)據(jù)庫

[root@node11 ~]# mongorestore -utom -p123456 -h 192.168.0.52:27017 --authenticationDatabase admin -d testdb --gzip --drop ./node12_mongodb_testdb-gzip/testdb/
2020-11-15T22:39:55.313+0800 The --db and --collection flags are deprecated for this use-case; please use --nsInclude instead, i.e. with --nsInclude=${DATABASE}.${COLLECTION}
2020-11-15T22:39:55.313+0800 building a list of collections to restore from node12_mongodb_testdb-gzip/testdb dir
2020-11-15T22:39:55.314+0800 reading metadata for testdb.test from node12_mongodb_testdb-gzip/testdb/test.metadata.json.gz
2020-11-15T22:39:55.321+0800 restoring testdb.test from node12_mongodb_testdb-gzip/testdb/test.bson.gz
2020-11-15T22:39:55.332+0800 no indexes to restore
2020-11-15T22:39:55.332+0800 finished restoring testdb.test (1000 documents, 0 failures)
2020-11-15T22:39:55.332+0800 1000 document(s) restored successfully. 0 document(s) failed to restore.
[root@node11 ~]# mongo -utom -p123456 192.168.0.52:27017/admin      MongoDB shell version v4.4.1
connecting to: mongodb://192.168.0.52:27017/admin?compressors=disabledgssapiServiceName=mongodb
Implicit session: session { "id" : UUID("73d98c33-f8f7-40e3-89bd-fda8c702e407") }
MongoDB server version: 4.4.1
---
The server generated these startup warnings when booting:
 2020-11-15T20:42:23.774+08:00: ***** SERVER RESTARTED *****
 2020-11-15T20:42:29.198+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
 2020-11-15T20:42:29.198+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
---
---
 Enable MongoDB's free cloud-based monitoring service, which will then receive and display
 metrics about your deployment (disk utilization, CPU, operation statistics, etc).
 
 The monitoring data will be available on a MongoDB website with a unique URL accessible to you
 and anyone you share the URL with. MongoDB may use this information to make product
 improvements and to suggest MongoDB products and deployment options to you.
 
 To enable free monitoring, run the following command: db.enableFreeMonitoring()
 To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
testdb 0.000GB
> use testdb
switched to db testdb
> show collections
test
> db.test.count()
1000
> db.test.findOne()
{
 "_id" : ObjectId("5fb130da012870b3c8e3c4ad"),
 "id" : 1,
 "name" : "test1",
 "age" : 1,
 "classes" : 1
}
>

  提示:使用mongorestore恢復(fù)單個庫使用-d選線指定要恢復(fù)的數(shù)據(jù)庫,恢復(fù)單個集合使用-c指定集合名稱即可,以及使用壓縮文件恢復(fù)加上對應(yīng)的--gzip選項即可,總之,備份時用的選項在恢復(fù)時也應(yīng)當(dāng)使用對應(yīng)的選項,這個mongodump備份使用的選項沒有特別的不同;

  使用mongoexport備份數(shù)據(jù)

  新建peoples數(shù)據(jù)庫,并向peoples_info集合中插入數(shù)據(jù)

> use peoples
switched to db peoples
> for(i=1;i=10000;i++) db.peoples_info.insert({id:i,name:"peoples"+i,age:(i%120),classes:(i%25)})
WriteResult({ "nInserted" : 1 })
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
peoples 0.000GB
testdb 0.000GB
> db.peoples_info.count()
10000
> db.peoples_info.findOne()
{
 "_id" : ObjectId("5fb13f35012870b3c8e3c895"),
 "id" : 1,
 "name" : "peoples1",
 "age" : 1,
 "classes" : 1
}
>

  使用mongoexport工具peoples庫下的peoples_info集合

[root@node11 ~]# mongoexport -utom -p123456 -h 192.168.0.52:27017 --authenticationDatabase admin -d peoples -c peoples_info --type json -o ./peoples-peopels_info.json
2020-11-15T22:54:18.287+0800 connected to: mongodb://192.168.0.52:27017/
2020-11-15T22:54:18.370+0800 exported 10000 records
[root@node11 ~]# ll
total 1004
-rw-r--r-- 1 root root 1024609 Nov 15 22:54 peoples-peopels_info.json
[root@node11 ~]# head -n 1 peoples-peopels_info.json
{"_id":{"$oid":"5fb13f35012870b3c8e3c895"},"id":1.0,"name":"peoples1","age":1.0,"classes":1.0}
[root@node11 ~]#

  提示:使用--type可以指定導(dǎo)出數(shù)據(jù)文件的格式,默認(rèn)是json格式,當(dāng)然也可以指定csv格式;這里還需要注意mongoexport這個工具導(dǎo)出數(shù)據(jù)必須要指定數(shù)據(jù)庫和對應(yīng)集合,它不能直接對整個數(shù)據(jù)庫下的所有集合做導(dǎo)出;只能單個單個的導(dǎo);

  導(dǎo)出csv格式的數(shù)據(jù)文件

[root@node11 ~]# mongoexport -utom -p123456 -h 192.168.0.52:27017 --authenticationDatabase admin -d peoples -c peoples_info --type csv -o ./peoples-peopels_info.csv
2020-11-15T22:58:30.495+0800 connected to: mongodb://192.168.0.52:27017/
2020-11-15T22:58:30.498+0800 Failed: CSV mode requires a field list
[root@node11 ~]# mongoexport -utom -p123456 -h 192.168.0.52:27017 --authenticationDatabase admin -d peoples -c peoples_info --type csv -f id,name,age -o ./peoples-peopels_info.csv 
2020-11-15T22:59:26.090+0800 connected to: mongodb://192.168.0.52:27017/
2020-11-15T22:59:26.143+0800 exported 10000 records
[root@node11 ~]# head -n 1 ./peoples-peopels_info.csv
id,name,age
[root@node11 ~]# head ./peoples-peopels_info.csv 
id,name,age
1,peoples1,1
2,peoples2,2
3,peoples3,3
4,peoples4,4
5,peoples5,5
6,peoples6,6
7,peoples7,7
8,peoples8,8
9,peoples9,9
[root@node11 ~]#

  提示:導(dǎo)出指定格式為csv時,必須用-f選項指定導(dǎo)出的字段名稱,分別用逗號隔開;

  將數(shù)據(jù)導(dǎo)入到node11的mongodb上

  導(dǎo)入json格式數(shù)據(jù)

[root@node11 ~]# systemctl start mongod.service
[root@node11 ~]# ss -tnl
State Recv-Q Send-Q  Local Address:Port   Peer Address:Port  
LISTEN 0 128   *:22     *:*   
LISTEN 0 100  127.0.0.1:25     *:*   
LISTEN 0 128  127.0.0.1:27017     *:*   
LISTEN 0 128   :::22     :::*   
LISTEN 0 100   ::1:25     :::*   
[root@node11 ~]# ll
total 1200
-rw-r--r-- 1 root root 198621 Nov 15 22:59 peoples-peopels_info.csv
-rw-r--r-- 1 root root 1024609 Nov 15 22:54 peoples-peopels_info.json
[root@node11 ~]# mongoimport -d testdb -c peoples_info --drop peoples-peopels_info.json
2020-11-15T23:05:03.004+0800 connected to: mongodb://localhost/
2020-11-15T23:05:03.005+0800 dropping: testdb.peoples_info
2020-11-15T23:05:03.186+0800 10000 document(s) imported successfully. 0 document(s) failed to import.
[root@node11 ~]#

  提示:導(dǎo)入數(shù)據(jù)時可以任意指定數(shù)據(jù)庫以及集合名稱;

  驗證:查看node11上的testdb庫下是否有peoples_info集合?集合中是否有數(shù)據(jù)呢?

[root@node11 ~]# mongo
MongoDB shell version v4.4.1
connecting to: mongodb://127.0.0.1:27017/?compressors=disabledgssapiServiceName=mongodb
Implicit session: session { "id" : UUID("4e3a00b0-8367-4b3a-9a77-e61d03bb1b3d") }
MongoDB server version: 4.4.1
---
The server generated these startup warnings when booting:
 2020-11-15T23:03:39.669+08:00: ***** SERVER RESTARTED *****
 2020-11-15T23:03:40.681+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
 2020-11-15T23:03:40.681+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
 2020-11-15T23:03:40.681+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
---
---
 Enable MongoDB's free cloud-based monitoring service, which will then receive and display
 metrics about your deployment (disk utilization, CPU, operation statistics, etc).
 
 The monitoring data will be available on a MongoDB website with a unique URL accessible to you
 and anyone you share the URL with. MongoDB may use this information to make product
 improvements and to suggest MongoDB products and deployment options to you.
 
 To enable free monitoring, run the following command: db.enableFreeMonitoring()
 To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
testdb 0.000GB
> use testdb
switched to db testdb
> show collections
peoples_info
> db.peoples_info.count()
10000
> db.peoples_info.findOne()
{
 "_id" : ObjectId("5fb13f35012870b3c8e3c895"),
 "id" : 1,
 "name" : "peoples1",
 "age" : 1,
 "classes" : 1
}
>

  導(dǎo)入csv格式數(shù)據(jù)到node12上的testdb庫下的test1集合中去

[root@node11 ~]# mongoimport -utom -p123456 -h 192.168.0.52:27017 --authenticationDatabase admin -d testdb -c test1 --type csv --headerline --file ./peoples-peopels_info.csv
2020-11-15T23:11:42.595+0800 connected to: mongodb://192.168.0.52:27017/
2020-11-15T23:11:42.692+0800 10000 document(s) imported successfully. 0 document(s) failed to import.
[root@node11 ~]#

 提示:導(dǎo)入csv格式的數(shù)據(jù)需要明確指定類型為csv,然后使用--headerline指定不導(dǎo)入第一行列名,--file使用用于指定csv格式文件的名稱;

  驗證:登錄node12的mongodb,查看testdb庫下是否有test1集合?對應(yīng)集合是否有數(shù)據(jù)呢?

[root@node11 ~]# mongo -utom -p123456 192.168.0.52:27017/admin
MongoDB shell version v4.4.1
connecting to: mongodb://192.168.0.52:27017/admin?compressors=disabledgssapiServiceName=mongodb
Implicit session: session { "id" : UUID("72a07318-ac04-46f9-a310-13b1241d2f77") }
MongoDB server version: 4.4.1
---
The server generated these startup warnings when booting:
 2020-11-15T20:42:23.774+08:00: ***** SERVER RESTARTED *****
 2020-11-15T20:42:29.198+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
 2020-11-15T20:42:29.198+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
---
---
 Enable MongoDB's free cloud-based monitoring service, which will then receive and display
 metrics about your deployment (disk utilization, CPU, operation statistics, etc).
 
 The monitoring data will be available on a MongoDB website with a unique URL accessible to you
 and anyone you share the URL with. MongoDB may use this information to make product
 improvements and to suggest MongoDB products and deployment options to you.
 
 To enable free monitoring, run the following command: db.enableFreeMonitoring()
 To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
peoples 0.000GB
testdb 0.000GB
> use testdb
switched to db testdb
> show collections
test
test1
> db.test1.count()
10000
> db.test1.findOne()
{
 "_id" : ObjectId("5fb1452ef09b563b65405f7c"),
 "id" : 1,
 "name" : "peoples1",
 "age" : 1
}
>

  提示:可以看到testdb庫下的test1結(jié)合就沒有classes字段信息了,這是因為我們導(dǎo)出數(shù)據(jù)時沒有指定要導(dǎo)出classes字段,所以導(dǎo)入的數(shù)據(jù)當(dāng)然也是沒有classes字段信息;以上就是mongodump/mongorestore和mongoexport/mongoimport工具的使用和測試;

  全量備份加oplog實現(xiàn)恢復(fù)mongodb數(shù)據(jù)庫到指定時間點的數(shù)據(jù)

  在mongodump備份數(shù)據(jù)時,我們可以使用--oplog選項來記錄開始dump數(shù)據(jù)到dump數(shù)據(jù)結(jié)束后的中間一段時間mongodb數(shù)據(jù)發(fā)生變化的日志;我們知道oplog就是用來記錄mongodb中的集合寫操作的日志,類似mysql中的binlog;我們可以使用oplog將備份期間發(fā)生變化的數(shù)據(jù)一起恢復(fù),這樣恢復(fù)出來的數(shù)據(jù)才是我們真正備份時的所有數(shù)據(jù);

  模擬備份時,一邊插入數(shù)據(jù),一邊備份數(shù)據(jù)

test_replset:PRIMARY> use testdb
switched to db testdb
test_replset:PRIMARY> for(i=1;i=1000000;i++) db.test3.insert({id:i,name:"test3-oplog"+i,commit:"test3"+i})

  在另外一邊同時對數(shù)據(jù)做備份

[root@node11 ~]# rm -rf *
[root@node11 ~]# ll
total 0
[root@node11 ~]# mongodump -utom -p123456 -h 192.168.0.52:27017 --authenticationDatabase admin --oplog -o ./alldatabase
2020-11-15T23:51:40.606+0800 writing admin.system.users to alldatabase/admin/system.users.bson
2020-11-15T23:51:40.606+0800 done dumping admin.system.users (4 documents)
2020-11-15T23:51:40.607+0800 writing admin.system.version to alldatabase/admin/system.version.bson
2020-11-15T23:51:40.608+0800 done dumping admin.system.version (2 documents)
2020-11-15T23:51:40.609+0800 writing testdb.test1 to alldatabase/testdb/test1.bson
2020-11-15T23:51:40.611+0800 writing testdb.test3 to alldatabase/testdb/test3.bson
2020-11-15T23:51:40.612+0800 writing testdb.test to alldatabase/testdb/test.bson
2020-11-15T23:51:40.612+0800 writing peoples.peoples_info to alldatabase/peoples/peoples_info.bson
2020-11-15T23:51:40.696+0800 done dumping peoples.peoples_info (10000 documents)
2020-11-15T23:51:40.761+0800 done dumping testdb.test3 (54167 documents)
2020-11-15T23:51:40.803+0800 done dumping testdb.test (31571 documents)
2020-11-15T23:51:40.966+0800 done dumping testdb.test1 (79830 documents)
2020-11-15T23:51:40.972+0800 writing captured oplog to
2020-11-15T23:51:40.980+0800  dumped 916 oplog entries
[root@node11 ~]# ll
total 0
drwxr-xr-x 5 root root 66 Nov 15 23:51 alldatabase
[root@node11 ~]# tree alldatabase/
alldatabase/
├── admin
│ ├── system.users.bson
│ ├── system.users.metadata.json
│ ├── system.version.bson
│ └── system.version.metadata.json
├── oplog.bson
├── peoples
│ ├── peoples_info.bson
│ └── peoples_info.metadata.json
└── testdb
 ├── test1.bson
 ├── test1.metadata.json
 ├── test3.bson
 ├── test3.metadata.json
 ├── test.bson
 └── test.metadata.json
 
3 directories, 13 files
[root@node11 ~]#

  提示:可以看到現(xiàn)在備份就多了一個oplog.bson;

  查看oplog.bson中第一行記錄的數(shù)據(jù)和第二行記錄的數(shù)據(jù)

[root@node11 ~]# ls
alldatabase
[root@node11 ~]# cd alldatabase/
[root@node11 alldatabase]# ls
admin oplog.bson peoples testdb
[root@node11 alldatabase]# bsondump oplog.bson > /tmp/oplog.bson.tmp
2020-11-15T23:55:04.801+0800 916 objects found
[root@node11 alldatabase]# head -n 1 /tmp/oplog.bson.tmp
{"op":"i","ns":"testdb.test3","ui":{"$binary":{"base64":"7PmE47CASOiQZt5sMGDZKw==","subType":"04"}},"o":{"_id":{"$oid":"5fb14e8c01fff06b2b50a2ac"},"id":{"$numberDouble":"54101.0"},"name":"test3-oplog54101","commit":"test354101"},"ts":{"$timestamp":{"t":1605455500,"i":1880}},"t":{"$numberLong":"1"},"wall":{"$date":{"$numberLong":"1605455500608"}},"v":{"$numberLong":"2"}}
[root@node11 alldatabase]# tail -n 1 /tmp/oplog.bson.tmp
{"op":"i","ns":"testdb.test3","ui":{"$binary":{"base64":"7PmE47CASOiQZt5sMGDZKw==","subType":"04"}},"o":{"_id":{"$oid":"5fb14e8c01fff06b2b50a63f"},"id":{"$numberDouble":"55016.0"},"name":"test3-oplog55016","commit":"test355016"},"ts":{"$timestamp":{"t":1605455500,"i":2795}},"t":{"$numberLong":"1"},"wall":{"$date":{"$numberLong":"1605455500961"}},"v":{"$numberLong":"2"}}
[root@node11 alldatabase]#

  提示:可以看到oplog中記錄了id為54101-55016數(shù)據(jù),這也就說明了我們開始dump數(shù)據(jù)時,到dump結(jié)束后,數(shù)據(jù)一致在發(fā)生變化,所以我們dump下來的數(shù)據(jù)是一個中間狀態(tài)的數(shù)據(jù);這里需要說明一點使用mongodump --oplog選項時,不能指定庫,因為oplog是對所有庫,而不針對某個庫記錄,所以--oplog只有在備份所有數(shù)據(jù)庫生效;

  刪除testdb數(shù)據(jù)庫,然后基于我們剛才dump的數(shù)據(jù)做數(shù)據(jù)恢復(fù)

test_replset:PRIMARY> show dbs
admin 0.000GB
config 0.000GB
local 0.014GB
peoples 0.000GB
testdb 0.019GB
test_replset:PRIMARY> use testdb
switched to db testdb
test_replset:PRIMARY> db.dropDatabase()
{
 "dropped" : "testdb",
 "ok" : 1,
 "$clusterTime" : {
  "clusterTime" : Timestamp(1605456134, 4),
  "signature" : {
   "hash" : BinData(0,"cRAdXcUj5c48Q77rCJ1DeeF10u8="),
   "keyId" : NumberLong("6895378399531892740")
  }
 },
 "operationTime" : Timestamp(1605456134, 4)
}
test_replset:PRIMARY> show dbs
admin 0.000GB
config 0.000GB
local 0.014GB
peoples 0.000GB
test_replset:PRIMARY>

  使用mongorestore恢復(fù)數(shù)據(jù)

[root@node11 ~]# ls
alldatabase
[root@node11 ~]# mongorestore -utom -p123456 -h 192.168.0.52:27017 --authenticationDatabase admin --oplogReplay --drop ./alldatabase/
2020-11-16T00:06:32.049+0800 preparing collections to restore from
2020-11-16T00:06:32.053+0800 reading metadata for testdb.test1 from alldatabase/testdb/test1.metadata.json
2020-11-16T00:06:32.060+0800 reading metadata for testdb.test3 from alldatabase/testdb/test3.metadata.json
2020-11-16T00:06:32.064+0800 reading metadata for testdb.test from alldatabase/testdb/test.metadata.json
2020-11-16T00:06:32.064+0800 restoring testdb.test1 from alldatabase/testdb/test1.bson
2020-11-16T00:06:32.074+0800 restoring testdb.test3 from alldatabase/testdb/test3.bson
2020-11-16T00:06:32.093+0800 restoring testdb.test from alldatabase/testdb/test.bson
2020-11-16T00:06:32.098+0800 reading metadata for peoples.peoples_info from alldatabase/peoples/peoples_info.metadata.json
2020-11-16T00:06:32.110+0800 restoring peoples.peoples_info from alldatabase/peoples/peoples_info.bson
2020-11-16T00:06:32.333+0800 no indexes to restore
2020-11-16T00:06:32.333+0800 finished restoring peoples.peoples_info (10000 documents, 0 failures)
2020-11-16T00:06:32.766+0800 no indexes to restore
2020-11-16T00:06:32.766+0800 finished restoring testdb.test (31571 documents, 0 failures)
2020-11-16T00:06:33.023+0800 no indexes to restore
2020-11-16T00:06:33.023+0800 finished restoring testdb.test3 (54167 documents, 0 failures)
2020-11-16T00:06:33.370+0800 no indexes to restore
2020-11-16T00:06:33.370+0800 finished restoring testdb.test1 (79830 documents, 0 failures)
2020-11-16T00:06:33.370+0800 restoring users from alldatabase/admin/system.users.bson
2020-11-16T00:06:33.416+0800 replaying oplog
2020-11-16T00:06:33.850+0800 applied 916 oplog entries
2020-11-16T00:06:33.850+0800 175568 document(s) restored successfully. 0 document(s) failed to restore.
[root@node11 ~]#

  提示:恢復(fù)是需要使用--oplogReplay選項來指定重放oplog.bson中的內(nèi)容;從上面恢復(fù)日志可以看到從oplog中恢復(fù)了916條數(shù)據(jù);也就是說從dump數(shù)據(jù)開始的那一刻開始到dump結(jié)束期間有916條數(shù)據(jù)發(fā)生變化;

  驗證:連接數(shù)據(jù)庫,看看對應(yīng)的testdb庫下的test3集合恢復(fù)了多少條數(shù)據(jù)?

test_replset:PRIMARY> use testdb
switched to db testdb
test_replset:PRIMARY> show tables
test
test1
test3
test_replset:PRIMARY> db.test3.count()
55016
test_replset:PRIMARY>

  提示:可以看到test3集合恢復(fù)了55016條數(shù)據(jù);剛好可以和oplog.bson中的最后一條數(shù)據(jù)的id對應(yīng)起來;

  備份oplog.rs實現(xiàn)指定恢復(fù)到某個時間節(jié)點

  為了演示容易看出效果,我這里從新將數(shù)據(jù)庫清空,關(guān)閉了認(rèn)證功能

  插入數(shù)據(jù)

test_replset:PRIMARY> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
test_replset:PRIMARY> use testdb
switched to db testdb
test_replset:PRIMARY> for(i=1;i=100000;i++) db.test.insert({id:(i+10000),name:"test-oplog"+i,commit:"test"+i})

  同時備份數(shù)據(jù),這次不加--oplog選項

[root@node11 ~]# ll
total 0
[root@node11 ~]# mongodump -h node12:27017 -o ./alldatabase
2020-11-16T09:38:00.921+0800 writing admin.system.version to alldatabase/admin/system.version.bson
2020-11-16T09:38:00.923+0800 done dumping admin.system.version (1 document)
2020-11-16T09:38:00.924+0800 writing testdb.test to alldatabase/testdb/test.bson
2020-11-16T09:38:00.960+0800 done dumping testdb.test (16377 documents)
[root@node11 ~]# ll
total 0
drwxr-xr-x 4 root root 33 Nov 16 09:38 alldatabase
[root@node11 ~]# tree ./alldatabase
./alldatabase
├── admin
│ ├── system.version.bson
│ └── system.version.metadata.json
└── testdb
 ├── test.bson
 └── test.metadata.json
 
2 directories, 4 files
[root@node11 ~]#

  提示:我們在一邊插入數(shù)據(jù),一邊備份數(shù)據(jù),從上面的被日志可以看到,我們備份testdb庫下的test集合16377條數(shù)據(jù),很顯然這不是testdb.test集合的所有數(shù)據(jù);我們備份的只是部分?jǐn)?shù)據(jù);正常情況等數(shù)據(jù)插入完成以后,testdb.test集合應(yīng)該有100000條數(shù)據(jù);

  驗證:查看testdb.test集合是否有100000條數(shù)據(jù)?

test_replset:PRIMARY> db
testdb
test_replset:PRIMARY> show collections
test
test_replset:PRIMARY> db.test.count()
100000
test_replset:PRIMARY>

  模擬誤操作刪除testdb.test集合所有數(shù)據(jù)

test_replset:PRIMARY> db
testdb
test_replset:PRIMARY> show collections
test
test_replset:PRIMARY> db.test.remove({})
WriteResult({ "nRemoved" : 100000 })
test_replset:PRIMARY>

  提示:現(xiàn)在我們不小心把testdb.test集合給刪除了,現(xiàn)在如果用之前的備份肯定只能恢復(fù)部分?jǐn)?shù)據(jù),怎么辦呢?我們這個時候可以導(dǎo)出oplog.rs集合,這個集合就是oplog存放數(shù)據(jù)的集合,它位于local庫下;

  備份local庫中的oplog.rs集合

[root@node11 ~]# ll
total 0
drwxr-xr-x 4 root root 33 Nov 16 09:38 alldatabase
[root@node11 ~]# mongodump -h node12:27017 -d local -c oplog.rs -o ./oplog-rs
2020-11-16T09:43:38.594+0800 writing local.oplog.rs to oplog-rs/local/oplog.rs.bson
2020-11-16T09:43:38.932+0800 done dumping local.oplog.rs (200039 documents)
[root@node11 ~]# ll
total 0
drwxr-xr-x 4 root root 33 Nov 16 09:38 alldatabase
drwxr-xr-x 3 root root 19 Nov 16 09:43 oplog-rs
[root@node11 ~]# tree ./oplog-rs
./oplog-rs
└── local
 ├── oplog.rs.bson
 └── oplog.rs.metadata.json
 
1 directory, 2 files
[root@node11 ~]#

  提示:oplog存放在local庫下的oplog.rs集合中,以上操作就是備份所有的oplog;現(xiàn)在我們準(zhǔn)備好一個oplog,但是現(xiàn)在還不能直接恢復(fù),如果直接恢復(fù),我們的誤操作也會跟著一起重放沒有任何意義,現(xiàn)在我們需要找到誤操作的時間點,然后在恢復(fù);

  在oplog中查找誤刪除的時間

[root@node11 ~]# bsondump oplog-rs/local/oplog.rs.bson |egrep "\"op\":\"d\""|head -n 3
{"op":"d","ns":"testdb.test","ui":{"$binary":{"base64":"C3FH7g1eSWWwHd2AZEJhiw==","subType":"04"}},"o":{"_id":{"$oid":"5fb1d7eb25343e833cbaa146"}},"ts":{"$timestamp":{"t":1605490915,"i":1}},"t":{"$numberLong":"1"},"wall":{"$date":{"$numberLong":"1605490915399"}},"v":{"$numberLong":"2"}}
{"op":"d","ns":"testdb.test","ui":{"$binary":{"base64":"C3FH7g1eSWWwHd2AZEJhiw==","subType":"04"}},"o":{"_id":{"$oid":"5fb1d7eb25343e833cbaa147"}},"ts":{"$timestamp":{"t":1605490915,"i":2}},"t":{"$numberLong":"1"},"wall":{"$date":{"$numberLong":"1605490915400"}},"v":{"$numberLong":"2"}}
{"op":"d","ns":"testdb.test","ui":{"$binary":{"base64":"C3FH7g1eSWWwHd2AZEJhiw==","subType":"04"}},"o":{"_id":{"$oid":"5fb1d7eb25343e833cbaa148"}},"ts":{"$timestamp":{"t":1605490915,"i":3}},"t":{"$numberLong":"1"},"wall":{"$date":{"$numberLong":"1605490915400"}},"v":{"$numberLong":"2"}}
2020-11-16T09:46:20.363+0800 100074 objects found
2020-11-16T09:46:20.363+0800 write /dev/stdout: broken pipe
[root@node11 ~]#

  提示:我們要恢復(fù)到第一次刪除前的數(shù)據(jù),我們就選擇第一條日志中的$timestamp字段中的{"t":1605490915,"i":1};這個就是我們第一次刪除的時間信息;

  復(fù)制oplog.rs.bson到備份的數(shù)據(jù)目錄為oplog.bson,模擬出使用--oplog選項備份的備份環(huán)境

[root@node11 ~]# cp ./oplog-rs/local/oplog.rs.bson ./alldatabase/oplog.bson
[root@node11 ~]#

  在使用mongorestore進(jìn)行恢復(fù)數(shù)據(jù),指定恢復(fù)到第一次刪除數(shù)據(jù)前的時間點所有數(shù)據(jù)

[root@node11 ~]# mongorestore -h node12:27017 --oplogReplay --oplogLimit "1605490915:1" --drop ./alldatabase/
2020-11-16T09:51:19.658+0800 preparing collections to restore from
2020-11-16T09:51:19.668+0800 reading metadata for testdb.test from alldatabase/testdb/test.metadata.json
2020-11-16T09:51:19.693+0800 restoring testdb.test from alldatabase/testdb/test.bson
2020-11-16T09:51:19.983+0800 no indexes to restore
2020-11-16T09:51:19.983+0800 finished restoring testdb.test (16377 documents, 0 failures)
2020-11-16T09:51:19.983+0800 replaying oplog
2020-11-16T09:51:22.657+0800 oplog 537KB
2020-11-16T09:51:25.657+0800 oplog 1.12MB
2020-11-16T09:51:28.657+0800 oplog 1.72MB
2020-11-16T09:51:31.657+0800 oplog 2.32MB
2020-11-16T09:51:34.657+0800 oplog 2.92MB
2020-11-16T09:51:37.657+0800 oplog 3.51MB
2020-11-16T09:51:40.657+0800 oplog 4.11MB
2020-11-16T09:51:43.657+0800 oplog 4.71MB
2020-11-16T09:51:46.657+0800 oplog 5.30MB
2020-11-16T09:51:49.657+0800 oplog 5.90MB
2020-11-16T09:51:52.657+0800 oplog 6.46MB
2020-11-16T09:51:55.657+0800 oplog 7.04MB
2020-11-16T09:51:58.657+0800 oplog 7.61MB
2020-11-16T09:52:01.657+0800 oplog 8.20MB
2020-11-16T09:52:04.657+0800 oplog 8.77MB
2020-11-16T09:52:07.657+0800 oplog 9.36MB
2020-11-16T09:52:10.657+0800 oplog 9.96MB
2020-11-16T09:52:13.657+0800 oplog 10.6MB
2020-11-16T09:52:16.656+0800 oplog 11.2MB
2020-11-16T09:52:19.657+0800 oplog 11.8MB
2020-11-16T09:52:22.657+0800 oplog 12.4MB
2020-11-16T09:52:25.657+0800 oplog 13.0MB
2020-11-16T09:52:28.657+0800 oplog 13.6MB
2020-11-16T09:52:31.657+0800 oplog 14.2MB
2020-11-16T09:52:34.657+0800 oplog 14.8MB
2020-11-16T09:52:37.657+0800 oplog 15.4MB
2020-11-16T09:52:40.657+0800 oplog 16.0MB
2020-11-16T09:52:43.657+0800 oplog 16.6MB
2020-11-16T09:52:46.657+0800 oplog 17.2MB
2020-11-16T09:52:49.657+0800 oplog 17.8MB
2020-11-16T09:52:52.433+0800 skipping applying the config.system.sessions namespace in applyOps
2020-11-16T09:52:52.433+0800 applied 100008 oplog entries
2020-11-16T09:52:52.433+0800 oplog 18.4MB
2020-11-16T09:52:52.433+0800 16377 document(s) restored successfully. 0 document(s) failed to restore.
[root@node11 ~]#

  提示:從上面的恢復(fù)日志可以看到oplog恢復(fù)了100008條,備份的16377條數(shù)據(jù)也成功恢復(fù);

  驗證:查看testdb.test集合是否恢復(fù)?數(shù)據(jù)恢復(fù)了多少條呢?

test_replset:PRIMARY> show dbs
admin 0.000GB
config 0.000GB
local 0.010GB
testdb 0.004GB
test_replset:PRIMARY> use testdb
switched to db testdb
test_replset:PRIMARY> show tables
test
test_replset:PRIMARY> db.test.count()
100000
test_replset:PRIMARY>

 提示:可以看到testdb.test集合恢復(fù)了100000條數(shù)據(jù);

  以上就是mongodb的備份與恢復(fù)相關(guān)話題的實踐;

到此這篇關(guān)于分布式文檔存儲數(shù)據(jù)庫之MongoDB備份與恢復(fù)的文章就介紹到這了,更多相關(guān)MongoDB備份與恢復(fù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • 分布式文檔存儲數(shù)據(jù)庫之MongoDB訪問控制的操作方法
  • 分布式文檔存儲數(shù)據(jù)庫之MongoDB分片集群的問題
  • SpringDataMongoDB多文檔事務(wù)的實現(xiàn)
  • mongodb如何對文檔內(nèi)數(shù)組進(jìn)行過濾的方法步驟
  • MongoDB中文檔的更新操作示例詳解
  • MongoDB數(shù)據(jù)庫文檔操作方法(必看篇)
  • mongodb 數(shù)據(jù)類型(null/字符串/數(shù)字/日期/內(nèi)嵌文檔/數(shù)組等)
  • PHP庫 查詢Mongodb中的文檔ID的方法
  • MongoDB如何更新多級文檔的數(shù)據(jù)

標(biāo)簽:安順 楚雄 白山 池州 呼倫貝爾 菏澤 舟山 黃石

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《分布式文檔存儲數(shù)據(jù)庫之MongoDB備份與恢復(fù)的實踐詳解》,本文關(guān)鍵詞  分布式,文檔,存儲,數(shù)據(jù)庫,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《分布式文檔存儲數(shù)據(jù)庫之MongoDB備份與恢復(fù)的實踐詳解》相關(guān)的同類信息!
  • 本頁收集關(guān)于分布式文檔存儲數(shù)據(jù)庫之MongoDB備份與恢復(fù)的實踐詳解的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    99精品视频一区| 91精品韩国| 2020色愉拍亚洲偷自拍| 亚洲狼人精品一区二区三区| 欧美视频精品在线| 精品剧情v国产在线观看在线| 国产精品视频导航| 国产精品亚洲综合久久小说| 久久国产综合| av大大超碰在线| 日韩成人网免费视频| 黄色一区二区在线观看| 中文字幕777| 丁香花电影在线观看完整版| www污污在线| 亚洲综合在线一区| 户外露出精品视频国产| 亚洲成av人片乱码色午夜| 欧美成人性福生活免费看| 欧美伦理视频网站| 日韩av电影一区| 无套白嫩进入乌克兰美女| 亚洲第一精品久久忘忧草社区| 成人av在线播放网址| 国产美女18xxxx免费视频| 日韩成人午夜电影| av日韩在线免费观看| 3d欧美精品动漫xxxx无尽| 日韩精品免费电影| 在线免费观看国产精品| 污污网站免费在线观看| 久久久久久黄| 一区二区成人免费视频| 亚洲综合自拍网| 欧美13一16娇小xxxx| 国产精品三区在线| 欧美xxxxx性| 国产91在线高潮白浆在线观看| 日日橹狠狠爱欧美超碰| 国产视色精品亚洲一区二区| 亚洲网站免费观看| 国产奶水涨喷在线播放| 中国色在线日|韩| 亚洲人妻一区二区三区| 亚洲五月六月| 国产视频一区二区三区四区| 国产精品va在线观看视色| 成年人网站在线观看免费| 欧美一区二区久久久| 中文幕av一区二区三区佐山爱| 四虎永久国产精品| 波多野结衣三级视频| 亚洲911精品成人18网站| 成人午夜免费影院| 亚洲国产日日夜夜| 91猫先生在线| 免费看91的网站| 成人激情综合网| 免费观看国产精品视频| 欧美伊久线香蕉线新在线| 波多野结衣国产| 久久久久久一区二区三区四区别墅| 美丽的姑娘在线观看免费动漫| 国产成人av一区| 欧美一级专区| 久久精品国产免费| 懂色一区二区三区av片| 337p日本欧洲亚洲大胆色噜噜| 成人精品高清在线视频| 国产精品一品二区三区的使用体验| hs网站在线观看| 中文在线一区| 色先锋av资源| 美女做a视频| 在线视频xx| 免费久久99精品国产自| 亚洲婷婷国产精品电影人久久| 欧美不卡一区二区三区| 亚洲女同女同女同女同女同69| 天堂网.www在线资源| 国产精品视频免费在线观看| 黄色三级高清在线播放| 四虎影视永久免费观看| 成人一级福利| 久久www成人_看片免费不卡| 激情五月俺来也| 国产精品人人| 日韩欧美综合在线| 草莓视频18免费观看| 久久夜色精品亚洲| 少妇一级淫片免费放中国| 91国产丝袜在线播放| 国产女同无遮挡互慰高潮91| 欧美激情福利| 综合国产第二页| 亚洲欧美视频在线播放| 国产一区二区调教| 亚洲人成精品久久久| 五月天婷婷在线视频| 尤物在线观看一区| 国产精品香蕉一区二区三区| av资源网在线观看| 污视频网站在线免费观看| 99久久99久久精品免费看蜜桃| 国产原创在线观看| 日韩精品在线视频免费观看| 黄色性视频网站| 日本免费一二三区| 国产91av视频| 911久久香蕉国产线看观看| 亚洲免费伊人电影在线观看av| 精品视频高清无人区区二区三区| 少女频道在线观看高清| 一区二区久久| 日本福利片免费看| 大胆av不用播放器在线播放| 韩国三级hd两男一女| 全国精品久久少妇| 色偷偷亚洲第一综合| 国产素人视频在线观看| 久久久久久久久久99| 国模大尺度视频一区二区| 日韩欧美国产一区在线观看| 性欧美暴力猛交69hd| 亚洲美女视频在线观看| 一本色道**综合亚洲精品蜜桃冫| 国产精品无码av无码| 美女扒开腿让男人桶爽久久软| 欧美不卡在线观看| 欧美视频在线第一页| 国产欧美日韩一区| 日韩精品在线免费观看| 中文字幕欧美激情一区| 欧美精品日韩在线| 日韩欧美一区二区三区在线观看| 午夜亚洲福利| 欧美一区二区三区在线观看免费| 亚洲最大的成人av| 亚洲第一天堂影院| 亚洲无人区码一码二码三码| 亚洲美女免费精品视频在线观看| 精品嫩草影院| 国产精品九色蝌蚪自拍| 欧美在线激情| 国产精品麻豆99久久久久久| www.51av欧美视频| 一个人看的www视频免费观看| 乱熟女高潮一区二区在线| 日韩精品久久久毛片一区二区| 日韩精品中文字幕有码专区| 可以免费看污视频的网站在线| 57pao国产成人免费| www三级免费| 日韩高清中文字幕一区二区| 欧美+日本+国产+在线a∨观看| 成人网站免费观看入口| 国产精品视频播放| 免费观看成年人视频在线观看| yw视频在线观看| 红桃视频国产精品| 久久综合激情| 国产 国语对白 露脸| 亚洲少妇一区| 宅男视频免费在线观看视频| 免费黄色日本网站| 欧美日本不卡视频| 国产精品日韩欧美一区二区三区| 北条麻妃一二三区| 天堂中文字幕一二区| 成人h视频在线观看| 久久99精品久久久久久野外| 国产精品腿扒开做爽爽爽挤奶网站| 日韩中文首页| 粉嫩av一区二区三区四区五区| 在线观看黄网站免费继续| 瑟瑟网站在线观看| 五月天婷婷视频| 日韩欧美亚洲天堂| 一区二区高清不卡| 91视频网页| 欧美午夜精品一区二区三区电影| 第一视频专区在线| 日本边添边摸边做边爱的第三级| 人妻少妇精品无码专区久久| 亚洲精品在线一区二区| 国产精品电影| 网站在线你懂的| 亚洲av成人精品日韩在线播放| japan高清日本乱xxxx| 97人人香蕉| 日本美女视频网站| 亚洲一区日本| 最近中文字幕免费观看| 在线视频精品免费| sm捆绑调教视频| 亚洲国产欧美在线人成| 精品a在线观看| 欧美最顶级丰满的aⅴ艳星| 在线免费观看h视频| 日韩.欧美.亚洲| 成人禁用看黄a在线| 久久午夜夜伦鲁鲁一区二区| 色偷偷福利视频| 91精品国产综合久久久久久久| 日皮视频在线免费观看| 成人18网址在线观看| 激情偷乱视频一区二区三区| 中文字幕精品av| 亚洲aⅴ优女av综合久久久| 又嫩又硬又黄又爽的视频| 日韩视频在线观看免费| www.91av视频.com| 91精品国产高清自在线| 在线 丝袜 欧美 日韩 制服| 国产va免费精品观看精品视频| 最新精品国偷自产在线| 久久精品免费电影| jizz大全欧美jizzcom| 日本成人小视频| 91美女视频网站| 国产日韩免费| 伊人久久婷婷色综合98网| 中文天堂最新版本在线观看| 国产一级大片| 天海翼一区二区三区免费| av网站大全在线观看| 国产精品无码久久久久成人app| 午夜免费一区二区| 九色精品免费永久在线| 日本网址在线观看| 国产福利精品导航| 婷婷久久一区| 亚洲色图欧美日韩| 在线视频亚洲欧美中文| 久久精品国亚洲| 亚洲国产精品久久久久秋霞不卡| 亚洲成年电人电影网站| 一道本无吗dⅴd在线播放一区| 蜜桃久久影院| 在线日韩精品视频| 在线精品视频一区二区三四| 国产欧美日韩一区| 在线看国产一区| 91久久久久久国产精品| 亚洲影院在线看| 亚洲美女在线视频| 欧美熟妇交换久久久久久分类| 中文字幕2018| 在线观看免费电影| 成人午夜在线影视| 欧美日韩中文字幕日韩欧美| 欧美va天堂在线| 日韩资源在线| 亚洲国产色一区| 亚洲美女视频在线| 91视频黄色| 99精品视频免费全部在线| 免费看的av网站| 91精品国产综合久久国产大片| 成人免费网站www网站高清| 91小视频在线| 26uuu色噜噜精品一区二区| 国产羞羞视频在线播放| 亚洲精品无码久久久久久久| 日本一区二区视频在线观看| 成人网址大全| 国产精品一区二区a| 精品精品国产三级a∨在线| 中文字幕乱码一区二区免费| 欧美一区二视频| 欧美成人中文字幕在线| 国产精品a久久久久久| 欧美欧美欧美欧美首页| 日韩午夜精品| 日本免费黄色小视频| 国内精品久久久久国产盗摄免费观看完整版| 欧美在线一级片| jizz久久久久久| 最新高清无码专区| 国产美女极度色诱视频www| 青青草免费在线视频观看| 97精品久久久午夜一区二区三区| 红桃视频国产精品| 亚洲国产成人91精品| 欧美日韩亚洲国产一区| 秋霞电影一区二区| 国产精品老熟女一区二区| 色丁香久综合在线久综合在线观看| 丰满少妇乱子伦精品看片| 欧美午夜精品久久久久免费视| 欧美午夜影院在线视频| 爱豆国产剧免费观看大全剧苏畅| 激情综合久久| 国产乱子伦精品视频| 日韩美女视频免费在线观看| 91嫩草在线播放| 51国产成人精品午夜福中文下载| 91超薄丝袜肉丝一区二区| 亚洲一区视频| av大片在线免费观看| 一本到av在线| 最新国产在线| 久久国产精品免费| 激情美女网站| 成人一区二区三区视频在线观看| 国产稀缺精品盗摄盗拍| 五月天丁香在线| 成人午夜两性视频| 亚洲1区2区3区4区| 亚洲aaa视频| 欧美乱大交xxxxx免费| 欧美日韩免费区域视频在线观看| 一色屋色费精品视频在线观看| 国产一区二区福利| 欧美色图免费看| 91看片淫黄大片一级| 色综合久久综合| 日韩精品成人免费观看视频| 亚洲欧洲日产国码无码久久99| 亚洲日本黄色片| 欧美视频在线观看免费| 性欧美video另类hd尤物| 国产一区二区在线播放视频| 精品一区二区三区在线成人| 欧美成人一二三区| 色天天久久综合婷婷女18| 先锋资源中文在线| 91香蕉视频污版|