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:Tg5jWUL8ri -H "Content-Type: application/json" -XDELETE "http://10.7.81.120:19200/_snapshot/esbackup/snapshot_$delete_d
ate"
##创建备份仓库目录
curl -u elastic:Tg5jWUL8ri -H "Content-Type: application/json" -XPUT http://10.7.81.120:19200/_snapshot/esbackup -d'{
"type": "fs",
"settings": {
"location": "/home/middle/esbak"
}
}'
##备份
curl -u elastic:Tg5jWUL8ri -H "Content-Type: application/json" -XPUT http://10.7.81.120: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