2

We deploy a laravel project in k8s(GCP) with mysql database. Now i want time to time backup of this database with the help of cronjob and I followed an articles but i'm unable to create a backup file. However, as per article we need to create the storage bucket and service account in GCP

It is working properly still there is no backup file in storage bucket.

cronjob.yaml file

apiVersion: batch/v1beta1 kind: CronJob metadata: name: backup-cronjob spec: schedule: "*/1 * * * *" jobTemplate: spec: template: spec: containers: - name: backup-container image: gcr.io/thereport/abcd env: - name: DB_NAME valueFrom: configMapKeyRef: name: backup-configmap key: db - name: GCS_BUCKET valueFrom: configMapKeyRef: name: backup-configmap key: gcs-bucket - name: DB_HOST valueFrom: secretKeyRef: name: backup key: db_host - name: DB_USER valueFrom: secretKeyRef: name: backup key: username - name: DB_PASS valueFrom: secretKeyRef: name: backup key: password - name: GCS_SA valueFrom: secretKeyRef: name: backup key: thereport-541be75e66dd.json args: - /bin/bash - -c - mysqldump --u root --p"root" homestead > trydata.sql; gcloud config set project thereport; gcloud auth activate-service-account --key-file backup; gsutil cp /trydata.sql gs://backup-buck

      restartPolicy: OnFailure

Saya Kasta
  • 160
  • 1
  • 9
  • Hello, do your kube service account have access to write objects in your bucket? for a quick try (not for real implementation) make your [bucket public](https://cloud.google.com/storage/docs/access-control/making-data-public#buckets) and try to run the job, if you see the dump file in your bucket after this you will need to take a look at your bucket policy to give access to your kube. – Chris32 Oct 17 '19 at 07:43

1 Answers1

1

You don't copy the right file:

mysqldump --u root --p"root" homestead > trydata.sql; gcloud config set project thereport; gcloud auth activate-service-account --key-file backup; gsutil cp /laravel.sql gs://backup-buck

guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76
  • To be sure that you get the same file, in the same directory, try with this (absolute path to trydata.sql file because you copy the file with this path) ` mysqldump --u root --p"root" homestead > /trydata.sql;` – guillaume blaquiere Oct 17 '19 at 13:40
  • i have done everything as per suggestion, still not able to take backup. – Saya Kasta Oct 19 '19 at 05:37