forked from kanisterio/kanister
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongo-blueprint.yaml
78 lines (78 loc) · 2.85 KB
/
mongo-blueprint.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
apiVersion: cr.kanister.io/v1alpha1
kind: Blueprint
metadata:
name: mongodb-blueprint
actions:
backup:
outputArtifacts:
cloudObject:
keyValue:
path: '/mongodb-replicaset-backups/{{ .StatefulSet.Name }}/{{ toDate "2006-01-02T15:04:05.999999999Z07:00" .Time | date "2006-01-02T15-04-05" }}/rs_backup.gz'
phases:
- func: KubeTask
name: takeConsistentBackup
objects:
mongosecret:
kind: Secret
name: '{{ .StatefulSet.Name }}'
namespace: "{{ .StatefulSet.Namespace }}"
args:
namespace: "{{ .StatefulSet.Namespace }}"
image: ghcr.io/kanisterio/mongodb:0.85.0
command:
- bash
- -o
- errexit
- -o
- pipefail
- -c
- |
host='{{ .StatefulSet.Name }}-0.{{ .StatefulSet.Name }}-headless.{{ .StatefulSet.Namespace }}.svc.cluster.local'
dbPassword='{{ index .Phases.takeConsistentBackup.Secrets.mongosecret.Data "mongodb-root-password" | toString }}'
dump_cmd="mongodump --oplog --gzip --archive --host ${host} -u root -p ${dbPassword}"
${dump_cmd} | kando location push --profile '{{ toJson .Profile }}' --path '/mongodb-replicaset-backups/{{ .StatefulSet.Name }}/{{ toDate "2006-01-02T15:04:05.999999999Z07:00" .Time | date "2006-01-02T15-04-05" }}/rs_backup.gz' -
restore:
inputArtifactNames:
- cloudObject
phases:
- func: KubeTask
name: pullFromBlobStore
objects:
mongosecret:
kind: Secret
name: '{{ .StatefulSet.Name }}'
namespace: "{{ .StatefulSet.Namespace }}"
args:
namespace: "{{ .StatefulSet.Namespace }}"
image: ghcr.io/kanisterio/mongodb:0.85.0
command:
- bash
- -o
- errexit
- -o
- pipefail
- -c
- |
host='{{ .StatefulSet.Name }}-0.{{ .StatefulSet.Name }}-headless.{{ .StatefulSet.Namespace }}.svc.cluster.local'
dbPassword='{{ index .Phases.pullFromBlobStore.Secrets.mongosecret.Data "mongodb-root-password" | toString }}'
restore_cmd="mongorestore --gzip --archive --oplogReplay --drop --host ${host} -u root -p ${dbPassword}"
kando location pull --profile '{{ toJson .Profile }}' --path '{{ .ArtifactsIn.cloudObject.KeyValue.path }}' - | ${restore_cmd}
delete:
inputArtifactNames:
- cloudObject
phases:
- func: KubeTask
name: deleteFromBlobStore
args:
namespace: "{{ .Namespace.Name }}"
image: ghcr.io/kanisterio/mongodb:0.85.0
command:
- bash
- -o
- errexit
- -o
- pipefail
- -c
- |
s3_path="{{ .ArtifactsIn.cloudObject.KeyValue.path }}"
kando location delete --profile '{{ toJson .Profile }}' --path ${s3_path}