forked from kanisterio/kanister
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cassandra-blueprint.yaml
183 lines (183 loc) · 6.73 KB
/
cassandra-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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
apiVersion: cr.kanister.io/v1alpha1
kind: Blueprint
metadata:
name: cassandra-blueprint
actions:
backup:
outputArtifacts:
params:
keyValue:
backupPrefixLocation: "{{ .Phases.getBackupPrefixLocation.Output.backupPrefixLocation }}"
snapshotPrefix: "{{ .Phases.getBackupPrefixLocation.Output.localSnapshotPrefixLocation }}"
replicaCount: "{{ .Phases.getBackupPrefixLocation.Output.replicaCount }}"
backupInfo: "{{ .Phases.backupToObjectStore.Output.BackupAllInfo }}"
restorePathPrefix: "/"
phases:
- func: KubeExecAll
name: getBackupPrefixLocation
args:
namespace: "{{ .StatefulSet.Namespace }}"
pods: "{{ range .StatefulSet.Pods }} {{.}}{{end}}"
containers: "cassandra"
command:
- bash
- -o
- errexit
- -o
- xtrace
- -o
- pipefail
- -c
- |
BACKUP_PREFIX_LOCATION={{ .Profile.Location.Bucket }}/cassandra_backups/{{ .StatefulSet.Namespace }}/{{ .StatefulSet.Name }}
LOCAL_SNAPSHOT_PREFIX_LOCATION=/bitnami/cassandra/cassandra_data/kanister_backups
kando output backupPrefixLocation $BACKUP_PREFIX_LOCATION
kando output localSnapshotPrefixLocation $LOCAL_SNAPSHOT_PREFIX_LOCATION
kando output replicaCount {{ len .StatefulSet.Pods }}
- func: KubeExecAll
name: takeSnapshots
args:
namespace: "{{ .StatefulSet.Namespace }}"
pods: "{{ range .StatefulSet.Pods }} {{.}}{{end}}"
containers: "cassandra"
command:
- bash
- -o
- errexit
- -o
- xtrace
- -o
- pipefail
- -c
- |
nodetool cleanup
nodetool clearsnapshot
nodetool snapshot -t ${HOSTNAME}
snapshot_prefix="{{ .Phases.getBackupPrefixLocation.Output.localSnapshotPrefixLocation }}"
mkdir -p ${snapshot_prefix}/${HOSTNAME}
cd /bitnami/cassandra/data/data/
if [ -n "$(ls -A | grep -v -w "system" | grep -v -w "system_traces")" ]
then
cp -r `ls -A | grep -v -w "system" | grep -v -w "system_traces"` ${snapshot_prefix}/${HOSTNAME}/
cd ${snapshot_prefix}/${HOSTNAME}/
cqlsh -u cassandra -p $CASSANDRA_PASSWORD -e "DESCRIBE SCHEMA" > schema.cql
fi
nodetool clearsnapshot
- func: BackupDataAll
name: backupToObjectStore
args:
namespace: "{{ .StatefulSet.Namespace }}"
pods: "{{ range .StatefulSet.Pods }} {{.}}{{end}}"
container: "cassandra"
includePath: "{{ .Phases.getBackupPrefixLocation.Output.localSnapshotPrefixLocation }}"
backupArtifactPrefix: "{{ .Phases.getBackupPrefixLocation.Output.backupPrefixLocation }}"
- func: KubeExec
name: deleteLocalBackup
args:
namespace: "{{ .StatefulSet.Namespace }}"
pod: "{{ index .StatefulSet.Pods 0}}"
command:
- bash
- -o
- errexit
- -o
- xtrace
- -o
- pipefail
- -c
- |
rm -rf {{ .Phases.getBackupPrefixLocation.Output.localSnapshotPrefixLocation }}
restore:
inputArtifactNames:
- params
phases:
- func: ScaleWorkload
name: shutdownPod
args:
namespace: "{{ .StatefulSet.Namespace }}"
name: "{{ .StatefulSet.Name }}"
kind: StatefulSet
replicas: 0
- func: RestoreDataAll
name: restoreFromObjectStore
args:
namespace: "{{ .StatefulSet.Namespace }}"
image: ghcr.io/kanisterio/kanister-tools:0.85.0
backupArtifactPrefix: "{{ .ArtifactsIn.params.KeyValue.backupPrefixLocation }}"
pods: "{{ range .StatefulSet.Pods }} {{.}}{{end}}"
restorePath: "{{ .ArtifactsIn.params.KeyValue.restorePathPrefix }}"
backupInfo: "{{ .ArtifactsIn.params.KeyValue.backupInfo }}"
- func: ScaleWorkload
name: bringupPod
args:
namespace: "{{ .StatefulSet.Namespace }}"
name: "{{ .StatefulSet.Name }}"
kind: StatefulSet
replicas: "{{ .ArtifactsIn.params.KeyValue.replicaCount }}"
- func: KubeExec
name: restoreSnapshot
args:
namespace: "{{ .StatefulSet.Namespace }}"
pod: "{{ index .StatefulSet.Pods 0 }}"
command:
- bash
- -o
- xtrace
- -o
- pipefail
- -o
- errexit
- -c
- |
local_snapshot_prefix=/bitnami/cassandra/cassandra_data/kanister_backups/${HOSTNAME}
rm -rf ${local_snapshot_prefix}/\?/
if [ -n "$(ls ${local_snapshot_prefix}/)" ]
then
timeout=300
while true
do
VAR=$((cqlsh -u cassandra -p $CASSANDRA_PASSWORD -e "DESCRIBE keyspaces;" --request-timeout=300) 2>&1)
if [[ $VAR != *"Could not connect to localhost"* ]]
then
break
fi
if [[ $timeout -le 0 ]]
then
echo "Timed out waiting for cqlsh to configure.."
exit 1
fi
sleep 2
timeout=$((timeout-2))
done
allkeyspaces=$(cqlsh -u cassandra -p $CASSANDRA_PASSWORD -e "DESCRIBE keyspaces" --request-timeout=300)
keyspacestodel=$(echo $allkeyspaces | xargs -n1 echo | grep -v ^system || true)
for ks in $keyspacestodel; do
cqlsh -u cassandra -p $CASSANDRA_PASSWORD -e "drop keyspace if exists $ks;" --request-timeout=300
done
cqlsh -u cassandra -p $CASSANDRA_PASSWORD -e "$(cat ${local_snapshot_prefix}/schema.cql)" --request-timeout=300
rm ${local_snapshot_prefix}/schema.cql
list="$(ls ${local_snapshot_prefix}/)"
cp -r ${local_snapshot_prefix}/. /bitnami/cassandra/data/data/
cd /bitnami/cassandra/data/data/
for keyspace in $list
do
cd $keyspace
for table in *
do
sstableloader -u cassandra -pw $CASSANDRA_PASSWORD -d ${HOSTNAME} $table/
done
cd ..
done
fi
rm -rf {{ .ArtifactsIn.params.KeyValue.snapshotPrefix }}
delete:
inputArtifactNames:
- params
phases:
- func: DeleteDataAll
name: deleteFromObjectStore
args:
namespace: "{{ .Object.metadata.name }}"
backupArtifactPrefix: "{{ .ArtifactsIn.params.KeyValue.backupPrefixLocation }}"
backupInfo: "{{ .ArtifactsIn.params.KeyValue.backupInfo }}"
reclaimSpace: true