mysql-cron-backup

Run a Docker container to automatically back up MySQL or MariaDB databases. Configure schedules with cron, manage backup retention, and restore with ease.

This Docker image provides a straightforward way to automate periodic backups of your MySQL or MariaDB databases. It runs mysqldump on a schedule you define, ensuring your data is consistently protected without manual intervention. The container is highly configurable through environment variables, allowing you to tailor the backup process to your specific needs.

Key features include:

  • Flexible Scheduling: Define any backup interval using the standard CRON_TIME format.
  • Automated Retention: Set a MAX_BACKUPS limit to automatically remove old backups and manage disk space.
  • Lifecycle Hooks: Create a backup immediately on container start with INIT_BACKUP or when it stops with EXIT_BACKUP. You can also automatically restore the latest backup on startup.
  • Full Customization: Pass custom arguments to mysqldump using MYSQLDUMP_OPTS, adjust gzip compression levels, or even use plain SQL files.
  • Secure Credentials: Safely provide your database credentials using environment variables or Docker secrets for enhanced security.

Simply link it to your database container, mount a volume for the backups, and let it handle the rest. It's an ideal companion for any project using MySQL or MariaDB within a Docker ecosystem.

Directory Structure

mysql-cron-backup
mysql-backup
backups
mysql-data
.env
docker-compose.yml

docker-compose.yml

services:
  mysql:
    image: mysql:8.0
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
    volumes:
      - ./mysql-data:/var/lib/mysql

  backup:
    image: fradelg/mysql-cron-backup
    restart: always
    depends_on:
      - mysql
    environment:
      MYSQL_HOST: mysql
      MYSQL_USER: root
      MYSQL_PASS: ${MYSQL_ROOT_PASSWORD}
      MAX_BACKUPS: 15
      INIT_BACKUP: 1
      CRON_TIME: "0 0 * * *"
    volumes:
      - ./backups:/backup

.env

MYSQL_ROOT_PASSWORD=your_super_secret_password
Categories:

Share:

Ad
Favicon

 

  
 

Similar to mysql-cron-backup

Favicon

 

  
  
Favicon

 

  
  
Favicon