Score:0

Run daily backup on Google Cloud Platform

gb flag

I have a system running on Google Cloud. The system has one DB VM and instance group that runs backend server VMs. All VMs use the cos-stable VM image, and run a single docker container that contains their logic.

The DB VM runs a docker image that contains a MariaDB database.

I want to run a daily job that backs the database up and stores it in a storage bucket. I'm not sure how to approach this. I do not have a VM that can handle cronjobs, and I don't want to have another VM running all the time, just for daily backup. In addition, I would like to mount the storage bucket to the backup VM using FUSE, instead of using the Google APIs to write to storage.

Is it possible for me to set up FUSE and a cronjob on one of the cos-stable VMs? If not, can I have a VM that boots every day and then shuts itself down? The schedulers I found on the Google Cloud Console are for app engine or for pub/sub notifications, not for starting a VM.

John Hanley avatar
cn flag
COS has limited to zero support for what you are trying to do. Setting up a VM to backup a database to Cloud Storage is easy, but how are you going to restore the database in a recovery situation? COS is the wrong platform for a database. You are trying to create a self-managed database, instead, use Cloud SQL and forget the gymnastics with CRON, FUSE, etc.
gb flag
Our code requires some MariaDB extensions that are not widely available on cloud managed MySQL instances, so we're forced to set up our own database. Database backups are mostly going to be restored elsewhere, by people checking the system. Restoring into the COS VM is a matter of starting it, docker execing into the container and running mysql < ...
Alex G avatar
ar flag
If you are going to the option on VM that boots every day and then shuts itself down, you can consider using [instance schedule](https://cloud.google.com/compute/docs/instances/schedule-instance-start-stop).
Score:1
st flag

Ideally, you should have your database on Cloud SQL and leverage its automated backup features.

Alternatively, you can set up a cronjob to run a mysqldump command and back it up.

One option to achieve it is:

  1. Create VM image with the appropriate MySQL client and a backup script that runs a mysqldump connecting to your MariaDB instance and save it to a Cloud Store bucket - You can set this script to run on boot and shutdown the instance afterward

  2. Create a Cloud Function to start or launch the VM which is going to execute the backup routine

  3. Create a Cloud Scheduler job to trigger your Cloud Function every day, at a specific time

gb flag
I did something similar, only using the instance scheduler instead of the cloud scheduler, as suggested by @Alex G .
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.