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

(ISSUE 196) - added neo4j backup cron pod #281

Merged
merged 10 commits into from
Feb 13, 2020
2 changes: 1 addition & 1 deletion amundsen-kube-helm/templates/helm/neo4j/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: neo4j
home: https://www.neo4j.com
appVersion: 3.3.0
version: 0.1.0
version: 0.2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{{ if and (and .Values.neo4j.backup.enabled (eq .Values.provider "aws")) (or (kindIs "invalid" .Values.neo4jpvc) .Values.neo4jpvc) }}
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: neo4j-s3-backup
spec:
schedule: {{ .Values.neo4j.backup.schedule }}
jobTemplate:
spec:
template:
spec:
containers:
- name: backup-neo4j
image: mesosphere/aws-cli:latest
command:
- "/bin/sh"
- "-c"
- |
apk -v --update add --no-cache --quiet curl
NOW="$(date "+%Y-%m-%d-%H:%M:%S")"
BACKUP_SCHEMA_NAME="graph.db-backup-$NOW.schema"
BACKUP_DATA_NAME="graph.db-backup-$NOW.data"
BACKUP_NAME="graph.db-backup-$NOW"
curl --user neo4j:test -H accept:application/json -H content-type:application/json \
-d '{"statements":[{"statement":"CALL apoc.export.cypher.schema(\"\/var\/lib\/neo4j\/data\/'$BACKUP_SCHEMA_NAME'\", {})"}]}' \
http://neo4j:7474/db/data/transaction/commit
curl --user neo4j:test -H accept:application/json -H content-type:application/json \
-d '{"statements":[{"statement":"CALL apoc.export.graphml.all(\"\/var\/lib\/neo4j\/data\/'$BACKUP_DATA_NAME'\", {useTypes: true, readLabels: true})"}]}' \
http://neo4j:7474/db/data/transaction/commit
printf "\nWaiting for APOC export..."
while [ ! -f /var/lib/neo4j/data/$BACKUP_DATA_NAME ]; do echo "backup data file does not exist, sleeping: /var/lib/neo4j/data/$BACKUP_DATA_NAME" && sleep 5; done
printf "\nTarring -> /var/lib/neo4j/data/$BACKUP_SCHEMA_NAME and /var/lib/neo4j/data/$BACKUP_DATA_NAME to /var/lib/neo4j/data/$BACKUP_NAME.tar"
tar -cvf "/var/lib/neo4j/data/$BACKUP_NAME.tar" -C "/var/lib/neo4j/data/" $BACKUP_SCHEMA_NAME $BACKUP_DATA_NAME
printf "Zipping -> /var/lib/neo4j/data/$BACKUP_NAME.tar.gz\n"
gzip -9 "/var/lib/neo4j/data/$BACKUP_NAME.tar"
printf "Zipped backup size:"
du -hs "/var/lib/neo4j/data/$BACKUP_NAME.tar.gz"
printf "Pushing /var/lib/neo4j/data/$BACKUP_NAME.tar.gz -> $BUCKET"
aws s3 cp "/var/lib/neo4j/data/$BACKUP_NAME.tar.gz" "$BUCKET"
printf "Cleaning up /var/lib/neo4j/data/graph.db-backup*"
rm /var/lib/neo4j/data/graph.db-backup*
env:
- name: BUCKET
value: {{ .Values.neo4j.backup.s3Path }}
volumeMounts:
- name: data
mountPath: /var/lib/neo4j/data
restartPolicy: Never
volumes:
- name: data
persistentVolumeClaim:
claimName: neo4j-pvc
{{- end}}
5 changes: 5 additions & 0 deletions amundsen-kube-helm/templates/helm/neo4j/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ config:
heap_initial_size: 23000m
heap_max_size: 23000m
pagecache_size: 26600m
neo4j:
backup:
enabled: false
s3Path: "s3://my-bucket/my-prefix"
schedule: "0 * * * *"