diff --git a/backup/.gitignore b/backup/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/backup/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/helmfile/environments/production.yaml.gotmpl b/helmfile/environments/production.yaml.gotmpl index 46924d6..a51bf7b 100644 --- a/helmfile/environments/production.yaml.gotmpl +++ b/helmfile/environments/production.yaml.gotmpl @@ -2,7 +2,7 @@ #{{ $ocelot_image_tag := env "OCELOT_IMAGE_TAG" | default (exec "../scripts/ocelot_image_tag.sh" (list) | trim) }} {{ $image_tag := env "IMAGE_TAG" | default (exec "../scripts/branded_image_tag.sh" (list) | trim) }} -domain: wir-social-production.ocelot-social-production.it4c.org +domain: wir.social namespace: wir-social-ocelot-production #image_tag: {{ env "IMAGE_TAG" | default (printf "ocelot-%s--branded-%s" $ocelot_image_tag $branded_image_tag) }} image_tag: {{ $image_tag }} diff --git a/patches/patch.ingress.maintenance.off.yaml b/patches/patch.ingress.maintenance.off.yaml new file mode 100644 index 0000000..cb144f0 --- /dev/null +++ b/patches/patch.ingress.maintenance.off.yaml @@ -0,0 +1,12 @@ +spec: + rules: + - host: + http: + paths: + - path: / + pathType: ImplementationSpecific + backend: + service: + name: wir-social-webapp + port: + number: 3000 \ No newline at end of file diff --git a/patches/patch.ingress.maintenance.on.yaml b/patches/patch.ingress.maintenance.on.yaml new file mode 100644 index 0000000..0aebd57 --- /dev/null +++ b/patches/patch.ingress.maintenance.on.yaml @@ -0,0 +1,12 @@ +spec: + rules: + - host: + http: + paths: + - path: / + pathType: ImplementationSpecific + backend: + service: + name: wir-social-maintenance + port: + number: 80 \ No newline at end of file diff --git a/scripts/maintenance.sh b/scripts/maintenance.sh new file mode 100755 index 0000000..a676626 --- /dev/null +++ b/scripts/maintenance.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# base setup +SCRIPT_PATH=$(realpath $0) +SCRIPT_DIR=$(dirname $SCRIPT_PATH) + +case $1 in + on) + echo "Network maintenance: on" + kubectl patch --namespace=wir-social-ocelot-production ingress wir-social --type merge --patch-file ${SCRIPT_DIR}/../patches/patch.ingress.maintenance.on.yaml + ;; + off) + echo "Network maintenance: off" + kubectl patch --namespace=wir-social-ocelot-production ingress wir-social --type merge --patch-file ${SCRIPT_DIR}/../patches/patch.ingress.maintenance.off.yaml + ;; + *) + echo -e "Run this script with first argument either 'on' or 'off'" + exit + ;; +esac \ No newline at end of file diff --git a/scripts/neo4j.sh b/scripts/neo4j.sh new file mode 100755 index 0000000..cc34aef --- /dev/null +++ b/scripts/neo4j.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# base setup +SCRIPT_PATH=$(realpath $0) +SCRIPT_DIR=$(dirname $SCRIPT_PATH) + +case $1 in + on) + # set Neo4j in offline mode (maintenance) + echo "Neo4j maintenance: on" + kubectl get --namespace=wir-social-ocelot-production statefulset ocelot-neo4j-neo4j -o json \ + | jq '.spec.template.spec.containers[] += {"command": ["tail", "-f", "/dev/null"]}' \ + | kubectl apply -f - + + # wait for the container to restart + echo "Wait 60s ..." + sleep 60 + ;; + off) + # set Neo4j in online mode + echo "Neo4j maintenance: off" + kubectl get --namespace=wir-social-ocelot-production statefulset ocelot-neo4j-neo4j -o json \ + | jq 'del(.spec.template.spec.containers[].command)' \ + | kubectl apply -f - + + # wait for the container to restart + echo "Wait 60s ..." + sleep 60 + ;; + *) + echo -e "Run this script with first argument either 'off' or 'on'" + exit + ;; +esac diff --git a/scripts/restore.sh b/scripts/restore.sh new file mode 100755 index 0000000..5492c61 --- /dev/null +++ b/scripts/restore.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +# base setup +SCRIPT_PATH=$(realpath $0) +SCRIPT_DIR=$(dirname $SCRIPT_PATH) + +# configuration +BACKUP_DATE="2024-12-04_09-39-10" +BACKUP_FOLDER=${BACKUP_FOLDER:-${SCRIPT_DIR}/../backup/${BACKUP_DATE}} + +printf "Backup folder: %s\n" $BACKUP_FOLDER + +${SCRIPT_DIR}/maintenance.sh on +${SCRIPT_DIR}/neo4j.sh on + +# copy neo4j backup from local drive +echo "Copying database from local file system ..." +kubectl cp \ + $BACKUP_FOLDER/neo4j-dump \ + wir-social-ocelot-production/$(kubectl --namespace=wir-social-ocelot-production get pods | grep ocelot-neo4j |awk '{ print $1 }'):/var/lib/neo4j/$BACKUP_DATE-neo4j-dump + +# copy image data +echo "Copying public uploads to local file system ..." +kubectl cp \ + $BACKUP_FOLDER/public-uploads/. \ + wir-social-ocelot-production/$(kubectl --namespace=wir-social-ocelot-production get pods | grep wir-social-backend |awk '{ print $1 }'):/app/public/uploads/ + +# restore database +echo "Restoring Database ..." +kubectl --namespace=wir-social-ocelot-production exec -it \ + $(kubectl --namespace=wir-social-ocelot-production get pods | grep ocelot-neo4j | awk '{ print $1 }') \ + -- neo4j-admin load --from=/var/lib/neo4j/$BACKUP_DATE-neo4j-dump --force + +${SCRIPT_DIR}/neo4j.sh off +${SCRIPT_DIR}/maintenance.sh off \ No newline at end of file