Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elasticdump for elasticsearch data backup #705

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 50 additions & 3 deletions charts/drupal/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,18 @@ wait
{{- end }}
{{- end }}

{{ if .Values.elasticsearch.enabled }}
{{ include "drupal.wait-for-elasticsearch-command" . }}
{{ end }}
{{- if .Values.elasticsearch.enabled }}
{{- include "drupal.wait-for-elasticsearch-command" . }}
{{- if and .Release.IsInstall .Values.referenceData.elasticsearch }}
if [[ -f /app/reference-data/elasticsearch.tar.gz || -f /app/reference-data/elasticsearch.tar.gz ]]; then
echo "Importing elasticsearch reference data"
mkdir /tmp/elasticsearch
tar -xzf /app/reference-data/elasticsearch.tar.gz -C /tmp/elasticsearch
multielasticdump --direction=load --input=/tmp/elasticsearch --output=http://${ELASTICSEARCH_HOST}:9200/
echo "Elasticsearch reference data imported"
fi
{{- end }}
{{- end }}

{{ if .Release.IsInstall }}
{{ .Values.php.postinstall.command }}
Expand All @@ -435,6 +444,7 @@ wait
{{- define "drupal.extract-reference-data" -}}
set -e
if [[ "$(drush status --fields=bootstrap)" = *'Successful'* ]] ; then

echo "Dump reference database."
dump_dir=/tmp/reference-data-export/
mkdir "${dump_dir}"
Expand Down Expand Up @@ -502,6 +512,15 @@ if [[ "$(drush status --fields=bootstrap)" = *'Successful'* ]] ; then
/app/reference-data/{{ $index }}
{{ end -}}
{{- end }}

{{- if .Values.referenceData.elasticsearch }}
echo "Creating reference data for elasticsearch"
mkdir /tmp/elasticsearch
multielasticdump --direction=dump --input=http://${ELASTICSEARCH_HOST}:9200/ --output=/tmp/elasticsearch
tar -czf /tmp/elasticsearch.tar.gz -C /tmp/elasticsearch .
cp /tmp/elasticsearch.tar.gz /app/reference-data
{{- end }}

else
echo "Drupal bootstrap unsuccessful, skipping reference database dump."
fi
Expand Down Expand Up @@ -559,6 +578,9 @@ fi

{{- define "drupal.backup-command" -}}
{{ include "drupal.backup-command.dump-database" . }}
{{- if and .Values.elasticsearch.enabled .Values.backup.elasticsearch }}
{{- include "drupal.backup-command.dump-elasticsearch" . }}
{{- end }}
{{ include "drupal.backup-command.archive-store-backup" . }}
{{- end }}

Expand All @@ -585,6 +607,24 @@ fi
echo "Database backup complete."
{{- end }}

{{- define "drupal.backup-command.dump-elasticsearch" }}
set -e

if ! command -v multielasticdump &> /dev/null
then
echo "multielasticdump could not be found. Elasticsearch backup failed."
exit 1
fi

# Dump elasticsearch data
echo "Starting Elasticsearch backup."
mkdir /tmp/elasticsearch
multielasticdump --direction=dump --input=http://${ELASTICSEARCH_HOST}:9200/ --output=/tmp/elasticsearch
tar -czf /tmp/elasticsearch.tar.gz -C /tmp/elasticsearch .

echo "Elasticsearch backup complete."
{{- end }}

{{- define "drupal.backup-command.archive-store-backup" -}}

# Compress the database dump and copy it into the backup folder.
Expand All @@ -594,6 +634,13 @@ fi

# Create a folder for the backup
mkdir -p $BACKUP_LOCATION

{{- if .Values.elasticsearch.enabled }}
# Copy the elasticsearch dump into the backup folder.
cp /tmp/elasticsearch.tar.gz $BACKUP_LOCATION/
{{- end }}

# Copy the database dump into the backup folder.
cp /tmp/db.sql.gz $BACKUP_LOCATION/db.sql.gz

{{- if not .Values.backup.skipFiles }}
Expand Down
2 changes: 2 additions & 0 deletions charts/drupal/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@
"storageClassName": { "type": "string" },
"csiDriverName": { "type": "string" },
"skipMount": { "type": "boolean" },
"elasticsearch": { "type": "boolean" },
"resources": {
"type": "object",
"additionalProperties": false,
Expand Down Expand Up @@ -518,6 +519,7 @@
"csiDriverName": { "type": "string" },
"ignoreTableContent": { "type": "string" },
"skipFiles": { "type": "boolean" },
"elasticsearch": { "type": "boolean" },
"resources": {
"type": "object",
"additionalProperties": false,
Expand Down
8 changes: 6 additions & 2 deletions charts/drupal/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ referenceData:
- languages
- php

elasticsearch: true

# Files larger than this will not be included in reference data.
maxFileSize: '5M'

Expand Down Expand Up @@ -535,8 +537,10 @@ backup:
# These tables will have their content ignored from the backups.
ignoreTableContent: '(cache|cache_.*)'

# Do not backup files
#skipFiles: true
# Do not backup files
skipFiles: false

elasticsearch: true

# Resources for the backup cron job.
resources:
Expand Down