This Go application automatically dumps a MySQL database using mydumper based on a configurable cron schedule.
- Cron-based Scheduling: Schedule database dumps using standard cron expressions.
mydumperIntegration: Leveragesmydumperfor efficient and reliable MySQL backups.- Dockerized: Easily deployable using Docker and Docker Compose.
- Docker and Docker Compose installed.
- A
mydumper.cnffile with your MySQL connection details and dump options.
-
Place
mydumper.cnf: Ensure yourmydumper.cnffile is in the root directory of this project. This file will be mounted into the Docker container.Example
mydumper.cnf:[client] user=root password=root host=mysql port=3306 [mydumper] database=testdb outputdir=/dump compress-protocol
-
Configure Cron Schedule: Set the
DUMP_CRON_SCHEDULEenvironment variable in yourdocker-compose.ymlfile. This variable accepts a standard cron expression.Example
docker-compose.ymlsnippet:datatron-service: build: . volumes: - ./mydumper.cnf:/mydumper.cnf:ro - ./dumps:/dump environment: DUMP_CRON_SCHEDULE: "0 2 * * *" # Dumps every day at 2 AM depends_on: - mysql
For testing, you can use
"* * * * *"to dump every minute. -
Run with Docker Compose: Navigate to the project root directory in your terminal and run:
docker-compose up --build -d
This will build the
datatron-serviceimage, start the MySQL container (if not already running), and then start thedatatron-servicewhich will begin scheduling dumps. -
Verify Dumps: Database dumps will be saved in the
./dumpsdirectory on your host machine. You can check the logs of thedatatron-serviceto see the execution status:docker-compose logs -f datatron-service
To build and run the Go application locally (without Docker):
- Install Go: Ensure you have Go (version 1.16 or higher) installed.
- Install Dependencies:
go mod tidy
- Build the Application:
go build -o mydumper-app . - Run the Application:
You need to set the
DUMP_CRON_SCHEDULEenvironment variable and ensuremydumper.cnfis accessible at/mydumper.cnf(or modify the Go code to look for it elsewhere).Note: Running locally requiresDUMP_CRON_SCHEDULE="* * * * *" ./mydumper-appmydumperto be installed on your host system and a MySQL instance accessible from your host.