多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > 數據庫 > 數據庫應用 > mongodb 通過mongodump來備份Sharded Cluste分片集群

mongodb 通過mongodump來備份Sharded Cluste分片集群

來源:程序員人生   發布時間:2016-07-07 19:31:52 閱讀次數:4867次

 

1mongodb所有組件

官方文檔地址:https://docs.mongodb.com/manual/reference/command/,所有的基礎組件都在里面,包括備份恢復的mongodump、mongorestore,如01.png所示:

 

 

 


2,備份組件mongodump 概要

mongodump is a utility for creating a binary export of the contents of a database. mongodump can export data from either mongod or mongos instances.

mongodump can be a part of a backup strategy with mongorestore for partial backups based on a query, syncing from production to staging or development environments, or changing the storage engine of a standalone. However, the use of mongodump and mongorestore as a backup strategy can be problematic for sharded clusters and replica sets.

# 翻譯以下

Mongodump是將mongodb數據庫內容以2進制日志的方式導出的組件函數。Mongodump和mongostore1起可以作為mongodb的備份策略的模塊,可以同步生產環境到臨時環境庫和開發環境庫,或也能夠改變單機環境的存儲引擎。但是作為備份策略方案mongodump和mongostore也能適用于cluster集群和replica-sets副本集。

 

Mongodump不備份索引數據,在做mongostore的時候會自動重建索引

 

mongodump can adversely affect performance of the mongod. Ifyour data is larger than system memory, themongodump will pushthe working set out of memory.

意味著如果數據所占據的容量遠遠大于系統內存,那末,mongodb將不在內存里面進行操作(字面理解)。

 


3,備份單個collection

mongodump  --db test --collection collection

/usr/local/mongodb-linux-x86_64⑶.0.3/bin/mongodump-hlocalhost --port 30000 -d parking -c enter  -o /data/mongodb/0626/enter.csv

 

備份控制臺信息:

[mongodb@db_mongodb_1 backup]$ /usr/local/mongodb-linux-x86_64⑶.0.3/bin/mongodump -hlocalhost --port 30000 -d parking -c enter   -o /data/mongodb/0626/enter.csv

2016-06⑵6T21:57:31.408+0800    writing parking.enter to /data/mongodb/0626/enter.csv/parking/enter.bson

2016-06⑵6T21:57:33.858+0800    [........................]  parking.enter  141864/4843440  (2.9%)

2016-06⑵6T21:57:36.855+0800    [#.......................]  parking.enter  374518/4843440  (7.7%)

……………………
2016-06⑵6T21:58:21.855+0800    [#######################.]  parking.enter  4654865/4843440  (96.1%)

2016-06⑵6T21:58:23.696+0800    writing parking.enter metadata to /data/mongodb/0626/enter.csv/parking/enter.metadata.json

2016-06⑵6T21:58:23.698+0800    done dumping parking.enter

[mongodb@db_mongodb_1 backup]$

 


4,備份sharding

Mongodump可以在mongos上面進行備份,在后面添加mongos的端口就能夠了,備份所有庫命令以下:

# 創建備份目錄

mkdir /data/mongodb/backup/20160626

# 開始備份

time /usr/local/mongodb-linux-x86_64⑶.0.3/bin/mongodump --host localhost:30000   -o /data/mongodb/backup/20160626

 

 

備份是多進程的,4個進程1起備份(N核就是N個進程),控制臺顯示信息:

# 備份控制臺信息:

…..

2016-06⑵6T16:42:58.398+0800     [#.......................]           pv.mobile  3184618/62143101   (5.1%)

2016-06⑵6T16:42:58.398+0800     [#####...................]  traffice.passenger  4982012/23503868  (21.2%)

2016-06⑵6T16:42:58.398+0800     [........................]             pv.stat    108114/3739398   (2.9%)

2016-06⑵6T16:42:58.398+0800     [###.....................]       parking.leave    402109/2920264  (13.8%)

2016-06⑵6T16:42:58.398+0800    

2016-06⑵6T16:43:01.397+0800     [#.......................]           pv.mobile  3209372/62143101   (5.2%)

2016-06⑵6T16:43:01.397+0800     [#####...................]  traffice.passenger  5222668/23503868  (22.2%)

2016-06⑵6T16:43:01.397+0800     [........................]             pv.stat    124667/3739398   (3.3%)

2016-06⑵6T16:43:01.397+0800     [####....................]       parking.leave    551075/2920264  (18.9%)

2016-06⑵6T16:43:01.397+0800    

2016-06⑵6T16:43:04.396+0800     [#.......................]           pv.mobile  3218224/62143101   (5.2%)

2016-06⑵6T16:43:04.396+0800     [#####...................]  traffice.passenger  5461117/23503868  (23.2%)

2016-06⑵6T16:43:04.396+0800     [........................]             pv.stat    141247/3739398   (3.8%)

2016-06⑵6T16:43:04.396+0800     [#####...................]       parking.leave    706371/2920264  (24.2%)

……

 

 

 

備份結果統計:

# 備份完,大概40G,所花費時間大概20分鐘

[mongodb@db_mongodb_1 backup]$ du -sh 20160626

41G  20160626

[mongodb@db_mongodb_1 backup]$

 

# 然后解緊縮,大概需要20分鐘

[mongodb@db_mongodb_1 backup]$ time tar -zcvf 20160626.tar.gz 20160626

……

20160626/ibeacon/usercoord.metadata.json

20160626/ibeacon/system.indexes.bson

20160626/ibeacon/usercoord.bson

 

real  19m48.689s

user 17m33.293s

sys   1m7.212s

[mongodb@db_mongodb_1 backup]$

 

 


5,備份用戶登錄驗證

In the next example, mongodump creates a database dump located at /data/backup/mongodump⑵016-06⑵6, from a database running on port 37017 on the host mongodb1.example.net and authenticating using the username user and the password pass,as follows:

mongodump --host mongodb1.example.net --port 37017 --username user --password pass --out /data/backup/mongodump⑵016-06⑵6

 


6,緊縮備份

To compress thefiles in the output dump directory, run mongodump with the new --gzip option. For example, the following operation outputs compressedfiles into the default dump directory.

mongodump --gzip --db test

PS:此mongodb版本必須不低于3.2:

--gzip?

New in version 3.2.

Compresses the output. If mongodump outputs to the dump directory, the new feature compresses the individual files. The files have the suffix .gz.

If mongodump outputs to an archive file or the standard out stream, the new feature compresses the archive file or the data output to the stream.

 


7,設立自動備份任務

全面理解了mongodb的mongodump備份組件后,可以設置crontab任務做到每天自動備份mongodb數據,可以在shareding集群的:

# 編寫簡潔的備份腳本

[root@db_mongodb_1 ~]# more /data/mongodb/backup/full_backup.sh

 

#!/bin/sh

export DATE=`date +%F`

export BACK_DIR='/data/mongodb/backup'

su - mongodb -c "

mkdir -p $BACK_DIR/$DATE

/usr/local/mongodb-linux-x86_64⑶.0.3/bin/mongodump --host localhost:30000 -o $BACK_DIR/$DATE

tar -zcvf $BACK_DIR/$DATE.tar.gz $BACK_DIR/$DATE

"

[root@db_mongodb_1 ~]#

 

# 設置備份任務

[root@db_mongodb_1 ~]# crontab -l

1 30 * * * sh /data/mongodb/backup/full_backup.sh

[root@db_mongodb_1 ~]#

 

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 国产成人亚洲精品91专区手机 | 成年人免费在线视频观看 | 久久在精品线影院精品国产 | 久久久久18 | 午夜影院免费入口 | 国产亚洲精品久久久久91网站 | 国产欧美日韩亚洲精品区2345 | 国产啊v在线观看 | 国产亚洲精品九九久在线观看 | 免费一级毛片清高播放 | 另类图片 亚洲 校园 小说区 | 黄色一级a毛片 | 日本一区二区视频免费播放 | 亚洲精品久久久久久久无 | 最近的最新的中文字幕视频 | 久久精品视频国产 | 好吊色永久免费视频大全 | 综合欧美一区二区三区 | 亚洲另类春色 | 亚洲国产欧美在线人成 | 香蕉久久夜色精品国产2020 | 亚洲精品国产自在久久老牛 | 青青草原国产在线视频 | 日本乱人伦片中文三区 | 日韩一区二区精品久久高清 | 校园春色 中文字幕 | 国产三级在线观看视频 | 噜噜片 | 欧美日韩亚洲天堂 | 一区二区三区在线免费看 | 欧美另类hd | 国产福利不卡 | 爱爱的免费视频 | 成年人性生活免费视频 | 日本天堂网址 | 中文字幕日韩精品一区口 | 免费操人视频 | 欧美巨大精品欧美一区二区 | 国产xxx护士爽免费看 | 国产人成精品免费视频 | 欧美操老逼 |