wir.social domain, restore script

This commit is contained in:
Ulf Gebhardt 2024-12-04 14:13:49 +01:00
parent 51076e21dd
commit 8731547afb
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
7 changed files with 116 additions and 1 deletions

2
backup/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -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 }}

View File

@ -0,0 +1,12 @@
spec:
rules:
- host:
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: wir-social-webapp
port:
number: 3000

View File

@ -0,0 +1,12 @@
spec:
rules:
- host:
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: wir-social-maintenance
port:
number: 80

20
scripts/maintenance.sh Executable file
View File

@ -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

34
scripts/neo4j.sh Executable file
View File

@ -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

35
scripts/restore.sh Executable file
View File

@ -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