-
Notifications
You must be signed in to change notification settings - Fork 0
/
cronjob.yaml
116 lines (112 loc) · 2.91 KB
/
cronjob.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
kind: ConfigMap
apiVersion: v1
metadata:
creationTimestamp: null
name: backup-script
data:
backup.sh: |
#!/bin/sh
cp /root/postgres/pgpass /root/.pgpass
cp /root/aws/credentials /root/.aws/
cp /root/aws/config /root/.aws/
chmod 600 /root/.pgpass
export BACKUP_FILE=$(echo /backup_$(date +%Y%m%d_%H%M).pgdump)
pg_dump -d $POSTGRES_DB \
-U $POSTGRES_USER \
-h $POSTGRES_HOST \
-f $BACKUP_FILE \
-W
bzip2 $BACKUP_FILE
mcrypt $BACKUP_FILE.bz2 -k $BACKUP_FILE_PW
aws s3 cp ${BACKUP_FILE}.bz2.nc s3://$S3_BUCKET
---
apiVersion: v1
kind: Secret
metadata:
name: pgpass
data:
pgpass: base64encodedsecret
---
apiVersion: v1
kind: Secret
metadata:
name: aws
data:
credentials: base64encodedsecret
config: base64encodedsecret
---
apiVersion: v1
kind: Secret
metadata:
name: backup
data:
password: base64encodedsecret
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: postgres-backup
spec:
schedule: 0 0 * * *
jobTemplate:
spec:
template:
spec:
containers:
- name: postgres-backup
image: tommymalmqvist/pgtos3backup:latest
imagePullPolicy: Always
env:
- name: S3_BUCKET
value: kundportalen-backup
- name: awsconfig
valueFrom:
secretKeyRef:
name: aws
key: config
- name: awscredentials
valueFrom:
secretKeyRef:
name: aws
key: credentials
- name: BACKUP_FILE_PW
valueFrom:
secretKeyRef:
name: backup
key: password
- name: POSTGRES_DB
value: db
- name: POSTGRES_USER
value: user
- name: POSTGRES_HOST
value: host
- name: PGSSLMODE
value: disable
- name: PGPORT
value: "5432"
- name: PGPASSFILE
value: "/root/.pgpass"
volumeMounts:
- name: pgpass
mountPath: "/root/postgres"
readOnly: true
- name: backup-script
mountPath: "/root/backup"
readOnly: true
- name: aws
mountPath: "/root/aws"
readOnly: true
volumes:
- name: backup-script
configMap:
name: backup-script
defaultMode: 0764
- name: pgpass
secret:
defaultMode: 0620
secretName: pgpass
- name: aws
secret:
defaultMode: 0620
secretName: aws
restartPolicy: Never