-
Notifications
You must be signed in to change notification settings - Fork 1
/
cronjob.yml
61 lines (54 loc) · 2.34 KB
/
cronjob.yml
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
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: cockroachdb-backup
spec:
schedule: 0 0 * * *
jobTemplate:
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: backup
image: alpine:latest
command: ["/bin/sh","-c"]
args:
- |-
apk add --no-cache --update curl bash ca-certificates wget python2 py2-openssl;
wget https://dl.google.com/dl/cloudsdk/channels/rapid/google-cloud-sdk.tar.gz;
tar -xvf google-cloud-sdk.tar.gz;
rm google-cloud-sdk.tar.gz;
google-cloud-sdk/install.sh --usage-reporting=false --path-update=false --bash-completion=false;
wget -qO- https://binaries.cockroachdb.com/cockroach-v${COCKROACH_VERSION}.linux-musl-amd64.tgz | tar xvz;
cp -i cockroach-v${COCKROACH_VERSION}.linux-musl-amd64/cockroach /;
chmod +x /cockroach;
date=`date +%Y-%m-%d.%H.%M.%S`;
file="${date}-${COCKROACH_DATABASE}.sql";
cat /google-cloud-sdk/path.bash.inc;
url="https://storage.googleapis.com/${GCP_BUCKET_NAME}/${file}";
echo "Dumping database";
/cockroach dump ${COCKROACH_DATABASE} --url ${COCKROACH_URL} > "/tmp/${file}";
echo "Dump completed. Uploading /tmp/${file} to ${url}";
echo "Generating GCP token...";
/google-cloud-sdk/bin/gcloud auth activate-service-account "${GCP_SA_USER}" --key-file=/gcp/key.json;
cat "/tmp/${file}";
curl -v --upload-file "/tmp/${file}" -H "Authorization: Bearer `/google-cloud-sdk/bin/gcloud auth print-access-token ${GCP_SA_USER}`" "${url}";
env:
- name: COCKROACH_URL
value: postgresql://root@db-cockroachdb-public:26257?sslmode=disable
- name: COCKROACH_DATABASE
value:
- name: GCP_BUCKET_NAME
value: cockroach-backup-bucket
- name: GCP_SA_USER
value:
- name: COCKROACH_VERSION
value: 2.0.6
volumeMounts:
- name: gcp-key
mountPath: /gcp
volumes:
- name: gcp-key
secret:
secretName: cockroach-backup-sa