Elasticseach目前作為查詢搜索平台,的確非常實用方便。我們今天在這里要討論的是如何做數據備份和type刪除。我的ES的版本是2.4.1。
ES的備份,可不像MySQL的mysqldump這么方便,需要一個插件進行數據的導出和導入進行備份和恢復操作。這里要說的插件是elasticdump。
elasticdump的安裝:
[root@localhost ~]# yum install elasticdump 已加載插件:fastestmirror, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast base | 3.6 kB 00:00:00 cuda | 2.5 kB 00:00:00 epel/x86_64/metalink | 5.0 kB 00:00:00 epel | 4.3 kB 00:00:00 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 (1/8): base/x86_64/primary_db | 5.7 MB 00:00:00 (2/8): epel/x86_64/group_gz | 170 kB 00:00:00 (3/8): epel/x86_64/updateinfo | 830 kB 00:00:00 (4/8): extras/x86_64/primary_db | 102 kB 00:00:00 (5/8): base/x86_64/group_gz | 156 kB 00:00:01 (6/8): updates/x86_64/primary_db | 2.8 MB 00:00:00 (7/8): epel/x86_64/primary_db | 4.8 MB 00:00:01 cuda/primary_db FAILED http://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/repodata/1d4cabb230a45d5f78f46ccd1b04914a98eab1b3-primary.sqlite.bz2: [Errno 12] Timeout on http://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/repodata/1d4cabb230a45d5f78f46ccd1b04914a98eab1b3-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds') 正在嘗試其它鏡像。 cuda/primary_db FAILED http://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/repodata/1d4cabb230a45d5f78f46ccd1b04914a98eab1b3-primary.sqlite.bz2: [Errno 14] curl#52 - "Empty reply from server"0 ETA 正在嘗試其它鏡像。 Determining fastest mirrors * epel: mirrors.tuna.tsinghua.edu.cn 正在解決依賴關系 --> 正在檢查事務 ---> 軟件包 elasticdump.noarch.0.2.2.0-2.el7 將被 安裝 --> 正在處理依賴關系 npm(request) < 3,它被軟件包 elasticdump-2.2.0-2.el7.noarch 需要 --> 正在處理依賴關系 npm(async) < 2,它被軟件包 elasticdump-2.2.0-2.el7.noarch 需要 --> 正在處理依賴關系 npm(request) >= 2,它被軟件包 elasticdump-2.2.0-2.el7.noarch 需要 --> 正在處理依賴關系 nodejs(engine) >= 1.0.0,它被軟件包 elasticdump-2.2.0-2.el7.noarch 需要 --> 正在處理依賴關系 npm(optimist),它被軟件包 elasticdump-2.2.0-2.el7.noarch 需要 --> 正在處理依賴關系 npm(JSONStream),它被軟件包 elasticdump-2.2.0-2.el7.noarch 需要 --> 正在處理依賴關系 /usr/bin/node,它被軟件包 elasticdump-2.2.0-2.el7.noarch 需要 --> 正在檢查事務 ---> 軟件包 nodejs.x86_64.1.6.11.1-1.el7 將被 安裝 --> 正在處理依賴關系 npm = 1:3.10.10-1.6.11.1.1.el7,它被軟件包 1:nodejs-6.11.1-1.el7.x86_64 需要 --> 正在處理依賴關系 libuv >= 1:1.9.1,它被軟件包 1:nodejs-6.11.1-1.el7.x86_64 需要 --> 正在處理依賴關系 http-parser >= 2.7.0,它被軟件包 1:nodejs-6.11.1-1.el7.x86_64 需要 --> 正在處理依賴關系 libuv.so.1()(64bit),它被軟件包 1:nodejs-6.11.1-1.el7.x86_64 需要 --> 正在處理依賴關系 libhttp_parser.so.2()(64bit),它被軟件包 1:nodejs-6.11.1-1.el7.x86_64 需要 ---> 軟件包 nodejs-async.noarch.0.0.2.10-1.el7 將被 安裝 ---> 軟件包 nodejs-jsonstream.noarch.0.0.10.0-2.el7 將被 安裝 --> 正在處理依賴關系 npm(through),它被軟件包 nodejs-jsonstream-0.10.0-2.el7.noarch 需要 --> 正在處理依賴關系 npm(jsonparse),它被軟件包 nodejs-jsonstream-0.10.0-2.el7.noarch 需要 ---> 軟件包 nodejs-optimist.noarch.0.0.4.0-1.el7 將被 安裝 --> 正在處理依賴關系 npm(wordwrap) < 0.1,它被軟件包 nodejs-optimist-0.4.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(wordwrap) >= 0.0.2,它被軟件包 nodejs-optimist-0.4.0-1.el7.noarch 需要 ---> 軟件包 nodejs-request.noarch.0.2.25.0-1.el7 將被 安裝 --> 正在處理依賴關系 npm(tunnel-agent) < 0.4,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(qs) < 0.7,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(oauth-sign) < 0.4,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(node-uuid) < 1.5,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(mime) < 1.3,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(json-stringify-safe) < 5.1,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(http-signature) < 0.11,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(hawk) < 1.1,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(form-data) < 0.2,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(forever-agent) < 0.6,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(cookie-jar) < 0.4,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(aws-sign) < 0.4,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(tunnel-agent) >= 0.3.0,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(qs) >= 0.6.0,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(oauth-sign) >= 0.3.0,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(node-uuid) >= 1.4.0,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(mime) >= 1.2.9,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(json-stringify-safe) >= 5.0.0,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(http-signature) >= 0.10.0,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(hawk) >= 1.0.0,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(form-data) >= 0.1.0,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(forever-agent) >= 0.5.0,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(cookie-jar) >= 0.3.0,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(aws-sign) >= 0.3.0,它被軟件包 nodejs-request-2.25.0-1.el7.noarch 需要 --> 正在檢查事務 ---> 軟件包 http-parser.x86_64.0.2.7.1-5.el7_4 將被 安裝 ---> 軟件包 libuv.x86_64.1.1.10.2-1.el7 將被 安裝 ---> 軟件包 nodejs-aws-sign.noarch.0.0.3.0-1.el7 將被 安裝 ---> 軟件包 nodejs-cookie-jar.noarch.1.0.3.0-1.el7 將被 安裝 ---> 軟件包 nodejs-forever-agent.noarch.0.0.5.0-1.el7 將被 安裝 ---> 軟件包 nodejs-form-data.noarch.0.0.1.1-1.el7 將被 安裝 --> 正在處理依賴關系 npm(combined-stream) < 0.1,它被軟件包 nodejs-form-data-0.1.1-1.el7.noarch 需要 --> 正在處理依賴關系 npm(combined-stream) >= 0.0.4,它被軟件包 nodejs-form-data-0.1.1-1.el7.noarch 需要 ---> 軟件包 nodejs-hawk.noarch.0.1.0.0-1.el7 將被 安裝 --> 正在處理依賴關系 npm(sntp) < 0.3,它被軟件包 nodejs-hawk-1.0.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(hoek) < 0.10,它被軟件包 nodejs-hawk-1.0.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(cryptiles) < 0.3,它被軟件包 nodejs-hawk-1.0.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(boom) < 0.5,它被軟件包 nodejs-hawk-1.0.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(sntp) >= 0.2,它被軟件包 nodejs-hawk-1.0.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(hoek) >= 0.9,它被軟件包 nodejs-hawk-1.0.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(cryptiles) >= 0.2,它被軟件包 nodejs-hawk-1.0.0-1.el7.noarch 需要 --> 正在處理依賴關系 npm(boom) >= 0.4,它被軟件包 nodejs-hawk-1.0.0-1.el7.noarch 需要 ---> 軟件包 nodejs-http-signature.noarch.0.0.10.0-3.el7 將被 安裝 --> 正在處理依賴關系 npm(ctype) < 0.6,它被軟件包 nodejs-http-signature-0.10.0-3.el7.noarch 需要 --> 正在處理依賴關系 npm(assert-plus) < 0.2,它被軟件包 nodejs-http-signature-0.10.0-3.el7.noarch 需要 --> 正在處理依賴關系 npm(asn1) < 0.2,它被軟件包 nodejs-http-signature-0.10.0-3.el7.noarch 需要 --> 正在處理依賴關系 npm(ctype) >= 0.5.3,它被軟件包 nodejs-http-signature-0.10.0-3.el7.noarch 需要 --> 正在處理依賴關系 npm(assert-plus) >= 0.1.2,它被軟件包 nodejs-http-signature-0.10.0-3.el7.noarch 需要 --> 正在處理依賴關系 npm(asn1) >= 0.1.11,它被軟件包 nodejs-http-signature-0.10.0-3.el7.noarch 需要 ---> 軟件包 nodejs-json-stringify-safe.noarch.0.5.0.0-1.el7 將被 安裝 ---> 軟件包 nodejs-jsonparse.noarch.0.1.0.0-2.el7 將被 安裝 ---> 軟件包 nodejs-mime.noarch.0.1.2.11-1.el7 將被 安裝 ---> 軟件包 nodejs-node-uuid.noarch.0.1.4.1-1.el7 將被 安裝 ---> 軟件包 nodejs-oauth-sign.noarch.0.0.3.0-1.el7 將被 安裝 ---> 軟件包 nodejs-qs.noarch.0.0.6.6-3.el7 將被 安裝 ---> 軟件包 nodejs-through.noarch.0.2.3.4-2.el7 將被 安裝 ---> 軟件包 nodejs-tunnel-agent.noarch.0.0.3.0-1.el7 將被 安裝 ---> 軟件包 nodejs-wordwrap.noarch.0.0.0.2-4.el7 將被 安裝 ---> 軟件包 npm.x86_64.1.3.10.10-1.6.11.1.1.el7 將被 安裝 --> 正在檢查事務 ---> 軟件包 nodejs-asn1.noarch.0.0.1.11-3.el7 將被 安裝 ---> 軟件包 nodejs-assert-plus.noarch.0.0.1.4-1.el7 將被 安裝 ---> 軟件包 nodejs-boom.noarch.0.0.4.2-2.el7 將被 安裝 ---> 軟件包 nodejs-combined-stream.noarch.0.0.0.4-3.el7 將被 安裝 --> 正在處理依賴關系 npm(delayed-stream) = 0.0.5,它被軟件包 nodejs-combined-stream-0.0.4-3.el7.noarch 需要 ---> 軟件包 nodejs-cryptiles.noarch.0.0.2.2-1.el7 將被 安裝 ---> 軟件包 nodejs-ctype.noarch.0.0.5.3-3.el7 將被 安裝 ---> 軟件包 nodejs-hoek.noarch.0.0.9.1-1.el7 將被 安裝 ---> 軟件包 nodejs-sntp.noarch.0.0.2.4-1.el7 將被 安裝 --> 正在檢查事務 ---> 軟件包 nodejs-delayed-stream.noarch.0.0.0.5-5.el7 將被 安裝 --> 解決依賴關系完成 依賴關系解決 =============================================================================================================================================================================================== Package 架構 版本 源 大小 =============================================================================================================================================================================================== 正在安裝: elasticdump noarch 2.2.0-2.el7 epel 26 k 為依賴而安裝: http-parser x86_64 2.7.1-5.el7_4 updates 28 k libuv x86_64 1:1.10.2-1.el7 epel 109 k nodejs x86_64 1:6.11.1-1.el7 epel 4.5 M nodejs-asn1 noarch 0.1.11-3.el7 epel 11 k nodejs-assert-plus noarch 0.1.4-1.el7 epel 7.3 k nodejs-async noarch 0.2.10-1.el7 epel 21 k nodejs-aws-sign noarch 0.3.0-1.el7 epel 5.7 k nodejs-boom noarch 0.4.2-2.el7 epel 37 k nodejs-combined-stream noarch 0.0.4-3.el7 epel 7.9 k nodejs-cookie-jar noarch 1:0.3.0-1.el7 epel 6.1 k nodejs-cryptiles noarch 0.2.2-1.el7 epel 6.9 k nodejs-ctype noarch 0.5.3-3.el7 epel 31 k nodejs-delayed-stream noarch 0.0.5-5.el7 epel 7.9 k nodejs-forever-agent noarch 0.5.0-1.el7 epel 5.6 k nodejs-form-data noarch 0.1.1-1.el7 epel 11 k nodejs-hawk noarch 1.0.0-1.el7 epel 105 k nodejs-hoek noarch 0.9.1-1.el7 epel 51 k nodejs-http-signature noarch 0.10.0-3.el7 epel 17 k nodejs-json-stringify-safe noarch 5.0.0-1.el7 epel 6.6 k nodejs-jsonparse noarch 1.0.0-2.el7 epel 10 k nodejs-jsonstream noarch 0.10.0-2.el7 epel 9.5 k nodejs-mime noarch 1.2.11-1.el7 epel 22 k nodejs-node-uuid noarch 1.4.1-1.el7 epel 10 k nodejs-oauth-sign noarch 0.3.0-1.el7 epel 4.9 k nodejs-optimist noarch 0.4.0-1.el7 epel 15 k nodejs-qs noarch 0.6.6-3.el7 epel 8.7 k nodejs-request noarch 2.25.0-1.el7 epel 27 k nodejs-sntp noarch 0.2.4-1.el7 epel 10 k nodejs-through noarch 2.3.4-2.el7 epel 7.1 k nodejs-tunnel-agent noarch 0.3.0-1.el7 epel 6.3 k nodejs-wordwrap noarch 0.0.2-4.el7 epel 6.4 k npm x86_64 1:3.10.10-1.6.11.1.1.el7 epel 2.5 M 事務概要 =============================================================================================================================================================================================== 安裝 1 軟件包 (+32 依賴軟件包) 總下載量:7.7 M 安裝大小:26 M Is this ok [y/d/N]: y Downloading packages: (1/33): http-parser-2.7.1-5.el7_4.x86_64.rpm | 28 kB 00:00:00 (2/33): elasticdump-2.2.0-2.el7.noarch.rpm | 26 kB 00:00:00 (3/33): libuv-1.10.2-1.el7.x86_64.rpm | 109 kB 00:00:00 (4/33): nodejs-6.11.1-1.el7.x86_64.rpm | 4.5 MB 00:00:00 (5/33): nodejs-asn1-0.1.11-3.el7.noarch.rpm | 11 kB 00:00:00 (6/33): nodejs-assert-plus-0.1.4-1.el7.noarch.rpm | 7.3 kB 00:00:00 (7/33): nodejs-async-0.2.10-1.el7.noarch.rpm | 21 kB 00:00:00 (8/33): nodejs-aws-sign-0.3.0-1.el7.noarch.rpm | 5.7 kB 00:00:00 (9/33): nodejs-boom-0.4.2-2.el7.noarch.rpm | 37 kB 00:00:00 (10/33): nodejs-combined-stream-0.0.4-3.el7.noarch.rpm | 7.9 kB 00:00:00 (11/33): nodejs-cookie-jar-0.3.0-1.el7.noarch.rpm | 6.1 kB 00:00:00 (12/33): nodejs-cryptiles-0.2.2-1.el7.noarch.rpm | 6.9 kB 00:00:00 (13/33): nodejs-ctype-0.5.3-3.el7.noarch.rpm | 31 kB 00:00:00 (14/33): nodejs-delayed-stream-0.0.5-5.el7.noarch.rpm | 7.9 kB 00:00:00 (15/33): nodejs-forever-agent-0.5.0-1.el7.noarch.rpm | 5.6 kB 00:00:00 (16/33): nodejs-form-data-0.1.1-1.el7.noarch.rpm | 11 kB 00:00:00 (17/33): nodejs-hawk-1.0.0-1.el7.noarch.rpm | 105 kB 00:00:00 (18/33): nodejs-hoek-0.9.1-1.el7.noarch.rpm | 51 kB 00:00:00 (19/33): nodejs-http-signature-0.10.0-3.el7.noarch.rpm | 17 kB 00:00:00 (20/33): nodejs-json-stringify-safe-5.0.0-1.el7.noarch.rpm | 6.6 kB 00:00:00 (21/33): nodejs-jsonparse-1.0.0-2.el7.noarch.rpm | 10 kB 00:00:00 (22/33): nodejs-jsonstream-0.10.0-2.el7.noarch.rpm | 9.5 kB 00:00:00 (23/33): nodejs-mime-1.2.11-1.el7.noarch.rpm | 22 kB 00:00:00 (24/33): nodejs-node-uuid-1.4.1-1.el7.noarch.rpm | 10 kB 00:00:00 (25/33): nodejs-oauth-sign-0.3.0-1.el7.noarch.rpm | 4.9 kB 00:00:00 (26/33): nodejs-optimist-0.4.0-1.el7.noarch.rpm | 15 kB 00:00:00 (27/33): nodejs-qs-0.6.6-3.el7.noarch.rpm | 8.7 kB 00:00:00 (28/33): nodejs-request-2.25.0-1.el7.noarch.rpm | 27 kB 00:00:00 (29/33): nodejs-sntp-0.2.4-1.el7.noarch.rpm | 10 kB 00:00:00 (30/33): nodejs-through-2.3.4-2.el7.noarch.rpm | 7.1 kB 00:00:00 (31/33): nodejs-tunnel-agent-0.3.0-1.el7.noarch.rpm | 6.3 kB 00:00:00 (32/33): nodejs-wordwrap-0.0.2-4.el7.noarch.rpm | 6.4 kB 00:00:00 (33/33): npm-3.10.10-1.6.11.1.1.el7.x86_64.rpm | 2.5 MB 00:00:00 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 總計 2.0 MB/s | 7.7 MB 00:00:03 Running transaction check Running transaction test Transaction test succeeded Running transaction 警告:RPM 數據庫已被非 yum 程序修改。 ** 發現 1 個已存在的 RPM 數據庫問題, 'yum check' 輸出如下: rhn-check-2.0.2-6.el7.noarch 有缺少的需求 yum-rhn-plugin >= ('0', '1.6.4', '1') 正在安裝 : 1:libuv-1.10.2-1.el7.x86_64 1/33 正在安裝 : http-parser-2.7.1-5.el7_4.x86_64 2/33 正在安裝 : 1:npm-3.10.10-1.6.11.1.1.el7.x86_64 3/33 正在安裝 : 1:nodejs-6.11.1-1.el7.x86_64 4/33 正在安裝 : nodejs-hoek-0.9.1-1.el7.noarch 5/33 正在安裝 : nodejs-boom-0.4.2-2.el7.noarch 6/33 正在安裝 : nodejs-mime-1.2.11-1.el7.noarch 7/33 正在安裝 : nodejs-async-0.2.10-1.el7.noarch 8/33 正在安裝 : nodejs-cryptiles-0.2.2-1.el7.noarch 9/33 正在安裝 : nodejs-sntp-0.2.4-1.el7.noarch 10/33 正在安裝 : nodejs-hawk-1.0.0-1.el7.noarch 11/33 正在安裝 : nodejs-forever-agent-0.5.0-1.el7.noarch 12/33 正在安裝 : nodejs-aws-sign-0.3.0-1.el7.noarch 13/33 正在安裝 : nodejs-qs-0.6.6-3.el7.noarch 14/33 正在安裝 : nodejs-wordwrap-0.0.2-4.el7.noarch 15/33 正在安裝 : nodejs-optimist-0.4.0-1.el7.noarch 16/33 正在安裝 : nodejs-assert-plus-0.1.4-1.el7.noarch 17/33 正在安裝 : nodejs-oauth-sign-0.3.0-1.el7.noarch 18/33 正在安裝 : nodejs-tunnel-agent-0.3.0-1.el7.noarch 19/33 正在安裝 : nodejs-asn1-0.1.11-3.el7.noarch 20/33 正在安裝 : nodejs-delayed-stream-0.0.5-5.el7.noarch 21/33 正在安裝 : nodejs-combined-stream-0.0.4-3.el7.noarch 22/33 正在安裝 : nodejs-form-data-0.1.1-1.el7.noarch 23/33 正在安裝 : 1:nodejs-cookie-jar-0.3.0-1.el7.noarch 24/33 正在安裝 : nodejs-jsonparse-1.0.0-2.el7.noarch 25/33 正在安裝 : nodejs-through-2.3.4-2.el7.noarch 26/33 正在安裝 : nodejs-jsonstream-0.10.0-2.el7.noarch 27/33 正在安裝 : nodejs-node-uuid-1.4.1-1.el7.noarch 28/33 正在安裝 : nodejs-ctype-0.5.3-3.el7.noarch 29/33 正在安裝 : nodejs-http-signature-0.10.0-3.el7.noarch 30/33 正在安裝 : nodejs-json-stringify-safe-5.0.0-1.el7.noarch 31/33 正在安裝 : nodejs-request-2.25.0-1.el7.noarch 32/33 正在安裝 : elasticdump-2.2.0-2.el7.noarch 33/33 驗證中 : elasticdump-2.2.0-2.el7.noarch 1/33 驗證中 : nodejs-forever-agent-0.5.0-1.el7.noarch 2/33 驗證中 : nodejs-aws-sign-0.3.0-1.el7.noarch 3/33 驗證中 : nodejs-qs-0.6.6-3.el7.noarch 4/33 驗證中 : http-parser-2.7.1-5.el7_4.x86_64 5/33 驗證中 : nodejs-combined-stream-0.0.4-3.el7.noarch 6/33 驗證中 : nodejs-wordwrap-0.0.2-4.el7.noarch 7/33 驗證中 : nodejs-assert-plus-0.1.4-1.el7.noarch 8/33 驗證中 : nodejs-oauth-sign-0.3.0-1.el7.noarch 9/33 驗證中 : nodejs-hoek-0.9.1-1.el7.noarch 10/33 驗證中 : nodejs-cryptiles-0.2.2-1.el7.noarch 11/33 驗證中 : nodejs-jsonstream-0.10.0-2.el7.noarch 12/33 驗證中 : nodejs-request-2.25.0-1.el7.noarch 13/33 驗證中 : nodejs-http-signature-0.10.0-3.el7.noarch 14/33 驗證中 : 1:libuv-1.10.2-1.el7.x86_64 15/33 驗證中 : nodejs-tunnel-agent-0.3.0-1.el7.noarch 16/33 驗證中 : nodejs-mime-1.2.11-1.el7.noarch 17/33 驗證中 : nodejs-hawk-1.0.0-1.el7.noarch 18/33 驗證中 : nodejs-asn1-0.1.11-3.el7.noarch 19/33 驗證中 : nodejs-delayed-stream-0.0.5-5.el7.noarch 20/33 驗證中 : 1:npm-3.10.10-1.6.11.1.1.el7.x86_64 21/33 驗證中 : nodejs-optimist-0.4.0-1.el7.noarch 22/33 驗證中 : nodejs-sntp-0.2.4-1.el7.noarch 23/33 驗證中 : nodejs-form-data-0.1.1-1.el7.noarch 24/33 驗證中 : 1:nodejs-cookie-jar-0.3.0-1.el7.noarch 25/33 驗證中 : nodejs-boom-0.4.2-2.el7.noarch 26/33 驗證中 : 1:nodejs-6.11.1-1.el7.x86_64 27/33 驗證中 : nodejs-jsonparse-1.0.0-2.el7.noarch 28/33 驗證中 : nodejs-through-2.3.4-2.el7.noarch 29/33 驗證中 : nodejs-node-uuid-1.4.1-1.el7.noarch 30/33 驗證中 : nodejs-ctype-0.5.3-3.el7.noarch 31/33 驗證中 : nodejs-async-0.2.10-1.el7.noarch 32/33 驗證中 : nodejs-json-stringify-safe-5.0.0-1.el7.noarch 33/33 已安裝: elasticdump.noarch 0:2.2.0-2.el7 作為依賴被安裝: http-parser.x86_64 0:2.7.1-5.el7_4 libuv.x86_64 1:1.10.2-1.el7 nodejs.x86_64 1:6.11.1-1.el7 nodejs-asn1.noarch 0:0.1.11-3.el7 nodejs-assert-plus.noarch 0:0.1.4-1.el7 nodejs-async.noarch 0:0.2.10-1.el7 nodejs-aws-sign.noarch 0:0.3.0-1.el7 nodejs-boom.noarch 0:0.4.2-2.el7 nodejs-combined-stream.noarch 0:0.0.4-3.el7 nodejs-cookie-jar.noarch 1:0.3.0-1.el7 nodejs-cryptiles.noarch 0:0.2.2-1.el7 nodejs-ctype.noarch 0:0.5.3-3.el7 nodejs-delayed-stream.noarch 0:0.0.5-5.el7 nodejs-forever-agent.noarch 0:0.5.0-1.el7 nodejs-form-data.noarch 0:0.1.1-1.el7 nodejs-hawk.noarch 0:1.0.0-1.el7 nodejs-hoek.noarch 0:0.9.1-1.el7 nodejs-http-signature.noarch 0:0.10.0-3.el7 nodejs-json-stringify-safe.noarch 0:5.0.0-1.el7 nodejs-jsonparse.noarch 0:1.0.0-2.el7 nodejs-jsonstream.noarch 0:0.10.0-2.el7 nodejs-mime.noarch 0:1.2.11-1.el7 nodejs-node-uuid.noarch 0:1.4.1-1.el7 nodejs-oauth-sign.noarch 0:0.3.0-1.el7 nodejs-optimist.noarch 0:0.4.0-1.el7 nodejs-qs.noarch 0:0.6.6-3.el7 nodejs-request.noarch 0:2.25.0-1.el7 nodejs-sntp.noarch 0:0.2.4-1.el7 nodejs-through.noarch 0:2.3.4-2.el7 nodejs-tunnel-agent.noarch 0:0.3.0-1.el7 nodejs-wordwrap.noarch 0:0.0.2-4.el7 npm.x86_64 1:3.10.10-1.6.11.1.1.el7 完畢! [root@localhost ~]#
elasticdump相關功能描述:
[root@localhost ~]# elasticdump --help elasticdump: Import and export tools for elasticsearch version: 2.2.0 Usage: elasticdump --input SOURCE --output DESTINATION [OPTIONS] --input Source location (required) --input-index Source index and type (default: all, example: index/type) --output Destination location (required) --output-index Destination index and type (default: all, example: index/type) --limit How many objects to move in batch per operation limit is approximate for file streams (default: 100) --debug Display the elasticsearch commands being used (default: false) --type What are we exporting? (default: data, options: [data, mapping]) --delete Delete documents one-by-one from the input as they are moved. Will not delete the source index (default: false) --searchBody Preform a partial extract based on search results (when ES is the input, (default: '{"query": { "match_all": {} } }')) --sourceOnly Output only the json contained within the document _source Normal: {"_index":"","_type":"","_id":"", "_source":{SOURCE}} sourceOnly: {SOURCE} (default: false) --all Load/store documents from ALL indexes (default: false) --ignore-errors Will continue the read/write loop on write error (default: false) --scrollTime Time the nodes will hold the requested search in order. (default: 10m) --maxSockets How many simultaneous HTTP requests can we process make? (default: 5 [node <= v0.10.x] / Infinity [node >= v0.11.x] ) --timeout Integer containing the number of milliseconds to wait for a request to respond before aborting the request. Passed directly to the request library. Mostly used when you don't care too much if you lose some data when importing but rather have speed. --offset Integer containing the number of rows you wish to skip ahead from the input transport. When importing a large index, things can go wrong, be it connectivity, crashes, someone forgetting to `screen`, etc. This allows you to start the dump again from the last known line written (as logged by the `offset` in the output). Please be advised that since no sorting is specified when the dump is initially created, there's no real way to guarantee that the skipped rows have already been written/parsed. This is more of an option for when you want to get most data as possible in the index without concern for losing some rows in the process, similar to the `timeout` option. --inputTransport Provide a custom js file to us as the input transport --outputTransport Provide a custom js file to us as the output transport --toLog When using a custom outputTransport, should log lines be appended to the output stream? (default: true, except for `$`) --help This page Examples: # Copy an index from production to staging with mappings: elasticdump \ --input=http://production.es.com:9200/my_index \ --output=http://staging.es.com:9200/my_index \ --type=mapping elasticdump \ --input=http://production.es.com:9200/my_index \ --output=http://staging.es.com:9200/my_index \ --type=data # Backup index data to a file: elasticdump \ --input=http://production.es.com:9200/my_index \ --output=/data/my_index_mapping.json \ --type=mapping elasticdump \ --input=http://production.es.com:9200/my_index \ --output=/data/my_index.json \ --type=data # Backup and index to a gzip using stdout: elasticdump \ --input=http://production.es.com:9200/my_index \ --output=$ \ | gzip > /data/my_index.json.gz # Backup the results of a query to a file elasticdump \ --input=http://production.es.com:9200/my_index \ --output=query.json \ --searchBody '{"query":{"term":{"username": "admin"}}}' ------------------------------------------------------------------------------ Learn more @ https://github.com/taskrabbit/elasticsearch-dump [root@localhost ~]#
重點說明:
依據上述的幫助文件,我們重點看elasticdump --input SOURCE --output DESTINATION
這里的source和destination可以是es的數據源,也可以是文件。也就是說,這個命令elasticdump既可以完成數據的導出,也可以完成數據的導入。
當表示es的數據源時,必須是{protocol}://{host}:{port}/{index}.
1. 將es集群中的某個index的數據導出到文件中。
[root@localhost ~]# elasticdump --input http://10.90.7.10:9200/robotkdb --output /opt/shihuc/robotkdb.json Thu, 21 Sep 2017 07:04:37 GMT | starting dump Thu, 21 Sep 2017 07:04:37 GMT | got 100 objects from source elasticsearch (offset: 0) Thu, 21 Sep 2017 07:04:37 GMT | sent 100 objects to destination file, wrote 100 Thu, 21 Sep 2017 07:04:37 GMT | got 100 objects from source elasticsearch (offset: 100) Thu, 21 Sep 2017 07:04:37 GMT | sent 100 objects to destination file, wrote 100 Thu, 21 Sep 2017 07:04:37 GMT | got 8 objects from source elasticsearch (offset: 200) Thu, 21 Sep 2017 07:04:37 GMT | sent 8 objects to destination file, wrote 8 Thu, 21 Sep 2017 07:04:37 GMT | got 0 objects from source elasticsearch (offset: 208) Thu, 21 Sep 2017 07:04:37 GMT | Total Writes: 208 Thu, 21 Sep 2017 07:04:37 GMT | dump complete [root@localhost ~]#
2.直接刪除指定的type下的內容
[root@localhost ~]# curl -XDELETE "http://10.90.7.10:9200/robotkdb/weibao?v" No handler found for uri [/robotkdb/weibao?v] and method [DELETE][root@localhost ~]#
刪除不成功。
查詢資料顯示說,ES2.x版本以上的系統中,禁止了直接刪除type。
那我要快速刪除一個type的內容,該如何處理呢?其實是有的,安裝delete-by-query的插件進行。安裝完成后,將Elasticsearch重啟一下。
[root@localhost bin]# ll 總用量 324 -rwxr-xr-x 1 es es 5551 8月 23 2016 elasticsearch -rw-rw-r-- 1 es es 909 8月 23 2016 elasticsearch.bat -rw-rw-r-- 1 es es 3351 9月 23 2016 elasticsearch.in.bat -rwxr-xr-x 1 es es 2814 8月 23 2016 elasticsearch.in.sh -rw-rw-r-- 1 es es 104448 7月 26 2016 elasticsearch-service-mgr.exe -rw-rw-r-- 1 es es 103936 7月 26 2016 elasticsearch-service-x64.exe -rw-rw-r-- 1 es es 80896 7月 26 2016 elasticsearch-service-x86.exe -rwxr-xr-x 1 es es 2992 8月 23 2016 plugin -rw-rw-r-- 1 es es 1303 8月 23 2016 plugin.bat -rw-rw-r-- 1 es es 6872 8月 23 2016 service.bat [root@localhost bin]# ./plugin install delete-by-query #注意,要到elasticsearch的安裝路徑下的bin下面執行這個命令 -> Installing delete-by-query... Trying https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/delete-by-query/2.4.1/delete-by-query-2.4.1.zip ... Downloading ..DONE Verifying https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/delete-by-query/2.4.1/delete-by-query-2.4.1.zip checksums if available ... Downloading .DONE Installed delete-by-query into /opt/ES/elasticsearch-2.4.1/plugins/delete-by-query [root@localhost bin]#
重啟elasticsearch的過程,就不描述了。然后再用命令執行刪除指定的type的數據:
[root@localhost ES]# curl -XDELETE "http://10.90.7.10:9200/robotkdb/weibao/_query?pretty" -d '{ "query":{ "match_all":{} }}' { "took" : 0, "timed_out" : false, "_indices" : { "_all" : { "found" : 208, "deleted" : 208, "missing" : 0, "failed" : 0 }, "robotkdb" : { "found" : 208, "deleted" : 208, "missing" : 0, "failed" : 0 } }, "failures" : [ ] } [root@localhost ES]#
從上述結果看,沒有錯誤。那么,再去查看下,weibao這個type下,還有沒有數據!
[root@localhost ES]# curl -XGET "http://10.90.7.10:9200/robotkdb/weibao/_search?pretty" { "took" : 3, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 0, "max_score" : null, "hits" : [ ] } }
說明刪除指定type的內容成功了。
3. elasticdump數據恢復
那最后再來恢復下剛才刪除掉的208個記錄吧。前面不是備份了一個數據嗎,在這個文件里面/opt/shihuc/robotkdb.json
[root@localhost shihuc]# elasticdump --input /opt/shihuc/robotkdb.json --output "http://10.90.7.10:9200/robotkdb" Thu, 21 Sep 2017 07:16:03 GMT | starting dump Thu, 21 Sep 2017 07:16:03 GMT | got 100 objects from source file (offset: 0) Thu, 21 Sep 2017 07:16:04 GMT | sent 100 objects to destination elasticsearch, wrote 100 Thu, 21 Sep 2017 07:16:04 GMT | got 108 objects from source file (offset: 100) Thu, 21 Sep 2017 07:16:04 GMT | sent 108 objects to destination elasticsearch, wrote 108 Thu, 21 Sep 2017 07:16:04 GMT | got 0 objects from source file (offset: 208) Thu, 21 Sep 2017 07:16:04 GMT | Total Writes: 208 Thu, 21 Sep 2017 07:16:04 GMT | dump complete
最后在瀏覽器上訪問看看吧,驗證數據載入、恢復是否成功!

Elasticsearch的數據備份,刪除以及恢復邏輯,到此驗證完畢!
總結:
1. Elasticsearch的2.x以上版本不支持直接刪除type級別的數據。支持刪除index,也支持逐個id的刪除。
2. Elasticsearch的數據備份和恢復,沒有直接的指令操作,需要安裝插件elasticdump來實現。
