forked from Informasjonsforvaltning/fdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdumpDataFromElasticsearch.sh
56 lines (41 loc) · 1.25 KB
/
dumpDataFromElasticsearch.sh
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
#!/usr/bin/env bash
set -e
# Dumps indexes from elasticsearch to file
# requires: npm install [email protected] -g
function startDump {
echo "Start"
environment=$1
sourceElasticUrl=https://elasticsearch-fellesdatakatalog-${environment}.paas-nprd.brreg.no
if [ "$environment" == "ppe" ]
then
sourceElasticUrl=https://elasticsearch-fellesdatakatalog-${environment}.paas.brreg.no
fi
DATETIME=`date "+%Y-%m-%dT%H_%M_%S"`
echo "Starting dump ${DATETIME}"
indexes="dcat scat register harvest"
# dump indexes
for i in ${indexes} ;
do
echo "******************"
echo "Dumping ${i} "
echo "******************"
elasticdump --bulk=true --input=${sourceElasticUrl}/${i} --output=${environment}_${i}.json --type=data
done
ENDTIME=`date "+%Y-%m-%dT%H_%M_%S"`
echo "Finished dump ${ENDTIME}"
}
if [ -z "$1" ]
then
echo "Elasticsearch environment must be specified: ut1, st1, st2, tt1 ppe or prd"
echo "correct usage: dumpEnv.sh <environment>"
exit 1
fi
echo "This will dump elasticsearch content of indexes from $1 to file"
read -r -p "Are you sure? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
startDump $1
else
exit 1
fi
echo "Done";