Skip to content

Commit dfe2372

Browse files
committed
elasticdump for elasticsearch data backup
1 parent fbffed4 commit dfe2372

File tree

6 files changed

+81
-5
lines changed

6 files changed

+81
-5
lines changed

charts/drupal/templates/_helpers.tpl

+50-3
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,18 @@ done
369369
{{- end }}
370370
{{- end }}
371371

372-
{{ if .Values.elasticsearch.enabled }}
373-
{{ include "drupal.wait-for-elasticsearch-command" . }}
374-
{{ end }}
372+
{{- if .Values.elasticsearch.enabled }}
373+
{{- include "drupal.wait-for-elasticsearch-command" . }}
374+
{{- if and .Release.IsInstall .Values.referenceData.elasticsearch }}
375+
if [[ -f /app/reference-data/elasticsearch.tar.gz || -f /app/reference-data/elasticsearch.tar.gz ]]; then
376+
echo "Importing elasticsearch reference data"
377+
mkdir /tmp/elasticsearch
378+
tar -xzf /app/reference-data/elasticsearch.tar.gz -C /tmp/elasticsearch
379+
multielasticdump --direction=load --input=/tmp/elasticsearch --output=http://${ELASTICSEARCH_HOST}:9200/
380+
echo "Elasticsearch reference data imported"
381+
fi
382+
{{- end }}
383+
{{- end }}
375384

376385
{{ if .Release.IsInstall }}
377386
{{ .Values.php.postinstall.command }}
@@ -395,6 +404,7 @@ done
395404
{{- define "drupal.extract-reference-data" -}}
396405
set -e
397406
if [[ "$(drush status --fields=bootstrap)" = *'Successful'* ]] ; then
407+
398408
echo "Dump reference database."
399409
dump_dir=/tmp/reference-data-export/
400410
mkdir "${dump_dir}"
@@ -462,6 +472,15 @@ if [[ "$(drush status --fields=bootstrap)" = *'Successful'* ]] ; then
462472
/app/reference-data/{{ $index }}
463473
{{ end -}}
464474
{{- end }}
475+
476+
{{- if .Values.referenceData.elasticsearch }}
477+
echo "Creating reference data for elasticsearch"
478+
mkdir /tmp/elasticsearch
479+
multielasticdump --direction=dump --input=http://${ELASTICSEARCH_HOST}:9200/ --output=/tmp/elasticsearch
480+
tar -czf /tmp/elasticsearch.tar.gz -C /tmp/elasticsearch .
481+
cp /tmp/elasticsearch.tar.gz /app/reference-data
482+
{{- end }}
483+
465484
else
466485
echo "Drupal is not installed, skipping reference database dump."
467486
fi
@@ -519,6 +538,9 @@ fi
519538
520539
{{- define "drupal.backup-command" -}}
521540
{{ include "drupal.backup-command.dump-database" . }}
541+
{{- if and .Values.elasticsearch.enabled .Values.backup.elasticsearch }}
542+
{{- include "drupal.backup-command.dump-elasticsearch" . }}
543+
{{- end }}
522544
{{ include "drupal.backup-command.archive-store-backup" . }}
523545
{{- end }}
524546
@@ -545,6 +567,24 @@ fi
545567
echo "Database backup complete."
546568
{{- end }}
547569
570+
{{- define "drupal.backup-command.dump-elasticsearch" }}
571+
set -e
572+
573+
if ! command -v multielasticdump &> /dev/null
574+
then
575+
echo "multielasticdump could not be found. Elasticsearch backup failed."
576+
exit 1
577+
fi
578+
579+
# Dump elasticsearch data
580+
echo "Starting Elasticsearch backup."
581+
mkdir /tmp/elasticsearch
582+
multielasticdump --direction=dump --input=http://${ELASTICSEARCH_HOST}:9200/ --output=/tmp/elasticsearch
583+
tar -czf /tmp/elasticsearch.tar.gz -C /tmp/elasticsearch .
584+
585+
echo "Elasticsearch backup complete."
586+
{{- end }}
587+
548588
{{- define "drupal.backup-command.archive-store-backup" -}}
549589
550590
# Compress the database dump and copy it into the backup folder.
@@ -554,6 +594,13 @@ fi
554594
555595
# Create a folder for the backup
556596
mkdir -p $BACKUP_LOCATION
597+
598+
{{- if .Values.elasticsearch.enabled }}
599+
# Copy the elasticsearch dump into the backup folder.
600+
cp /tmp/elasticsearch.tar.gz $BACKUP_LOCATION/
601+
{{- end }}
602+
603+
# Copy the database dump into the backup folder.
557604
cp /tmp/db.sql.gz $BACKUP_LOCATION/db.sql.gz
558605
559606
{{- if not .Values.backup.skipFiles }}

charts/drupal/values.schema.json

+2
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@
448448
"storageClassName": { "type": "string" },
449449
"csiDriverName": { "type": "string" },
450450
"skipMount": { "type": "boolean" },
451+
"elasticsearch": { "type": "boolean" },
451452
"resources": {
452453
"type": "object",
453454
"additionalProperties": false,
@@ -488,6 +489,7 @@
488489
"csiDriverName": { "type": "string" },
489490
"ignoreTableContent": { "type": "string" },
490491
"skipFiles": { "type": "boolean" },
492+
"elasticsearch": { "type": "boolean" },
491493
"resources": {
492494
"type": "object",
493495
"additionalProperties": false,

charts/drupal/values.yaml

+6-2
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,8 @@ referenceData:
450450
- languages
451451
- php
452452

453+
elasticsearch: true
454+
453455
# Files larger than this will not be included in reference data.
454456
maxFileSize: '5M'
455457

@@ -530,8 +532,10 @@ backup:
530532
# These tables will have their content ignored from the backups.
531533
ignoreTableContent: '(cache|cache_.*)'
532534

533-
# Do not backup files
534-
#skipFiles: true
535+
# Do not backup files
536+
skipFiles: false
537+
538+
elasticsearch: true
535539

536540
# Resources for the backup cron job.
537541
resources:

silta/php.Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@ FROM wunderio/silta-php-fpm:8.2-fpm-v1
33

44
COPY --chown=www-data:www-data . /app
55

6+
#####
7+
# Install Elasticdump
8+
RUN apk add npm nodejs && npm install -g elasticdump
9+
#####
10+
611
USER www-data

silta/shell.Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# Dockerfile for the Drupal container.
22
FROM wunderio/silta-php-shell:php8.2-v1
33

4+
#####
5+
# Install Elasticdump (skip when php base image contains it)
6+
RUN apk add npm nodejs && npm install -g elasticdump
7+
#####
8+
49
COPY --chown=www-data:www-data . /app

silta/silta.yml

+13
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,16 @@ php:
5555
# The ~ symbol will be replaced by a random digit from 0 to 9.
5656
# This will avoid running all cron jobs at the same time.
5757
schedule: '~ 0 31 2 *'
58+
59+
backup:
60+
enabled: true
61+
schedule: "*/10 * * * *"
62+
retention: 3
63+
64+
referenceData:
65+
enabled: true
66+
referenceEnvironment: 'feature/esdump'
67+
68+
# TODO: wait for https://github.com/wunderio/silta-images/pull/180
69+
# TODO: remove elasticdump installation from local dockerfiles
70+
# TODO: remove test values

0 commit comments

Comments
 (0)