日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

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

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

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

 

1,mongodb所有組件

官方文檔地址: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 ~]#

 

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 欧美精品一区二区三区在线四季 | 夜夜爽爽爽久久久久久魔女 | 久久亚洲春色中文字幕久久久 | 黄色三级在线观看 | 九九热在线播放 | 欧美 中文字幕 | 18av在线视频 | 日韩欧美电影在线观看 | 欧美精品一区二区三区蜜桃视频 | 日韩成人一区二区 | 国产精品成人3p一区二区三区 | 亚洲欧美一区二区三区 | 嫩草在线免费观看 | 欧美精品一区二区三区在线 | 91久久久久久久一区二区 | 精品一区二区三区不卡 | 国产一区免费在线观看 | 亚洲成人毛片 | 色图综合 | 2015成人永久免费视频 | 欧美黄绝片 | 免费一级毛片电影 | 免费国产视频在线观看 | 午夜一二区 | 最近更新2019中文在线视频 | 亚洲最大av网 | 亚洲精品一二 | 特黄aaaaaaaaa真人毛片 | 国产福利91精品一区二区三区 | 成人国产在线视频 | 在线播放日韩 | 亚洲午夜精品视频 | 亚洲视频国产 | 黄网免费在线观看 | 久久尤物视频 | 久久精品成人 | 亚洲毛茸茸少妇高潮呻吟 | 精品一区二区三区在线视频 | 亚洲一区二区三区四区精品 | 亚洲成人精品一区二区三区 | 久久久久久中文字幕 |