备份脚本 es_backup.sh :

#!/bin/bash
#备份昨天数据,删除30天前索引
host=`hostname`
address="xxx@xxx.com"
es_user=$1
es_passwd=$2
#获取昨天日期(备份使用)
date_yesterday=`date -d "-1 day" +%Y.%m.%d`
#获取当前时间戳
date_now=`date +%s`
#获取一个月前的日期
date_month_ago=`date -d@$[ $date_now - 2592000 ] "+%Y.%m.%d"`
for i in txxxx zhaoxxx #指定备份索引
do
#判断仓库是否存在,不存在则创建
code=`curl -XGET -u$es_user:$es_passwd -s -w "%{http_code}\n" http://127.0.0.1:9200/_snapshot/"$i" -o /dev/null -I`
[ ! -d /S3/elasticsearch/"$i" ] && /usr/bin/sudo mkdir /S3/elasticsearch/"$i" && /usr/bin/sudo chown -R elasticsearch.elasticsearch /S3/elasticsearch/
if [ "$code" -ne 200 ];then
curl -XPUT -u$es_user:$es_passwd http://127.0.0.1:9200/_snapshot/"$i" -d '
{
"type": "fs",
"settings": {
"location": "/S3/elasticsearch/'$i'"
}
} '
[ $? -eq 0 ]&& echo "创建仓库: $i"
else
echo "仓库:$i 已存在!"
fi
#备份昨天数据
curl -XPUT -u$es_user:$es_passwd http://127.0.0.1:9200/_snapshot/"$i"/"$i"-"$date_yesterday"?wait_for_completion=true -d '
{
"indices": "'$i'-'$date_yesterday'"
}'
[ $? -ne 0 ]&& echo "$time $host $i-$date_yesterday backup failed!" |mail -s "ES Backup Information" $address
#删除上个月当天的数据
curl -XDELETE -u$es_user:$es_passwd http://127.0.0.1:9200/"$i"-"$date_month_ago"|| echo "上个月前一天的数据不存在!"
done

恢复脚本 es_restore.sh:

#!/bin/bash
#恢复指定时间段内索引数据
es_user=$1
es_passwd=$2
while :
do
#读取用户输入
read -p "请输入你想要恢复的服务(eg: xxxxx, q 退出): " service #指定恢复数据的索引名
echo "输入为: $service "
if [ "$service" = "q" ];then
exit
fi while :
do
read -p "请输入开始的日期(eg: 2018-05-01, q 返回上一级):" start_date
if [ "$start_date" = "q" ];then
break
fi
read -p "请输入结束的日期(eg: 2018-05-30, q 返回上一级):" end_date
if [ "$end_date" = "q" ];then
break
fi
start_date_toSecond=`date -d $start_date +%s`
end_date_toSecond=`date -d $end_date +%s`
#收集所有日期
function gen_date {
index=0
while [ "$start_date_toSecond" -le "$end_date_toSecond" ]
do
curr_date=`date -d@$start_date_toSecond +%Y.%m.%d`
date_arr[index]=$curr_date
start_date_toSecond=$[ $start_date_toSecond+86400 ]
let index++
done
}
gen_date $start_date $end_date n=0
while [ "$n" -lt "${#date_arr[@]}" ]
do
echo ${date_arr[$n]}
    code=`curl -XPOST  -u$es_user:$es_passwd  -s -w "%{http_code}\n" http://127.0.0.1:9200/_snapshot/"$service"/"$service"-${date_arr[$n]}/_restore?wait_for_completion=true  -d  '{"ignore_unavailable": "true", "include_global_state": false ,"index_settings": { "index.number_of_replicas": 0 }}' -o /dev/null`
let n++
echo "$code"
if [ "$code" -eq 200 ];then
echo "$service_${date_arr[$n]} 导入成功"
else
echo "$service_${date_arr[$n]} 导入失败"
fi
done
done
done

elasticsearch 索引备份恢复的更多相关文章

  1. 【ELK】Elasticsearch的备份和恢复

    非原创,只是留作自己查询使用,转自http://keenwon.com/1393.html Elasticsearch的备份和恢复 备份 Elasticsearch的一大特点就是使用简单,api也比较 ...

  2. Elasticsearch系列---生产数据备份恢复方案

    前言 生产环境中运行的组件,只要有数据存储,定时备份.灾难恢复是必修课,mysql数据库的备份方案已经非常成熟,Elasticsearch也同样有成熟的数据备份.恢复方案,我们来了解一下. 概要 本篇 ...

  3. 第五章 MySQL事务,视图,索引,备份和恢复

    第五章 MySQL事务,视图,索引,备份和恢复 一.事务 1.什么是事务 事务是一种机制,一个操作序列,它包含了一组数据库操作命令,并且把所有的命令作为一个整体一起向系统提交或撤销操作请求.要么都执行 ...

  4. ES集群7.3.0设置快照,存储库进行索引备份和恢复等

    说明:三台ES节点组成ES集群,一台kibana主机,版本均是7.3.0,白金试用版 官方地址:https://www.elastic.co/guide/en/elasticsearch/refere ...

  5. ElasticSearch 索引 剖析

    ElasticSearch index 剖析 在看ElasticSearch权威指南基础入门中关于:分片内部原理这一小节内容后,大致对ElasticSearch的索引.搜索底层实现有了一个初步的认识. ...

  6. Elasticsearch snapshot 备份的使用方法 【备忘】

    常见的数据库都会提供备份的机制,以解决在数据库无法使用的情况下,可以开启新的实例,然后通过备份来恢复数据减少损失.虽然 Elasticsearch 有良好的容灾性,但由于以下原因,其依然需要备份机制. ...

  7. ElasticSearch索引快照

    参考文档:https://www.elastic.co/guide/en/elasticsearch/reference/5.1/modules-snapshots.html 备份数据之前,要创建一个 ...

  8. Xtrabackup原理及使用innobackupex进行MySQL数据库备份恢复

    Xtrabackup是由percona提供的mysql数据库备份工具,据官方介绍,这也是世界上惟一一款开源的能够对innodb和xtradb数据库进行热备的工具. Xtrabackup中主要包含两个工 ...

  9. [转]PLSQL Developer备份恢复oracle数据

    本文转自:http://www.cnblogs.com/iampkm/archive/2013/06/09/3128273.html 使用PL sql提供的功能可以快速的备份恢复oracle数据. 1 ...

随机推荐

  1. 学习Vue 入门到实战——学习笔记(二)

    闲聊: 哈哈哈!过了好几天才更新博客啦,嘻嘻,马上过年了,大家最近是不是都开心的快飞起来了,小颖好几个朋友公司都已经放假了,可是我们公司要等到腊月29上完班才给放假,哎!心情不美气的很,用我之前大学舍 ...

  2. [原]Failed connect to mirrors.cloud.aliyuncs.com:80; Connection refused

    web site : https://opsx.alibaba.com/mirror 运行后出现下面的Error: base//x86_64/other_db FAILED http://mirror ...

  3. [原]Docker-issue(1) image name 显示为 <none>

    问题:今天发现重新上传新的image的时候覆盖了原来的镜像后,REPOSITORY 就变为了 <none> ,如下图 解决办法: 使用tag重新命名image 问题解决:

  4. Redis 教程 Java工程师学习知识点

    1. Redis简介及安装 1.1 Redis 简介 Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库. Redis 与其他 key - value 缓存产品有以下 ...

  5. HTML5 - Canvas【申明:来源于网络】

    HTML5 - Canvas 地址:http://hwaphon.site/

  6. C# 封装winio.dll 驱动级按键鼠标操作模拟

    using System;using System.Collections.Generic;using System.Text;using System.Runtime.InteropServices ...

  7. gtest 安装与使用

    打开资源管理器: nautilus . gtest 获取 从:https://www.bogotobogo.com/cplusplus/google_unit_test_gtest.php 获取gte ...

  8. 审核被拒:1. 1 Safety: Objectionable Content ;3. 1.1 Business: Payments - In-App Purchase ;4. 3 Design: Spam ;5. 1.1 Legal: Privacy - Data Collection and Storage

    1. 1 Safety: Objectionable Content                          有人民币符号—隐藏收费课程 3. 1.1 Business: Payments ...

  9. 图->有向无环图->拓扑排序

    文字描述 关于有向无环图的基础定义: 一个无环的有向图称为有向无环图,简称DAG图(directed acycline graph).DAG图是一类较有向树更一般的特殊有向图. 举个例子说明有向无环图 ...

  10. rebuild online时意外中断 再次重建时报错解决方法

    rebuild online时意外中断 再次重建时报错 SQL> alter index PARTY.IDX_CM_INDIV_CUSTOMER_4 rebuild online; alter ...