Elasticsearch Index Backup Recovery

Source: Internet
Author: User

Backup Script es_backup.sh:

#!/bin/bash
#备份昨天数据, deleted 30 days ago Index host= ' hostname ' es_user=$1es_passwd=$2# get yesterday date (backup used) date_yesterday= ' date-d '-1 day "+%y.%m.%d ' # Gets the current timestamp date_now= ' Date +%s ' #获取一个月前的日期date_month_ago = ' date [email protected]$[$date _now-2592000] "+%y.%m.%d" ' For i in Txxxx zhaoxxx #指定备份索引do #判断仓库是否存在, does not exist create 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 Mkdi r/s3/elasticsearch/"$i" &&/usr/bin/sudo chown-r elasticsearch.elasticsearch/s3/elasticsearch/if ["$code" -ne];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]&&A mp echo "Create warehouse: $i" Else echo "warehouse: $i already exists!" Fi #备份昨天数据 curl-xput-u$es_user: $es _passwd http://127.0.0.1:9200/_snapshot/"$i"/"$i"-"$date _yesterday"-d ' {"Indices": "' $i '-' $date _yesterday '"} ' [$-ne 0]&& echo "$time $host $i-$date _yesterday backup F ailed! "|mail-s" ES Backup Information "$address #删除上个月当天的数据 curl-xdelete-u$es_user: $es _passwd http://127.0.0.1: 9200/"$i"-"$date _month_ago" | | echo "No data existed the day before last month!" Done

Recovery Script es_restore.sh:

#!/bin/bash
#恢复指定时间段内索引数据es_user =$1es_passwd=$2while:d o #读取用户输入 read-p "Please enter the service you want to restore (eg:xxxxx, q exit): Service #指定恢复数据的索引名 EC Ho "Input: $service" If ["$service" = "Q"];then exit fi while:do read-p "Please enter the start date (eg:2018-05-01, Q return to previous level):" start_date if ["$start _date" = "Q"];then break fi read-p "Please enter the end date (eg:2018-05-30, Q return to previous level):" End_date If ["$end _date" = "Q"];then break fi start_date_tosecond= ' date-d $start _date +%s ' end_date_tosecond= ' da te-d $end _date +%s ' #收集所有日期 function gen_date {index=0 while ["$start _date_tosecond"-le "$end _date_tos Econd "] do curr_date= ' date [email protected] $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_u Ser: $es _passwd-s-W "%{http_code}\n "http://127.0.0.1:9200/_snapshot/" $service "/" $service "-${date_arr[$n]}/_restore-o/dev/null ' let n++ echo "$code" if ["$code"-eq];then echo "$service _${date_arr[$n]} import Successful" Else echo "$s ervice_${date_arr[$n]} Import Failed "Fi done Donedone

Elasticsearch Index Backup Recovery

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.