changeset 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 8f797bb7ccb3
children 934feeb03449
files scripts/backup-document-store.sh scripts/list-document-store-snapshots.sh scripts/restore-document-store.sh
diffstat 3 files changed, 74 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/backup-document-store.sh	Tue Sep 19 11:36:03 2023 -0400
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+projectDir=${1:-$PWD}
+
+cd "$projectDir" || echo "Unable to change to project directory: $projectDir"
+
+function prop {
+  grep "${1}" .env/ssdt-document-store-shared.properties|cut -d'=' -f2
+}
+
+entityId=$(prop 'entityId' | tr -d '"')
+repository="${entityId}_fs_backup"
+certificate=${projectDir}/http_ca.crt
+baseUrl="https://$(prop 'DOCUMENTSTORE_ELASTIC_HOST' | tr -d '"'):$(prop 'DOCUMENTSTORE_ELASTIC_PORT' | tr -d '"')"
+elasticPassword=$(prop 'ELASTIC_PASSWORD' | tr -d '"')
+
+verifyRepository=$(curl --cacert "${certificate}" -s -u elastic:"${elasticPassword}" -X POST "${baseUrl}/_snapshot/${repository}/_verify?pretty")
+
+countMissingException=$(echo "${verifyRepository}" | grep -c "repository_missing_exception")
+
+if [ "$countMissingException" -gt 0 ]; then
+  echo "creating Repository ${repository}"
+    curl --cacert "${certificate}" -s -u elastic:"${elasticPassword}" -X PUT "${baseUrl}/_snapshot/${repository}?pretty" -H 'Content-Type: application/json' -d'
+    {
+        "type": "fs",
+        "settings": {
+            "location": "/usr/share/elasticsearch/backup",
+            "compress": true
+        }
+    }
+    '
+fi
+
+snapshotName="%3C${entityId}-snapshot-%7Bnow%2Fs%7Byyyy.MM.dd-HH.mm.ss%7D%7D%3E"
+
+curl --cacert "${certificate}" -s -u elastic:"${elasticPassword}" -X PUT "${baseUrl}/_snapshot/${repository}/${snapshotName}?pretty"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/list-document-store-snapshots.sh	Tue Sep 19 11:36:03 2023 -0400
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+projectDir=${1:-$PWD}
+detailedView=${2:-false}
+
+cd "$projectDir" || echo "Unable to change to project directory: $projectDir"
+
+function prop {
+  grep "${1}" .env/ssdt-document-store-shared.properties|cut -d'=' -f2
+}
+
+entityId=$(prop 'entityId' | tr -d '"')
+repository="${entityId}_fs_backup"
+certificate=${projectDir}/http_ca.crt
+baseUrl="https://$(prop 'DOCUMENTSTORE_ELASTIC_HOST' | tr -d '"'):$(prop 'DOCUMENTSTORE_ELASTIC_PORT' | tr -d '"')"
+elasticPassword=$(prop 'ELASTIC_PASSWORD' | tr -d '"')
+
+options="pretty&verbose=${detailedView}&index_names=${detailedView}&ignore_unavailable=true"
+
+curl --cacert "${certificate}" -s -u elastic:"${elasticPassword}" -X GET "${baseUrl}/_snapshot/${repository}/_all?${options}"
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/restore-document-store.sh	Tue Sep 19 11:36:03 2023 -0400
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+projectDir=${1:-$PWD}
+snapshot=${2?Must provide snapshot name to restore}
+
+cd "$projectDir" || echo "Unable to change to project directory: $projectDir"
+
+function prop {
+  grep "${1}" .env/ssdt-document-store-shared.properties|cut -d'=' -f2
+}
+
+entityId=$(prop 'entityId' | tr -d '"')
+repository="${entityId}_fs_backup"
+certificate=${projectDir}/http_ca.crt
+baseUrl="https://$(prop 'DOCUMENTSTORE_ELASTIC_HOST' | tr -d '"'):$(prop 'DOCUMENTSTORE_ELASTIC_PORT' | tr -d '"')"
+elasticPassword=$(prop 'ELASTIC_PASSWORD' | tr -d '"')
+
+curl --cacert "${certificate}" -s -u elastic:"${elasticPassword}" -X POST "${baseUrl}/_snapshot/${repository}/${snapshot}/_restore?pretty"
\ No newline at end of file