dineridthe/mysql-backup-s3

By dineridthe

Updated 8 months ago

Docker container for Mysql backup to s3 compatible storage

Image
Developer Tools
0

88

MySQL Backup to S3

This Docker image is designed to back up MySQL databases to an S3-compatible storage. Each database is saved as a separate .sql.gz file in the specified S3 bucket and path, with the folder name based on the date and time of the backup.

Features

  • Backs up each MySQL database into a separate .sql.gz file.
  • Uploads backups directly to S3 without intermediate storage (but temporary files are created before uploading to s3).
  • Configurable MySQL connection details (host, port, user, password).
  • Configurable S3 bucket and path for storing backups.
  • Automatic folder creation based on the backup date and time.

Environment Variables

The following environment variables can be set to configure the backup process:

  • MYSQL_USER - MySQL user.
  • MYSQL_PASSWORD - MySQL password.
  • MYSQL_HOST - MySQL host.
  • MYSQL_PORT - MySQL port (default: 3306).
  • S3_BUCKET - S3 bucket name.
  • S3_ENDPOINT - S3-compatible endpoint URL.
  • S3_PATH - Path within the S3 bucket to store backups (default: backup/).
  • AWS_ACCESS_KEY_ID - AWS access key ID.
  • AWS_SECRET_ACCESS_KEY - AWS secret access key.
  • AWS_REGION - AWS region.

Usage

Docker Compose

Here is an example docker-compose.yml to use this image:

version: '3.8'

services:
  mysql:
    image: mysql:8.0
    container_name: mysql_container
    environment:
      MYSQL_ROOT_PASSWORD: root_password
      MYSQL_DATABASE: testdb
      MYSQL_USER: your_mysql_user
      MYSQL_PASSWORD: your_mysql_password
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql

  backup:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: backup_container
    depends_on:
      - mysql
    environment:
      MYSQL_USER: your_mysql_user
      MYSQL_PASSWORD: your_mysql_password
      MYSQL_HOST: mysql
      MYSQL_PORT: 3306
      S3_BUCKET: your_s3_bucket_name
      S3_ENDPOINT: your_s3_endpoint
      S3_PATH: backup/
      AWS_ACCESS_KEY_ID: your_aws_access_key_id
      AWS_SECRET_ACCESS_KEY: your_aws_secret_access_key
      AWS_REGION: your_aws_region

volumes:
  mysql_data:

Docker Pull Command

docker pull dineridthe/mysql-backup-s3