2023-12-17 06:43:15 +01:00
# MySQL Backup
2024-08-10 10:50:00 +02:00
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.
2024-08-03 16:03:17 +02:00
It also supports __encrypting__ your backups using GPG.
2023-12-22 10:45:45 +01:00
2024-08-03 16:03:17 +02:00
The [jkaninda/mysql-bkup ](https://hub.docker.com/r/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.
[](https://github.com/jkaninda/mysql-bkup/actions/workflows/release.yml)
2024-01-18 15:07:01 +01:00
[](https://goreportcard.com/report/github.com/jkaninda/mysql-bkup)
2023-12-22 10:45:45 +01:00


2024-08-15 06:05:39 +02:00
Successfully tested on:
2023-12-18 07:08:43 +01:00
- Docker
2024-08-15 06:05:39 +02:00
- Docker in Swarm mode
2023-12-18 07:08:43 +01:00
- Kubernetes
2024-08-21 03:52:49 +02:00
- OpenShift
2023-12-17 06:43:15 +01:00
2024-08-03 16:03:17 +02:00
## Documentation is found at <https://jkaninda.github.io/mysql-bkup>
2023-12-22 10:44:38 +01:00
2023-12-17 06:43:15 +01:00
2024-08-03 16:03:17 +02:00
## Links:
2023-12-17 06:43:15 +01:00
2024-08-03 16:03:17 +02:00
- [Docker Hub ](https://hub.docker.com/r/jkaninda/mysql-bkup )
- [Github ](https://github.com/jkaninda/mysql-bkup )
2023-12-17 19:51:37 +01:00
2024-08-03 16:08:24 +02:00
## PostgreSQL solution :
2023-12-17 19:43:20 +01:00
2024-08-03 16:08:24 +02:00
- [PostgreSQL ](https://github.com/jkaninda/pg-bkup )
2023-12-19 04:07:18 +01:00
2024-08-03 16:03:17 +02:00
## Storage:
- Local
- AWS S3 or any S3 Alternatives for Object Storage
2024-08-21 03:49:15 +02:00
- SSH remote server
2023-12-17 19:22:09 +01:00
2024-08-03 16:03:17 +02:00
## Quickstart
2023-12-17 19:43:20 +01:00
2024-08-03 16:03:17 +02:00
### Simple backup using Docker CLI
2023-12-17 19:43:20 +01:00
2024-08-10 10:50:00 +02:00
To run a one time backup, bind your local volume to `/backup` in the container and run the `backup` command:
2023-12-17 19:45:28 +01:00
2024-08-03 16:03:17 +02:00
```shell
docker run --rm --network your_network_name \
-v $PWD/backup:/backup/ \
-e "DB_HOST=dbhost" \
-e "DB_USERNAME=username" \
-e "DB_PASSWORD=password" \
2024-08-10 10:50:00 +02:00
jkaninda/mysql-bkup backup -d database_name
2023-12-17 19:45:28 +01:00
```
2023-12-19 04:07:18 +01:00
2024-08-03 16:03:17 +02:00
Alternatively, pass a `--env-file` in order to use a full config as described below.
2023-12-19 04:07:18 +01:00
2024-08-11 09:38:31 +02:00
```yaml
docker run --rm --network your_network_name \
2024-08-11 09:49:41 +02:00
--env-file your-env-file \
2024-08-11 09:38:31 +02:00
-v $PWD/backup:/backup/ \
jkaninda/mysql-bkup backup -d database_name
```
2023-12-19 04:07:18 +01:00
2024-08-03 16:03:17 +02:00
### Simple backup in docker compose file
2023-12-19 04:07:18 +01:00
2023-12-17 06:43:15 +01:00
```yaml
services:
mysql-bkup:
2024-08-03 16:03:17 +02:00
# 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.
2023-12-22 06:04:35 +01:00
image: jkaninda/mysql-bkup
2023-12-17 06:43:15 +01:00
container_name: mysql-bkup
2024-08-10 11:29:58 +02:00
command: backup
2023-12-17 06:43:15 +01:00
volumes:
- ./backup:/backup
environment:
2024-08-21 03:49:15 +02:00
- DB_PORT=3306
- DB_HOST=mysql
2024-08-03 16:03:17 +02:00
- DB_NAME=foo
- DB_USERNAME=bar
2023-12-17 06:43:15 +01:00
- DB_PASSWORD=password
2024-08-03 16:03:17 +02:00
# mysql-bkup container must be connected to the same network with your database
networks:
- web
networks:
web:
2023-12-17 06:43:15 +01:00
```
2024-08-03 16:03:17 +02:00
## Deploy on Kubernetes
2023-12-17 19:43:20 +01:00
2024-08-14 22:19:02 +02:00
For Kubernetes, you don't need to run it in scheduled mode. You can deploy it as Job or CronJob.
2023-12-17 19:43:20 +01:00
2024-08-14 22:19:02 +02:00
### Simple Kubernetes backup Job :
2023-12-17 06:43:15 +01:00
```yaml
apiVersion: batch/v1
2024-08-14 22:19:02 +02:00
kind: Job
2023-12-17 06:43:15 +01:00
metadata:
2024-08-30 19:58:12 +02:00
name: backup-job
2023-12-17 06:43:15 +01:00
spec:
2024-08-30 19:58:12 +02:00
ttlSecondsAfterFinished: 100
2024-08-14 22:19:02 +02:00
template:
2023-12-17 06:43:15 +01:00
spec:
2024-08-14 22:19:02 +02:00
containers:
2024-08-30 19:58:12 +02:00
- name: pg-bkup
2024-08-14 22:19:02 +02:00
# 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:
2024-08-28 20:35:01 +02:00
- /bin/sh
- -c
2024-08-30 19:58:12 +02:00
- backup -d dbname
2024-08-14 22:19:02 +02:00
resources:
limits:
memory: "128Mi"
cpu: "500m"
env:
- name: DB_HOST
2024-08-30 19:58:12 +02:00
value: "mysql"
2024-08-14 22:19:02 +02:00
- name: DB_USERNAME
2024-08-30 19:58:12 +02:00
value: "user"
2024-08-14 22:19:02 +02:00
- name: DB_PASSWORD
2024-08-30 19:58:12 +02:00
value: "password"
volumeMounts:
- mountPath: /backup
name: backup
volumes:
- name: backup
hostPath:
path: /home/toto/backup # directory location on host
type: Directory # this field is optional
2024-08-14 22:19:02 +02:00
restartPolicy: Never
2023-12-26 21:28:39 +01:00
```
2024-08-03 16:03:17 +02:00
## 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` :
```
2024-08-10 10:50:00 +02:00
docker pull jkaninda/mysql-bkup
docker pull ghcr.io/jkaninda/mysql-bkup
2024-08-03 16:03:17 +02:00
```
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:
2023-12-26 21:28:39 +01:00
2024-08-03 16:03:17 +02:00
- The original image is based on `ubuntu` and requires additional tools, making it heavy.
- This image is written in Go.
- `arm64` and `arm/v7` architectures are supported.
- Docker in Swarm mode is supported.
- Kubernetes is supported.
2023-12-26 21:28:39 +01:00
## License
This project is licensed under the MIT License. See the LICENSE file for details.
## Authors
**Jonas Kaninda**
- < https: // github . com / jkaninda >
## Copyright
Copyright (c) [2023] [Jonas Kaninda]