5.5 KiB
MySQL Backup
MySQL Backup is a Docker container image that can be used to backup and restore MySQL database. It supports local storage, AWS S3 or any S3 Alternatives for Object Storage, and SSH compatible storage. It also supports encrypting your backups using GPG.
The jkaninda/mysql-bkup Docker image can be deployed on Docker, Docker Swarm and Kubernetes. It handles recurring backups of postgres database on Docker and can be deployed as CronJob on Kubernetes using local, AWS S3 or SSH compatible storage.
It also supports encrypting your backups using GPG.
- Docker
- Docker Swarm
- Kubernetes
Documentation is found at https://jkaninda.github.io/mysql-bkup
Links:
PostgreSQL solution :
Storage:
- Local
- AWS S3 or any S3 Alternatives for Object Storage
- SSH
Quickstart
Simple backup using Docker CLI
To run a one time backup, bind your local volume to /backup in the container and run the backup command:
docker run --rm --network your_network_name \
-v $PWD/backup:/backup/ \
-e "DB_HOST=dbhost" \
-e "DB_USERNAME=username" \
-e "DB_PASSWORD=password" \
jkaninda/mysql-bkup backup -d database_name
Alternatively, pass a --env-file in order to use a full config as described below.
docker run --rm --network your_network_name \
--env-file your-env-file
-v $PWD/backup:/backup/ \
jkaninda/mysql-bkup backup -d database_name
Simple backup in docker compose file
services:
mysql-bkup:
# In production, it is advised to lock your image tag to a proper
# release version instead of using `latest`.
# Check https://github.com/jkaninda/mysql-bkup/releases
# for a list of available releases.
image: jkaninda/mysql-bkup
container_name: mysql-bkup
command: backup
volumes:
- ./backup:/backup
environment:
- DB_PORT=5432
- DB_HOST=postgres
- DB_NAME=foo
- DB_USERNAME=bar
- DB_PASSWORD=password
# mysql-bkup container must be connected to the same network with your database
networks:
- web
networks:
web:
Deploy on Kubernetes
For Kubernetes, you don't need to run it in scheduled mode. You can deploy it as CronJob.
Simple Kubernetes CronJob usage:
apiVersion: batch/v1
kind: CronJob
metadata:
name: bkup-job
spec:
schedule: "0 1 * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: mysql-bkup
# In production, it is advised to lock your image tag to a proper
# release version instead of using `latest`.
# Check https://github.com/jkaninda/mysql-bkup/releases
# for a list of available releases.
image: jkaninda/mysql-bkup
command:
- /bin/sh
- -c
- mysql-bkup backup -s s3 --path /custom_path
env:
- name: DB_PORT
value: "5432"
- name: DB_HOST
value: ""
- name: DB_NAME
value: ""
- name: DB_USERNAME
value: ""
# Please use secret!
- name: DB_PASSWORD
value: ""
- name: AWS_S3_ENDPOINT
value: "https://s3.amazonaws.com"
- name: AWS_S3_BUCKET_NAME
value: "xxx"
- name: AWS_REGION
value: "us-west-2"
- name: AWS_ACCESS_KEY
value: "xxxx"
- name: AWS_SECRET_KEY
value: "xxxx"
- name: AWS_DISABLE_SSL
value: "false"
restartPolicy: Never
Available image registries
This Docker image is published to both Docker Hub and the GitHub container registry.
Depending on your preferences and needs, you can reference both jkaninda/mysql-bkup as well as ghcr.io/jkaninda/mysql-bkup:
docker pull jkaninda/mysql-bkup
docker pull ghcr.io/jkaninda/mysql-bkup
Documentation references Docker Hub, but all examples will work using ghcr.io just as well.
Supported Engines
This image is developed and tested against the Docker CE engine and Kubernetes exclusively. While it may work against different implementations, there are no guarantees about support for non-Docker engines.
References
We decided to publish this image as a simpler and more lightweight alternative because of the following requirements:
- The original image is based on
ubuntuand requires additional tools, making it heavy. - This image is written in Go.
arm64andarm/v7architectures are supported.- Docker in Swarm mode is supported.
- Kubernetes is supported.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Authors
Jonas Kaninda
Copyright
Copyright (c) [2023] [Jonas Kaninda]