forked from bcgov/embc-ess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup-cronjob-log-only.yaml
229 lines (229 loc) · 8.57 KB
/
backup-cronjob-log-only.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
---
kind: "Template"
apiVersion: "v1"
metadata:
name: "{$JOB_NAME}-cronjob-template"
annotations:
description: "Scheduled Task to perform a Database Backup"
tags: "cronjob,backup"
parameters:
- name: "JOB_NAME"
displayName: "Job Name"
description: "Name of the Scheduled Job to Create."
value: "ess-db-backup-log-only"
required: true
- name: "JOB_PERSISTENT_STORAGE_NAME"
displayName: "Backup Persistent Storage Name"
description: "Pre-Created PVC to use for backup target"
value: ""
required: true
- name: "SCHEDULE"
displayName: "Cron Schedule"
description: "Cron Schedule to Execute the Job (in UTC)"
# Currently targeting every hour on the hour
value: "0 * * * *"
required: true
- name: "SOURCE_IMAGE_NAME"
displayName: "Source Image Name"
description: "The name of the image to use for this resource."
required: true
value: "db-backup"
- name: "IMAGE_NAMESPACE"
displayName: "Image Namespace"
description: "The namespace of the OpenShift project containing the imagestream for the application."
required: true
value: "jhnamn-tools"
- name: "TAG_NAME"
displayName: "Environment TAG name"
description: "The TAG name for this environment, e.g., dev, test, prod"
required: true
value: "latest"
- name: "DATABASE_NAME"
displayName: "Database Name"
description: "The name of the database."
required: true
value: ""
- name: "DATABASE_SERVICE_NAME"
displayName: "Database Deployment Name"
description: "The name associated to the database deployment resources. In particular, this is used to wire up the credentials associated to the database."
required: true
value: "mssql"
- name: "DATABASE_SERVICE_URI"
displayName: "Database Hostname"
description: "The host name address of the service mapping to the database within the cluster."
required: true
value: ""
- name: "BACKUP_STRATEGY"
displayName: "Backup Strategy"
description: "The strategy to use for backups; for example daily, or rolling."
required: true
value: "rolling"
- name: "BACKUP_DIR"
displayName: "The root backup directory"
description: "The name of the root backup directory"
required: true
value: "/backups/"
- name: "BACKUP_LOG_ONLY"
displayName: "Flag to backup of the database log only"
description: "Flag to backup of the database log only. If false the backup will be a full backup and if true it will only back up the transaction log"
required: false
value: "true"
- name: "NUM_BACKUPS"
displayName: "The number of backup files to be retained"
description: "The number of backup files to be retained. Used for the `daily` backup strategy. Ignored when using the `rolling` backup strategy."
required: false
value: "5"
- name: "DAILY_BACKUPS"
displayName: "Number of Daily Backups to Retain"
description: "The number of daily backup files to be retained. Used for the `rolling` backup strategy."
required: false
value: "7"
- name: "WEEKLY_BACKUPS"
displayName: "Number of Weekly Backups to Retain"
description: "The number of weekly backup files to be retained. Used for the `rolling` backup strategy."
required: false
value: "4"
- name: "MONTHLY_BACKUPS"
displayName: "Number of Monthly Backups to Retain"
description: "The number of monthly backup files to be retained. Used for the `rolling` backup strategy."
required: false
value: "1"
- name: "JOB_SERVICE_ACCOUNT"
displayName: "Service Account Name"
description: "Name of the Service Account To Exeucte the Job As."
value: "default"
required: true
- name: "SUCCESS_JOBS_HISTORY_LIMIT"
displayName: "Successful Job History Limit"
description: "The number of successful jobs that will be retained"
value: "5"
required: true
- name: "FAILED_JOBS_HISTORY_LIMIT"
displayName: "Failed Job History Limit"
description: "The number of failed jobs that will be retained"
value: "2"
required: true
- name: "JOB_BACKOFF_LIMIT"
displayName: "Job Backoff Limit"
description: "The number of attempts to try for a successful job outcome"
value: "0"
required: false
objects:
- kind: ConfigMap
apiVersion: v1
metadata:
name: "${JOB_NAME}-config"
labels:
template: "${JOB_NAME}-config-template"
cronjob: "${JOB_NAME}"
data:
DATABASE_SERVICE_URI: "${DATABASE_SERVICE_URI}"
DATABASE_SERVICE_NAME: "${DATABASE_SERVICE_NAME}"
MSSQL_DATABASE: "${DATABASE_NAME}"
RETENTION.NUM_BACKUPS: "${NUM_BACKUPS}"
BACKUP_STRATEGY: "rolling"
RETENTION.DAILY_BACKUPS: "${DAILY_BACKUPS}"
RETENTION.WEEKLY_BACKUPS: "${WEEKLY_BACKUPS}"
RETENTION.MONTHLY_BACKUPS: "${MONTHLY_BACKUPS}"
- kind: "CronJob"
apiVersion: "batch/v1beta1"
metadata:
name: "${JOB_NAME}"
labels:
template: "${JOB_NAME}-cronjob"
cronjob: "${JOB_NAME}"
spec:
schedule: "${SCHEDULE}"
concurrencyPolicy: "Forbid"
successfulJobsHistoryLimit: "${{SUCCESS_JOBS_HISTORY_LIMIT}}"
failedJobsHistoryLimit: "${{FAILED_JOBS_HISTORY_LIMIT}}"
jobTemplate:
metadata:
labels:
template: "${JOB_NAME}-job"
cronjob: "${JOB_NAME}"
spec:
backoffLimit: ${JOB_BACKOFF_LIMIT}
template:
spec:
containers:
- name: "${JOB_NAME}-cronjob"
image: "docker-registry.default.svc:5000/${IMAGE_NAMESPACE}/${SOURCE_IMAGE_NAME}:${TAG_NAME}"
# image: backup
command:
- "/bin/bash"
- "-c"
- "/opt/mssql-tools/bin/uid_entrypoint;/backup.sh -1"
volumeMounts:
- mountPath: "${BACKUP_DIR}"
name: "backup"
env:
- name: BACKUP_DIR
value: "${BACKUP_DIR}"
- name: BACKUP_STRATEGY
valueFrom:
configMapKeyRef:
name: "${JOB_NAME}-config"
key: BACKUP_STRATEGY
- name: NUM_BACKUPS
valueFrom:
configMapKeyRef:
name: "${JOB_NAME}-config"
key: NUM_BACKUPS
optional: true
- name: BACKUP_LOG_ONLY
value: "${BACKUP_LOG_ONLY}"
- name: DAILY_BACKUPS
valueFrom:
configMapKeyRef:
name: "${JOB_NAME}-config"
key: RETENTION.DAILY_BACKUPS
optional: true
- name: WEEKLY_BACKUPS
valueFrom:
configMapKeyRef:
name: "${JOB_NAME}-config"
key: RETENTION.WEEKLY_BACKUPS
optional: true
- name: MONTHLY_BACKUPS
valueFrom:
configMapKeyRef:
name: "${JOB_NAME}-config"
key: RETENTION.MONTHLY_BACKUPS
optional: true
- name: DATABASE_SERVICE_URI
valueFrom:
configMapKeyRef:
name: "${JOB_NAME}-config"
key: DATABASE_SERVICE_URI
- name: DATABASE_SERVICE_NAME
valueFrom:
configMapKeyRef:
name: "${JOB_NAME}-config"
key: DATABASE_SERVICE_NAME
- name: DEFAULT_PORT
valueFrom:
configMapKeyRef:
name: "${JOB_NAME}-config"
key: DEFAULT_PORT
optional: true
- name: MSSQL_DATABASE
valueFrom:
configMapKeyRef:
name: "${JOB_NAME}-config"
key: MSSQL_DATABASE
- name: DB_ADMIN_PASSWORD
valueFrom:
secretKeyRef:
name: "${DATABASE_SERVICE_NAME}"
key: database-admin-password
volumes:
- name: backup
persistentVolumeClaim:
claimName: "${JOB_PERSISTENT_STORAGE_NAME}"
restartPolicy: "Never"
terminationGracePeriodSeconds: 30
activeDeadlineSeconds: 1600
dnsPolicy: "ClusterFirst"
serviceAccountName: "${JOB_SERVICE_ACCOUNT}"
serviceAccount: "${JOB_SERVICE_ACCOUNT}"