Skip to content

Commit 3703b73

Browse files
authored
Merge pull request #42 - setup backup for torchlite dashboard mongodb
33 setup backup for torchlite dashboard mongodb
2 parents 2b48157 + 06a6210 commit 3703b73

File tree

9 files changed

+87
-4
lines changed

9 files changed

+87
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Kubernetes manifest files for running EF-API in the production instance. [#72](https://github.com/htrc/torchlite-app/issues/72)
1313
- Credentials for mutual TLS with registry to all torchlite-backend deployments to support direct communication when getting worksets. [#125](https://github.com/htrc/torchlite-backend/issues/125)
1414
- Google Analytics ID to production [#156](https://github.com/htrc/torchlite-frontend/issues/156)
15+
- Add cron job for setting up mongodb backup in all TORCHLITE instances. [#33](https://github.com/htrc/torchlite-argocd/issues/33)
1516

1617
### Changed
1718
- Backend cache expiration time in the development instance to 3600 seconds (1 hour). [#7](https://github.com/htrc/torchlite-argocd/issues/7)

torchlite-mongodb-backup-prod.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: Application
3+
metadata:
4+
name: torchlite-mongodb-backup-prod-argocd-app
5+
namespace: argocd
6+
labels:
7+
env: prod
8+
annotations:
9+
notifications.argoproj.io/subscribe.on-deployed.slack: torchlite
10+
notifications.argoproj.io/subscribe.on-health-degraded.slack: torchlite
11+
spec:
12+
project: default
13+
14+
source:
15+
repoURL: https://github.com/htrc/torchlite-argocd.git
16+
targetRevision: main
17+
path: torchlite-mongodb-backup/prod
18+
destination:
19+
server: https://kubernetes.default.svc
20+
namespace: torchlite-prod
21+
22+
syncPolicy:
23+
syncOptions:
24+
- CreateNamespace=true
25+
26+
automated:
27+
selfHeal: true
28+
prune: true

torchlite-mongodb-backup/dev/cronjob.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ spec:
2929
volumes:
3030
- name: backup-storage
3131
persistentVolumeClaim:
32-
claimName: mongodb-backup-pvc
32+
claimName: mongodb-backup-dev-pvc

torchlite-mongodb-backup/dev/pv.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v1
22
kind: PersistentVolume
33
metadata:
4-
name: mongodb-backup-pv
4+
name: mongodb-backup-dev-pv
55
spec:
66
capacity:
77
storage: 100Gi # 2 times the size of the dev mongodb persistent volume as we will be retaining the most recent 2 backups in the backup volume

torchlite-mongodb-backup/dev/pvc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v1
22
kind: PersistentVolumeClaim
33
metadata:
4-
name: mongodb-backup-pvc
4+
name: mongodb-backup-dev-pvc
55
spec:
66
accessModes:
77
- ReadWriteOnce
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: batch/v1
2+
kind: CronJob
3+
metadata:
4+
name: mongodb-backup
5+
spec:
6+
schedule: "00 05 * * *" # Runs backup every day at 5:00 AM
7+
jobTemplate:
8+
spec:
9+
template:
10+
spec:
11+
containers:
12+
- name: mongodump
13+
image: quay.io/mongodb/mongodb-community-server:6.0.5-ubi8
14+
command:
15+
- sh
16+
- -c
17+
- |
18+
# Perform backup
19+
mongodump --host=mongodb-svc -u torchlite -p $password --port=27017 --out=/backup/$(date +\%Y-\%m-\%dT\%H-\%M-\%S)
20+
# Remove backups older than 7 days
21+
find /backup -type d -mtime +7 -exec rm -rf {} +
22+
envFrom:
23+
- secretRef:
24+
name: mongodb-admin-torchlite
25+
volumeMounts:
26+
- name: backup-storage
27+
mountPath: /backup
28+
restartPolicy: OnFailure
29+
volumes:
30+
- name: backup-storage
31+
persistentVolumeClaim:
32+
claimName: mongodb-backup-prod-pvc
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: PersistentVolume
3+
metadata:
4+
name: mongodb-backup-prod-pv
5+
spec:
6+
capacity:
7+
storage: 700Gi # 7 times the size of the prod mongodb persistent volume as we will be retaining 7 days of backups in the backup volume
8+
accessModes:
9+
- ReadWriteOnce
10+
hostPath:
11+
path: /mnt/mongodb-backup
12+
type: DirectoryOrCreate
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: PersistentVolumeClaim
3+
metadata:
4+
name: mongodb-backup-prod-pvc
5+
spec:
6+
accessModes:
7+
- ReadWriteOnce
8+
resources:
9+
requests:
10+
storage: 700Gi # 7 times the size of the prod mongodb persistent volume as we will be retaining 7 days of backups in the backup volume

torchlite-mongodb-backup/stage/cronjob.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: CronJob
33
metadata:
44
name: mongodb-backup
55
spec:
6-
schedule: "*/5 * * * *" # Test stage backup.
6+
schedule: "00 04 15 * *" # Run at 4:00 AM on the 15th of every month
77
jobTemplate:
88
spec:
99
template:

0 commit comments

Comments
 (0)