python_note
  • Introduction
  • My Python
    • Anaconda
    • argparse
    • datetime
    • json
    • logging
    • numpy
    • open
    • openCC
    • pandas & csv
    • Socket & SocketServer
    • re
    • yaml
    • smtp
    • 物件操作
    • unittest
    • 線程
    • prettytable
    • IO
    • pycurl
    • sys
    • pickle
    • auto-python-to-exe
    • cython
    • nuitka
  • Crawler
    • Urllib & Requests
      • User-agent
      • Percent-Encoding
      • mail code
    • Selenium
    • TCP & UDP
    • 控制字符(control character)
  • Web Development
    • Flask
      • RESTful api
      • Template
      • blueprint
    • Django
      • 環境佈署(windows)
    • 檢查Port
    • Apache
    • 使用者行為
    • jQuery
    • 壓力測試
    • DataTable
    • Bootstrap
    • CSS
    • JavaScript
    • Chart.js
  • Deep Learning
    • Keras 設定
    • RNN
    • LSTM
  • Test
    • T-Test
  • 資料結構
    • Hash
    • 時間複雜度
  • NLP
    • N-gram
    • CKIP
    • 中文轉數字
    • CRF
    • Mutual Information
    • 模糊比對
  • Linebot
    • Heroku
    • 圖文選單
    • channel
  • Linux
    • 常用指令
    • shell script
    • sshfs
    • ssh
    • nodejs & npm
    • debug
  • GCP
    • app engine
    • ssh(gcp)
    • gsutil
    • brabrabra
    • Load Balancer
    • k8s
  • Database
    • mysql
    • elasticsearch
      • Query
      • Backup and Restore
      • elasticdump
      • es2csv
      • ELK
    • mongodb
      • install
      • authentication
      • pymongo
    • sql server
  • go
    • Swarm
  • Docker
    • Kitematic
    • Dockerfile
    • Swarm
  • Git
  • 其他
    • USB軟體保護
    • Windows效能監視器
  • Blockchain
Powered by GitBook
On this page
  • 備份與還原
  • 資料夾設定
  • elasticsearch.yml設定
  • Repository設定
  • 建立repository
  • 檢查repository設定是否成功
  • 查詢所有repository設定
  • 刪除註冊完成的repository
  • Snapshot設定
  • 建立snapshot並自行命名,包含所有index
  • 建立特定index的snapshot
  • 查詢snapshot建立進度
  • 查詢所有snapshot版本
  • 刪除snapshot
  • 恢復snapshot
  • 列出所有index
  • 先刪除特定index
  • 關閉index
  • 指定snapshot進行恢復
  • 指定snapshot中的index進行恢復
  • 查看恢復進度

Was this helpful?

  1. Database
  2. elasticsearch

Backup and Restore

備份與還原

測試版本:5.6.3

建立資料夾

bitnami:需要加-H 'Content-Type: application/json'

-H 'Content-Type: application/json'

資料夾設定

# 打開資料夾所有權限  避免使用者權限問題
sudo chmod -R 777 [path]

# 檢視資料夾詳細設定
ls -al [path]

elasticsearch.yml設定

更新elasticsearch.yml內容 (cluster每一台都要?)

# 新增備份絕對路徑
path.repo: ["/mnt/es_backup"]

設定完成後重啟es server

# bitnami環境
sudo service bitnami restart

# 檢查重啟是否成功
systemctl status bitnami.service

Repository設定

建立repository

curl -XPUT 'http://[ip]:9200/_snapshot/[repository_name]' -d '{
     "type":"fs",
     "settings":{
         "location":"[backup_absolute_path]",
         "compress":true,
         "max_snapshot_bytes_per_sec" : "50mb", 
         "max_restore_bytes_per_sec" : "50mb"
     }
 }'

 # 可能會回傳一些error資訊,但依然可先查詢repository是否有設定成功
 # 可更改備份與恢復的速度,預設是20mb
 # 建立時使用PUT,而更新設定時則使用POST

檢查repository設定是否成功

 curl -XPOST http://[ip]:9200/_snapshot/[repository_name]/_verify?pretty

如果在建立或檢查repository時出現資料夾權限錯誤(repository verification exception)

可自行建立sshfs共享資料夾來解決(參考Linux/sshfs)

查詢所有repository設定

curl -XGET 'http://[ip]:9200/_snapshot?pretty'

# 已設定完成的結果
{
  "[backup_name]" : {
    "type" : "fs",
    "settings" : {
      "compress" : "true",
      "location" : "[backup_name]"
    }
  }
}

刪除註冊完成的repository

curl -XDELETE 'http://[ip]:9200/_snapshot/[repository_name]?pretty'

# 若repository已有snapshot,則無法直接刪除

Snapshot設定

建立snapshot並自行命名,包含所有index

curl -XPUT 'http://[ip]:9200/_snapshot/[repository_name]/[snpashot_name]?wait_for_completion=true'

# 可從successful、failed欄位得知備份是否完全成功
# 快照只會處理狀態是open的index

建立特定index的snapshot

curl -XPUT 'http://[ip]:9200/_snapshot/[repository_name]/[snapshot_name]' -d '{"indices":"[index_name]"}'

# snapshot備份完成結果格式都相同

查詢snapshot建立進度

curl -XGET 'http://[ip]:9200/_snapshot/[repository_name]/[snapshot_name]/_status?pretty'

查詢所有snapshot版本

curl -XGET "[ip]:9200/_snapshot/[backup_name]/_all?pretty"

# 若已有儲存snapshot,可看到其相關資訊
{
    "snapshots": [
    {
        "snapshot": "snapshot版本名稱",
        "indices": [儲存的index],
        ...
    }
    ]
}

# 可從successful、failed欄位得知備份是否完全成功

刪除snapshot

curl -XDELETE 'http://140.96.68.132:9200/_snapshot/[repository_name]/[snapshot_name]'

恢復snapshot

列出所有index

curl -XGET '[ip]:9200/_cat/indices?v'

先刪除特定index

curl -XDELETE 'http://[ip]:9200/[index_name]'

# 刪除完成後再列出一次所有index,確認刪除成功

關閉index

# 恢復前需先關閉index
# 關閉所有index
curl -XPOST 'http://[ip]:9200/_all/_close'

# 關閉指定index
curl -XPOST 'http://[ip]:9200/[index_name]/_close'

指定snapshot進行恢復

curl -XPOST 'http://[ip]:9200/_snapshot/[repository_name]/[snapshot_name]/_restore?wait_for_completion=true"

# 成功可看到failed:0
# 恢復完成後再檢查一次index
# 在該次恢復完成前,無法再度執行其他snapshot版本的恢復

指定snapshot中的index進行恢復

curl -XPOST 'http://[ip]:9200/_snapshot/[repository_name]/[snapshot_name]/_restore' -d '{
    "indices": "[index_name]", 
    "rename_replacement": "[new_index]"
}‘

查看恢復進度

curl -XGET http://[ip]:9200/_recovery?pretty
PreviousQueryNextelasticdump

Last updated 5 years ago

Was this helpful?

參考連結:

https://docs.bitnami.com/virtual-machine/apps/elasticsearch/
https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html
http://droidspa.blogspot.com/2016/11/elasticsearch-backup-and-restore.html
http://www.itread01.com/content/1495128248.html
http://keenwon.com/1393.html
http://openskill.cn/article/468
http://smallasa.com/2017/03/09/elasticsearch-backup-and-restore/