-
Notifications
You must be signed in to change notification settings - Fork 1
/
restore-opensearch-indexes.bash
executable file
·112 lines (92 loc) · 2.51 KB
/
restore-opensearch-indexes.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
APP_NAME="$(basename "$0")"
#
# This script can bring invenio-rdm down in an orderly fashion
# or start it back up.
#
function usage() {
cat <<EOT
% ${APP_NAME}() ${APP_NAME} user manual
% R. S. Doiel
% August 17, 2022
# NAME
${APP_NAME}
# SYNOPSIS
${APP_NAME} [PATH_TO_OPENSEARCH_DUMP_DIR]
# DESCRIPTION
Restore the OpenSearch indexes for an Invenio RDM instance from
a opensearch-dump directory. It uses the "opensearch-indexes.txt" for
the index list. If you want to only restore some of the index you should
edit the "opensearch-indexes.txt" file accordingly.
This script uses 'elasticdump' which is available from
<https://github.com/elasticsearch-dump/elasticsearch-dump>
and runs via npm/NodeJS.
# EXAMPLES
Restore the Opensearch for caltechdata running on CaltechDATA.
~~~shell
sudo -u ubuntu ${APP_NAME} /storage/OpenSearchBackups
~~~
EOT
}
function restore_opensearch_to() {
BACKUP_DIR="$1"
#FIXME: Need to figure out how to identify the two indexes we want to backup to get the stats.
if [ "${BACKUP_DIR}" = "" ]; then
echo "Missing the backup directory name"
exit 1
fi
if [ ! -d "${BACKUP_DIR}" ]; then
echo "${BACKUP_DIR} does not exist"
exit 1
fi
if [ ! -f "${BACKUP_DIR}/opensearch-indexes.txt" ]; then
echo "${BACKUP_DIR}/opensearch-indexes.txt not found, aborting"
exit 2
fi
while read -r INDEX_NAME; do
# Retrieve the index mapping first, then the index data
if [ -f "${BACKUP_DIR}/${INDEX_NAME}.mapping.json.gz" ]; then
gunzip "${BACKUP_DIR}/${INDEX_NAME}.mapping.json.gz"
elasticdump \
--input "${BACKUP_DIR}/${INDEX_NAME}.mapping.json" \
--output "http://localhost:9200/${INDEX_NAME}" \
--type mapping
fi
if [ -f "${BACKUP_DIR}/${INDEX_NAME}.data.json.gz" ]; then
gunzip "${BACKUP_DIR}/${INDEX_NAME}.data.json.gz"
elasticdump \
--intput "${BACKUP_DIR}/${INDEX_NAME}.data.json" \
--output "http://localhost:9200/${INDEX_NAME}" \
--type data
fi
done <"${BACKUP_DIR}/opensearch-indexes.txt"
}
function run_restore() {
#
# Sanity check our requiremented environment
#
SCRIPTNAME="$(readlink -f "$0")"
DNAME="$(dirname "${SCRIPTNAME}")"
cd "${DNAME}" || exit 1
restore_opensearch_to "$1" "$2"
}
#
# Main entry script point.
#
case "$1" in
h | help | -h | --help)
usage
exit 0
;;
*)
if [ "$1" = "" ]; then
usage
exit 1
fi
if [ "$1" != "" ] && [ -d "$1" ]; then
run_restore "$1"
else
run_restore "opensearch-dumps"
fi
;;
esac