A Go program that automatically backs up a MySQL database and uploads the backup to Google Drive.
259
This Go program automatically backs up a MySQL database and uploads the backup files to a specified Google Drive folder using a service account. It runs periodically based on the configured frequency and is designed to be easily deployed using Docker.
The program performs the following tasks:
mysqldump.JSON credentials file for the service account downloaded from Google Cloud.JSON key file for the service account.JSON key file, which looks like [email protected]./folders/ in the URL).Create a folder named my_drive_credentials in the root directory of your project and place the service-account.json file inside.
Create a docker-compose.yml file with the following configuration:
version: "3.8"
services:
backup-service:
image: unkcode/db-recordum:tagname
environment:
- MYSQL_DB=mydb
- MYSQL_HOST=myhost
- MYSQL_USER=myuser
- MYSQL_PASSWORD=mypassword
- BACKUP_FRECUENCY=24h
- GDRIVE_FOLDER_ID=your_folder_id
- GDRIVE_FILE_PREFIX=my_backup
volumes:
- ./my_drive_credentials:/my_drive_credentials
Replace the values in the docker-compose.yml file:
MYSQL_DB: The name of your database.MYSQL_HOST: The IP address or hostname of your database.MYSQL_USER: The database user.MYSQL_PASSWORD: The database user's password.BACKUP_FRECUENCY: The backup frequency in hours (e.g., 24 for a daily backup).GDRIVE_FOLDER_ID: The ID of the Google Drive folder where the backups will be uploaded.GDRIVE_FILE_PREFIX: The prefix used in the backup file names.Build the Docker image (if it is not already available on Docker Hub):
docker build -t your-docker-image .
Start the service using Docker Compose:
docker-compose up -d
The container will run in the background, making backups periodically based on the specified frequency.
mysqldump is available and properly configured in the Docker container if you are managing dependencies manually.service-account.json file to any public repository and handle the credentials securely.docker logs backup-service
That's it! With this setup, your program will automatically back up and upload files to Google Drive.
Content type
Image
Digest
sha256:8e42e0e38…
Size
246.1 MB
Last updated
almost 2 years ago
docker pull unkcode/db-recordum