Skip to content

Commit

Permalink
Merge pull request #5 from nycmeshnet/james/final_updates
Browse files Browse the repository at this point in the history
updates
  • Loading branch information
james-otten authored Nov 6, 2024
2 parents ba51ad2 + 77ae879 commit 5a225a7
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 26 deletions.
78 changes: 64 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,28 @@ gzip < wiki.tar > wiki.tgz

## Restore

1. Create `restore.yaml`
1. Create `restore.db.yaml`

```yaml
apiVersion: batch/v1
kind: Job
metadata:
name: restorejob
name: restorejobdb
namespace: wiki
spec:
template:
spec:
containers:
- name: restorejob
- name: restorejobdb
image: lscr.io/linuxserver/mariadb
command:
- /bin/bash
- /restore.sh
- /restore.db.sh
volumeMounts:
- name: backup-script
mountPath: /restore.sh
subPath: restore.sh
mountPath: /restore.db.sh
subPath: restore.db.sh
readOnly: true
- name: config-vol
mountPath: /config
- name: image-uploads-vol
mountPath: /app/www/public/img
env:
- name: RESTORE_S3_URL
value: "s3://.../backups/wiki.tgz"
Expand Down Expand Up @@ -81,8 +77,57 @@ spec:
configMap:
name: backup-script
items:
- key: restore.sh
path: restore.sh
- key: restore.db.sh
path: restore.db.sh
```
2. Create `restore.files.yaml`

```yaml
apiVersion: batch/v1
kind: Job
metadata:
name: restorejobfiles
namespace: wiki
spec:
template:
spec:
containers:
- name: restorejobfiles
image: lscr.io/linuxserver/bookstack:v23.02.2-ls71
command:
- /bin/bash
- /restore.files.sh
volumeMounts:
- name: backup-script
mountPath: /restore.files.sh
subPath: restore.files.sh
readOnly: true
- name: config-vol
mountPath: /config
- name: image-uploads-vol
mountPath: /app/www/public/img
env:
- name: RESTORE_S3_URL
value: "s3://.../backups/wiki.tgz"
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: wiki-secrets
key: access-key-id
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: wiki-secrets
key: secret-access-key
restartPolicy: OnFailure
volumes:
- name: backup-script
configMap:
name: backup-script
items:
- key: restore.files.sh
path: restore.files.sh
- name: config-vol
persistentVolumeClaim:
claimName: wikiconfig
Expand All @@ -91,14 +136,19 @@ spec:
claimName: wikiimages
```

2. Run the restore job
2. Run the restore jobs

```
kubectl scale --replicas=0 deployment.apps/wiki-bookstack-helm-bookstack -n wiki
kubectl apply -f restore.yaml
kubectl apply -f restore.files.yaml
# wait for it to complete
kubectl get all -n wiki
kubectl scale --replicas=1 deployment.apps/wiki-bookstack-helm-bookstack -n wiki

kubectl apply -f restore.db.yaml
# wait for it to complete
kubectl get all -n wiki
kubectl scale --replicas=1 deployment.apps/wiki-bookstack-helm-db -n wiki
```
3. If the url is changing, you may need the following:
Expand Down
14 changes: 7 additions & 7 deletions bookstack-helm/templates/backup.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: backupjob
name: backupjob-db
namespace: {{ .Values.meshwiki_app_namespace }}
spec:
schedule: {{ .Values.bookstack.backup.cron_schedule | quote }}
Expand All @@ -11,16 +11,16 @@ spec:
spec:
restartPolicy: OnFailure
containers:
- name: backupjob
- name: backupjob-db
image: "{{ .Values.db_image.repository }}:{{ .Values.db_image.tag }}"
imagePullPolicy: {{ .Values.db_image.pullPolicy }}
command:
- /bin/bash
- /backup.sh
- /backup.db.sh
volumeMounts:
- name: backup-script
mountPath: /backup.sh
subPath: backup.sh
mountPath: /backup.db.sh
subPath: backup.db.sh
readOnly: true
env:
- name: DB_HOST
Expand Down Expand Up @@ -63,5 +63,5 @@ spec:
configMap:
name: backup-script
items:
- key: backup.sh
path: backup.sh
- key: backup.db.sh
path: backup.db.sh
47 changes: 47 additions & 0 deletions bookstack-helm/templates/backupfiles.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: backupjob-files
namespace: {{ .Values.meshwiki_app_namespace }}
spec:
schedule: {{ .Values.bookstack.backup.cron_schedule | quote }}
jobTemplate:
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: backupjob-files
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- /bin/bash
- /backup.files.sh
volumeMounts:
- name: backup-script
mountPath: /backup.files.sh
subPath: backup.files.sh
readOnly: true
env:
- name: BACKUP_S3_URL
valueFrom:
secretKeyRef:
name: wiki-secrets
key: backup-s3-url
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: wiki-secrets
key: access-key-id
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: wiki-secrets
key: secret-access-key
volumes:
- name: backup-script
configMap:
name: backup-script
items:
- key: backup.files.sh
path: backup.files.sh
30 changes: 25 additions & 5 deletions bookstack-helm/templates/backupscript.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@ metadata:
name: backup-script
namespace: {{ .Values.meshwiki_app_namespace }}
data:
backup.sh: |
backup.db.sh: |
echo "Dumping db"
mysqldump -h "$DB_HOST" -u "$DB_USER" --password="$DB_PASS" "$DB_DATABASE" > wiki.sql
echo "Creating tarball"
backup_name="wiki_backup_$(date +%s).tar.gz"
tar -chzvf $backup_name wiki.sql /app/www/public/uploads/ /app/www/storage/uploads/ /app/www/public/img/
backup_name="wiki_backup_db_$(date +%s).tar.gz"
tar -chzvf $backup_name wiki.sql
echo "push to s3"
apk add aws-cli
aws s3 cp ./$backup_name "$BACKUP_S3_URL"
echo "done"
restore.sh: |
backup.files.sh: |
echo "Creating tarball"
backup_name="wiki_backup_files_$(date +%s).tar.gz"
tar -chzvf $backup_name /app/www/public/uploads/ /app/www/storage/uploads/ /app/www/public/img/
echo "push to s3"
apk add aws-cli
aws s3 cp ./$backup_name "$BACKUP_S3_URL"
echo "done"
restore.db.sh: |
echo "Checking if restore is needed"
echo "Restore file is: $RESTORE_S3_URL"
if [ ! -z "$RESTORE_S3_URL" ]; then
Expand All @@ -23,9 +31,21 @@ data:
aws s3 cp "$RESTORE_S3_URL" /tmp/restore.tgz
echo "downloaded tarball"
tar -xzf /tmp/restore.tgz -C /
echo "Files restored"
mysql -h "$DB_HOST" -u "$DB_USER" --password="$DB_PASS" $DB_DATABASE < /wiki.sql
else
echo "Not restoring"
fi
echo "done"
restore.files.sh: |
echo "Checking if restore is needed"
echo "Restore file is: $RESTORE_S3_URL"
if [ ! -z "$RESTORE_S3_URL" ]; then
echo "Restoring from $RESTORE_S3_URL"
apk add aws-cli
aws s3 cp "$RESTORE_S3_URL" /tmp/restore.tgz
echo "downloaded tarball"
tar -xzf /tmp/restore.tgz -C /
else
echo "Not restoring"
fi
echo "done"

0 comments on commit 5a225a7

Please sign in to comment.