前置工作索引备份
1.索引备份
#创建Es备份仓库es_bk文件夹
cd /iflytek/data
mkdir es_bk
#给es用户添加访问权限
chown -R elastic:elastic /iflytek/data/es_bk/
cd /iflytek/server/elasticsearch-5.4.3
#配置es配置
vim config/elasticsearch.yml
#添加一下数据行 配置以上创建的文件夹
path.repo: ["/iflytek/data/es_bk"]
#重启ES 确认用户是否为elastic
kill -9 espid
su elastic
cd /iflytek/server/elasticsearch-5.4.3/bin
./elasticsearch -d
2.新建索引备份仓库
#新建备份仓库
PUT _snapshot/my_backup
{
"type": "fs",
"settings": {
"location": "/iflytek/data/es_bk",
"compress": true
}
}
#查看备份仓库
GET _snapshot/my_backup
#备份索引tuling-swk-sw 为索引名称 my_backup为仓库名称
PUT _snapshot/my_backup/snapshot_swk?wait_for_completion=true
{
"indices": "tuling-swk-sw",
"ignore_unavailable": true,
"include_global_state": false
}
#恢复数据
POST /_snapshot/my_backup/snapshot_swk/_restore
{
"indices": "tuling-swk-sw",
"rename_pattern": "index_(.+)",
"rename_replacement": "restored_index_$1"
}
3.删除语句(非必要不执行)
#以下删除语句不要执行
#删除备份
DELETE _snapshot/my_backup/snapshot_swk
#删除仓库
DELETE _snapshot/my_backup
#查看所有
GET _snapshot/my_backup/_all
附(curl执行语句)
#创建仓库
curl -XPUT "http://10.124.41.11:9209/_snapshot/my_backup" -H 'Content-Type: application/json' -d'
{
"type": "fs",
"settings": {
"location": "/iflytek/data/es_bk",
"compress": true
}
}'
#查看仓库
curl -XGET "http://10.124.41.11:9209/_snapshot/my_backup"
#备份索引
curl -XPUT "http://10.124.41.11:9209/_snapshot/my_backup/snapshot_swk?wait_for_completion=true" -H 'Content-Type: application/json' -d'
{
"indices": "tuling-swk-sw",
"ignore_unavailable": true,
"include_global_state": false
}'
#恢复索引数据
curl -XPOST "http://10.124.41.11:9209/_snapshot/my_backup/snapshot_swk/_restore" -H 'Content-Type: application/json' -d'
{
"indices": "tuling-swk-sw",
"rename_pattern": "index_(.+)",
"rename_replacement": "restored_index_$1"
}'
curl -XDELETE "http://10.124.41.11:9209/_snapshot/my_backup/snapshot_swk"
curl -XDELETE "http://10.124.41.11:9209/_snapshot/my_backup"
curl -XDELETE "http://10.124.41.11:9209/_snapshot/my_backup"