https://www.notion.so/Mongodb-backup-to-gcs-with-k8s-cron-703fe5df394e455c818832d7c48fe9eb
Scripts and config to backup mongodb to Google Cloud Storage in GKE
- kubernetes cronJob to execute our docker image with the necesari script and dependencies
- Dockerfile of the image used by de cronJob
- Script with the necesary steps to backup database and upload to GCS
-
Create bucket in Google Cloud Storage to upload backups
-
Create Google cloud service account with credentials and access permisions for GCS (Storage Object Creator, Storage Object Viewer): https://cloud.google.com/kubernetes-engine/docs/tutorials/authenticating-to-cloud-platform?hl=es
-
Create kubernetes secret in your kubernetes cluster to store Service Account Credentials: kubectl create secret generic gcs-key --from-file=key.json=.json
-
Build and upload docker image to your registry
-
Apply cron.yaml to your kubernetes cluster: kubectl apply -f cron.yaml
- Need to save your Google cloud service account credentials json in same path
- Run: docker run -ti -v .:/var/mongobackup -e GOOGLE_APPLICATION_CREDENTIALS='/var/mongobackup/<CREDENTIALS_FILENAME>.json' -e MONGO_URI='<MONGO_URI>' -e BUCKET_NAME='<BUCKET_NAME>' mongobackup