Commit 567c43f4 authored by kartish's avatar kartish
Browse files

Issue #000 fix: backup and restore shell scripts for elasticsearch

No related merge requests found
Showing with 33 additions and 14 deletions
+33 -14
#!/bin/sh
backup_path=/etc/elasticsearch/backup
es_ip=10.2.1.5
es_ip=$(ip route get 8.8.8.8 | awk '{print $NF; exit}')
if [ -f $backup_path ]
if [ -d $backup_path ];
then
echo "directory exists"
echo "directory exists"
else
mkdir -p /etc/elasticsearch/backup
mkdir -p /etc/elasticsearch/backup
fi
cat >> /etc/elasticsearch/es-1/elasticsearch.yml << EOF
temp=$(grep "path.repo:" /etc/elasticsearch/es-1/elasticsearch.yml)
if [ $? -ne 0 ]; then
cat >> /etc/elasticsearch/es-1/elasticsearch.yml << EOF
path.repo: ["/etc/elasticsearch/backup"]
EOF
/usr/share/elasticsearch/bin/elasticsearch \
-p /var/run/elasticsearch/10.2.1.5-es-1/elasticsearch.pid \
--quiet \
-Edefault.path.logs=${LOG_DIR} \
-Edefault.path.data=${DATA_DIR} \
-Edefault.path.conf=${CONF_DIR}
fi
chown -R elasticsearch:elasticsearch $backup_path
echo $es_ip
curl -XPUT 'http://$es_ip:9200/_snapshot/my_backup' -d {
curl -XPUT http://$es_ip:9200/_snapshot/my_backup -d '{
"type": "fs",
"settings": {
"location": "$backup_path",
"location": "'$backup_path'",
"compress": true
}
}'
curl -XPUT "$es_ip:9200/_snapshot/my_backup/snapshot_1?wait_for_completion=true"
timestamp=`date '+%d_%m_%Y%H%M%S'`
curl -XPUT http://$es_ip:9200/_snapshot/my_backup/snapshot_$timestamp?wait_for_completion=true
\ No newline at end of file
#!/bin/sh
backup_path=/etc/elasticsearch/backup
es_ip=$(ip route get 8.8.8.8 | awk '{print $NF; exit}')
curl 172.31.0.239:9200/_cat/indices?v | awk '{print $3}' | awk 'NR>1' > ~/index.txt
while read line;
do
curl -XDELETE http://$es_ip:9200/$line
done < ~/index.txt
rm -rf ~/index.txt
snapshot_id=$1
curl -XPOST "http://$es_ip:9200/_snapshot/my_backup/$snapshot_id/_restore"
echo $(curl http://$es_ip:9200/_cat/indices?v)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment