comparison scripts/backup-document-store.sh @ 424:52c2ec5ddeb5

DS-54: add backup, restore, and list snapshots scripts for document store
author Robin Fronk <robin.fronk@mcoecn.org>
date Tue, 19 Sep 2023 11:36:03 -0400
parents
children
comparison
equal deleted inserted replaced
423:8f797bb7ccb3 424:52c2ec5ddeb5
1 #!/bin/bash
2
3 projectDir=${1:-$PWD}
4
5 cd "$projectDir" || echo "Unable to change to project directory: $projectDir"
6
7 function prop {
8 grep "${1}" .env/ssdt-document-store-shared.properties|cut -d'=' -f2
9 }
10
11 entityId=$(prop 'entityId' | tr -d '"')
12 repository="${entityId}_fs_backup"
13 certificate=${projectDir}/http_ca.crt
14 baseUrl="https://$(prop 'DOCUMENTSTORE_ELASTIC_HOST' | tr -d '"'):$(prop 'DOCUMENTSTORE_ELASTIC_PORT' | tr -d '"')"
15 elasticPassword=$(prop 'ELASTIC_PASSWORD' | tr -d '"')
16
17 verifyRepository=$(curl --cacert "${certificate}" -s -u elastic:"${elasticPassword}" -X POST "${baseUrl}/_snapshot/${repository}/_verify?pretty")
18
19 countMissingException=$(echo "${verifyRepository}" | grep -c "repository_missing_exception")
20
21 if [ "$countMissingException" -gt 0 ]; then
22 echo "creating Repository ${repository}"
23 curl --cacert "${certificate}" -s -u elastic:"${elasticPassword}" -X PUT "${baseUrl}/_snapshot/${repository}?pretty" -H 'Content-Type: application/json' -d'
24 {
25 "type": "fs",
26 "settings": {
27 "location": "/usr/share/elasticsearch/backup",
28 "compress": true
29 }
30 }
31 '
32 fi
33
34 snapshotName="%3C${entityId}-snapshot-%7Bnow%2Fs%7Byyyy.MM.dd-HH.mm.ss%7D%7D%3E"
35
36 curl --cacert "${certificate}" -s -u elastic:"${elasticPassword}" -X PUT "${baseUrl}/_snapshot/${repository}/${snapshotName}?pretty"