Cockroach db daily backup from GKE Kubernetes to GCP storage

(vishal) #1

I have deployed Cockroach db database in google Kubernetes engine, and now i want to backup that database daily purpose. I want to backup database from Kubernetes and upload that database dump to my google storage bucket. Suggest me if anyone have any idea about it.

(Ron Arévalo) #2

Hey @vishal,

I would suggest using our BACKUP feature and running cron or some other task schedule to run that backup command. You can read more about our documentation for BACKUP here.

Using BACKUP would be the best option, however you could also use the DUMP feature, but there are some things to consider then using DUMP that you can read about in the docs here.



(vishal) #3

@ronarev Thanks for the reply :blush: First thing is i am using non enterprice version of cockroach db and i have explore dump command to backup database and it’s working fine from my machine, My exact point is I want to schedule that dump command from kubernetes Cron. I am able to dump and upload it to gcp storage with below script from my local machine.

CLUSTER_NAME=‘your clustername’
REGION_NAME=‘your region’
PROJECT_NAME=‘your gcp project name’
DATABASE_NAME=‘your database name’
DUMP_DIR=‘path of your dump dir’
TODAY= date +"%d%b%Y"
BUCKET=‘your bucket name’
BUCKET_FOLDER=‘folder name in bucket’

  • gcloud beta container clusters get-credentials {CLUSTER_NAME} --region {REGION_NAME} --project ${PROJECT_NAME}

  • kubectl exec -it cockroachdb-client-secure – ./cockroach dump {DATABASE_NAME} > {DATABASE_NAME}-${TODAY}.sql --certs-dir=/cockroach-certs --host=cockroachdb-public

  • gsutil rsync -r {DUMP_DIR} gs://{BUCKET}/${BUCKET_FOLDER}(edited)

        But i want to run script from kubernetes crontab and upload it to gcp storage on daily basis. I don't want any instance to run backup script.

(Ron Arévalo) #4

Hey @vishal

I’m not sure I understand what you mean by:

I don’t want any instance to run backup script.

Could you clarify?



(vishal) #5

I am using cockroach db on Kubernetes and i want dump their database on daily basis, and dump should be upload on Google storage bucket. and i want backup script to take database that create dump of many database which deployed in kubernetes cluster and upload it to storage. also i have to run that script from kubernetes deployment only. not using cron from local machine or dedicated system.

Also, Is there any command to take dump cockroach database from kubernetes directly?

I checked dump command from cockroach site.

but i think there is not details available to dump database from kubernetes cluster.

(Jesse) #6

Hi @vishal,

Our Kubernetes tutorials provide a yaml file to launch a pod and keep it running indefinitely for ad-hoc client commands. In the tutorials, we focus on using the built-in SQL shell (cockroach sql), but you can run any cockroach command from that pod, including cockroach dump.

Please take a look if you haven’t already seen this: Secure, Insecure.