es备份和恢复

 

1.备份

root@elasticsearch-010007081120 ~]# more /home/elasticsearch/script/es_backup.sh
#!/bin/sh
now_date=`date "+%Y%m%d"`
delete_date=`date +%Y%m%d -d "1 days ago"` 


##删除之前的备份
curl -u elastic:passwd -H "Content-Type: application/json" -XDELETE "http://192.168.1.100:19200/_snapshot/esbackup/snapshot_$delete_d
ate"

##创建备份仓库目录
curl -u elastic:passwd -H "Content-Type: application/json" -XPUT http://192.168.1.100:19200/_snapshot/esbackup -d'{
    "type": "fs", 
    "settings": {
        "location": "/home/middle/esbak"
    }
}'

##备份
curl -u elastic:passwd -H "Content-Type: application/json" -XPUT http://192.168.1.100:19200/_snapshot/esbackup/snapshot_$now_date

[root@elasticsearch-010007081120 ~]# 
[root@elasticsearch-010007081120 ~]# more /home/elasticsearch/script/es_backup_tar.sh
#!/bin/bash
now_date=`date "+%Y%m%d"`
delete_date=`date +%Y%m%d -d "2 days ago"` 

tar_file=/home/middle/esbak_tar/esbak_${now_date}.tar.gz
cd /home/middle

tar -czvf ${tar_file} ./esbak

##删除本地备份文件
delete_tar_file=/home/middle/esbak_tar/esbak_${delete_date}.tar.gz

##删除本地文件
if [ -f "${delete_tar_file}" ];then
  rm ${delete_tar_file}
fi

 

2.恢复所有的index

curl -H "Content-Type: application/json" -XPUT http://192.168.1.100:19200/_snapshot/esbackup -d'{
"type": "fs",
"settings": {
"location": "/nasdata/middle/elasticsearch/esbak/backup"
}
}'

 

curl -XPOST http://192.168.1.100:19200/_snapshot/esbackup/snapshot_20250317/_restore?wait_for_completion=true

 

3.恢复具体的index

curl -XPOST "http://192.168.1.100:19200/_snapshot/esbackup/snapshot_20250317/_restore?wait_for_completion=true" -H 'Content-Type: application/json' -d'
{
  "indices": "my_index1,my_index2"
}
'

 

4.恢复后改名

curl -XPOST "http://1920.168.1.100:19200/_snapshot/esbackup/snapshot_20250317/_restore?wait_for_completion" -H 'Content-Type: application/json' -d'
{
  "indices": "hxl_community_content",
  "rename_pattern": "hxl_(.+)",
  "rename_replacement": "restored_hxl_$1"
}
'

 

 hxl_community_content 恢复后改名为 restored_hxl_community_content

 

posted @ 2021-04-24 18:18  slnngk  阅读(531)  评论(0)    收藏  举报