forked from appuio/techlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob_mysql-dump.yaml
43 lines (43 loc) · 1.25 KB
/
job_mysql-dump.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
apiVersion: batch/v1
kind: Job
metadata:
name: mysql-dump
spec:
template:
spec:
containers:
- name: mysql
image: mysql:5.6
command:
- 'bash'
- '-eo'
- 'pipefail'
- '-c'
- >
trap "echo Backup failed; exit 0" ERR;
FILENAME=backup-${MYSQL_DATABASE}-`date +%Y-%m-%d_%H%M%S`.sql.gz;
mysqldump --user=${MYSQL_USER} --password=${MYSQL_PASSWORD} --host=${MYSQL_HOST} --port=${MYSQL_PORT} --skip-lock-tables --quick --add-drop-database --routines ${MYSQL_DATABASE} | gzip > /tmp/$FILENAME;
echo "";
echo "Backup successful"; du -h /tmp/$FILENAME;
env:
- name: MYSQL_DATABASE
valueFrom:
secretKeyRef:
key: database-name
name: mysql
- name: MYSQL_USER
valueFrom:
secretKeyRef:
key: database-user
name: mysql
- name: MYSQL_HOST
value: mysql
- name: MYSQL_PORT
value: "3306"
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
key: database-password
name: mysql
restartPolicy: OnFailure
backoffLimit: 3