前置工作索引备份

    1.索引备份

    1. #创建Es备份仓库es_bk文件夹
    2. cd /iflytek/data
    3. mkdir es_bk
    4. #给es用户添加访问权限
    5. chown -R elastic:elastic /iflytek/data/es_bk/
    6. cd /iflytek/server/elasticsearch-5.4.3
    7. #配置es配置
    8. vim config/elasticsearch.yml
    9. #添加一下数据行 配置以上创建的文件夹
    10. path.repo: ["/iflytek/data/es_bk"]
    11. #重启ES 确认用户是否为elastic
    12. kill -9 espid
    13. su elastic
    14. cd /iflytek/server/elasticsearch-5.4.3/bin
    15. ./elasticsearch -d

    2.新建索引备份仓库

    1. #新建备份仓库
    2. PUT _snapshot/my_backup
    3. {
    4. "type": "fs",
    5. "settings": {
    6. "location": "/iflytek/data/es_bk",
    7. "compress": true
    8. }
    9. }
    10. #查看备份仓库
    11. GET _snapshot/my_backup
    12. #备份索引tuling-swk-sw 为索引名称 my_backup为仓库名称
    13. PUT _snapshot/my_backup/snapshot_swk?wait_for_completion=true
    14. {
    15. "indices": "tuling-swk-sw",
    16. "ignore_unavailable": true,
    17. "include_global_state": false
    18. }
    19. #恢复数据
    20. POST /_snapshot/my_backup/snapshot_swk/_restore
    21. {
    22. "indices": "tuling-swk-sw",
    23. "rename_pattern": "index_(.+)",
    24. "rename_replacement": "restored_index_$1"
    25. }

    3.删除语句(非必要不执行)

    1. #以下删除语句不要执行
    2. #删除备份
    3. DELETE _snapshot/my_backup/snapshot_swk
    4. #删除仓库
    5. DELETE _snapshot/my_backup
    6. #查看所有
    7. GET _snapshot/my_backup/_all

    附(curl执行语句)

    1. #创建仓库
    2. curl -XPUT "http://10.124.41.11:9209/_snapshot/my_backup" -H 'Content-Type: application/json' -d'
    3. {
    4. "type": "fs",
    5. "settings": {
    6. "location": "/iflytek/data/es_bk",
    7. "compress": true
    8. }
    9. }'
    10. #查看仓库
    11. curl -XGET "http://10.124.41.11:9209/_snapshot/my_backup"
    12. #备份索引
    13. curl -XPUT "http://10.124.41.11:9209/_snapshot/my_backup/snapshot_swk?wait_for_completion=true" -H 'Content-Type: application/json' -d'
    14. {
    15. "indices": "tuling-swk-sw",
    16. "ignore_unavailable": true,
    17. "include_global_state": false
    18. }'
    19. #恢复索引数据
    20. curl -XPOST "http://10.124.41.11:9209/_snapshot/my_backup/snapshot_swk/_restore" -H 'Content-Type: application/json' -d'
    21. {
    22. "indices": "tuling-swk-sw",
    23. "rename_pattern": "index_(.+)",
    24. "rename_replacement": "restored_index_$1"
    25. }'
    26. curl -XDELETE "http://10.124.41.11:9209/_snapshot/my_backup/snapshot_swk"
    27. curl -XDELETE "http://10.124.41.11:9209/_snapshot/my_backup"
    28. curl -XDELETE "http://10.124.41.11:9209/_snapshot/my_backup"