Skip to content

Commit 92551e7

Browse files
committed
Add ES index backup script for upgrade safety
1 parent 6dbc8fe commit 92551e7

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

elasticsearch/backup-indexes.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
# Backup Elasticsearch indexes before ES 7->8 upgrade
3+
# Run from lipas root: ./elasticsearch/backup-indexes.sh
4+
5+
set -e
6+
7+
BACKUP_DIR="./data/es-backup-$(date +%Y%m%d-%H%M%S)"
8+
mkdir -p "$BACKUP_DIR"
9+
10+
echo "Backing up to: $BACKUP_DIR"
11+
12+
# Indexes to backup (excluding logstash, sports_sites, loi, legacy, search)
13+
INDEXES=(
14+
"analytics-2024-09-15t14-18-01-881678"
15+
"city_stats"
16+
#"diversity-2022-10-01t19-32-50-999"
17+
#"diversity-2022-10-02-initial"
18+
#"diversity-2023-12-28t15-35-55-575928"
19+
"diversity-2025-11-01-harmonized"
20+
#"diversity-2025-11-01t18-31-48-076648"
21+
"kunnat_2021_wgs84"
22+
"kunnat_2021_wgs84_fixed"
23+
#"population-1km-2023-12-31t11-50-44-797"
24+
"population-1km-2025-11-01-harmonized"
25+
#"population-1km-2025-11-01t16-06-49-692277"
26+
#"population-250m-2023-12-29t14-29-03-761335"
27+
"population-250m-2025-11-01-harmonized"
28+
#"population-250m-2025-11-01t16-28-46-364857"
29+
#"population-250m-2025-11-01t16-32-19-479132"
30+
"schools"
31+
"subsidies"
32+
"vaestoruutu_1km_2019_kp"
33+
"vaestoruutu_250m_2020_kp"
34+
)
35+
36+
backup_index() {
37+
local index=$1
38+
local backup_subdir="/data/es-backup-$(date +%Y%m%d-%H%M%S)"
39+
40+
echo "=== Backing up: $index ==="
41+
42+
# Backup mapping
43+
docker compose run --rm elasticdump \
44+
--input=http://elasticsearch:9200/$index \
45+
--output=/data/$index.mapping.json \
46+
--type=mapping
47+
48+
# Backup data
49+
docker compose run --rm elasticdump \
50+
--input=http://elasticsearch:9200/$index \
51+
--output=/data/$index.data.json \
52+
--type=data \
53+
--limit=10000
54+
55+
echo " Done: $index"
56+
}
57+
58+
for index in "${INDEXES[@]}"; do
59+
backup_index "$index"
60+
done
61+
62+
echo ""
63+
echo "=== Backup complete ==="
64+
echo "Files saved to: ./data/"
65+
ls -lh ./data/*.json 2>/dev/null | tail -20

0 commit comments

Comments
 (0)