-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backup job script for single wiki (#1766)
Bug: T365443 Co-authored-by: Deniz Erdogan <[email protected]> Co-authored-by: Thomas Arrow <[email protected]>
- Loading branch information
1 parent
d08d2a1
commit 3e27137
Showing
6 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
|
||
# DATABASE_NAME should be set to the database to backup | ||
|
||
if [[ -z "$DATABASE_NAME" ]]; then | ||
echo "DATABASE_NAME not set" | ||
exit 1 | ||
fi | ||
|
||
# This creates the PVC (if it doesn't exist) for backups to be saved to | ||
# It will not be automatically deleted so you may need to clean this up when you are done | ||
kubectl apply -f singleWikiBackupPvc.yaml | ||
|
||
kubectl create -f singleWikiBackup.yaml -o=json --dry-run=client |\ | ||
jq ".spec.template.spec.containers[0].env += [{\"name\": \"DATABASE_NAME\", \"value\": \"${DATABASE_NAME}\"}]" |\ | ||
kubectl create -f - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
generateName: backup-single-wiki- | ||
namespace: adhoc-jobs | ||
spec: | ||
ttlSecondsAfterFinished: 604800 #7days | ||
template: | ||
metadata: | ||
name: backup-single-wiki | ||
spec: | ||
volumes: | ||
- name: temporary-backup-pvc | ||
persistentVolumeClaim: | ||
claimName: temporary-backup-pvc | ||
containers: | ||
- name: backup-single-wiki | ||
env: | ||
- name: MYSQL_PWD | ||
valueFrom: | ||
secretKeyRef: | ||
name: sql-secrets-passwords | ||
key: mariadb-root-password | ||
image: mariadb:10.5 | ||
|
||
command: | ||
- 'bash' | ||
- '-c' | ||
- | | ||
mysqldump --verbose \ | ||
--host sql-mariadb-primary.default.svc.cluster.local \ | ||
${DATABASE_NAME} \ | ||
> /backup/${DATABASE_NAME}.sql | ||
volumeMounts: | ||
- name: temporary-backup-pvc | ||
mountPath: "/backup/" | ||
|
||
restartPolicy: OnFailure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: temporary-backup-pvc | ||
namespace: adhoc-jobs | ||
spec: | ||
storageClassName: standard | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 3Gi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
# DATABASE_NAME should be set to the database to restore | ||
|
||
if [[ -z "$DATABASE_NAME" ]]; then | ||
echo "DATABASE_NAME not set" | ||
exit 1 | ||
fi | ||
|
||
kubectl create -f singleWikiRestore.yaml -o=json --dry-run=client |\ | ||
jq ".spec.template.spec.containers[0].env += [{\"name\": \"DATABASE_NAME\", \"value\": \"${DATABASE_NAME}\"}]" |\ | ||
kubectl create -f - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
generateName: restore-single-wiki- | ||
namespace: adhoc-jobs | ||
spec: | ||
ttlSecondsAfterFinished: 604800 #7days | ||
template: | ||
metadata: | ||
name: restore-single-wiki | ||
spec: | ||
volumes: | ||
- name: temporary-backup-pvc | ||
persistentVolumeClaim: | ||
claimName: temporary-backup-pvc | ||
containers: | ||
- name: restore-single-wiki | ||
env: | ||
- name: MYSQL_PWD | ||
valueFrom: | ||
secretKeyRef: | ||
name: sql-secrets-passwords | ||
key: mariadb-root-password | ||
image: mariadb:10.5 | ||
|
||
command: | ||
- 'bash' | ||
- '-c' | ||
- | | ||
mysql --show-warnings \ | ||
--host sql-mariadb-primary.default.svc.cluster.local \ | ||
${DATABASE_NAME} \ | ||
< /backup/${DATABASE_NAME}.sql | ||
if [[ $? == 0 ]]; then | ||
echo "SQL import successful" | ||
else | ||
echo "Error while importing SQL" | ||
fi | ||
volumeMounts: | ||
- name: temporary-backup-pvc | ||
mountPath: "/backup/" | ||
|
||
restartPolicy: OnFailure |