Image with mysql backup cli
10K+
This image allows a simple backup strategy for mysql and mariadb databases. Backups are created via mysqldump
and gziped, and can be restored with this image by just changing a single environment variable.
This image follows a simple strategy for keeping or removing backuped dumps:
daily-*) that are older than a specified amount of days.hourly-*) and only keeps a specified amount of files.This strategy ensures, that there are always a certain amount of backup files available from the last couple of days, but also that there are at least a few recent backups available too, without storing too many backups.
The following environment variables can be used to configure the script:
| Variable | Default | Description |
|---|---|---|
MODE | backup | Tell the script whether it should create a backup or restore one. Allowed values: backup restore |
DATABASE_DSN | The DSN of the database you want to backup or restore in the format mysql://user:password@host:port/database_name | |
DATABASE_DSN_FILE | Alternative to DATABASE_DSN if you prefer to pass in a path to a file that contains the DSN instead of passing it directly via environment variable. | |
BACKUP_DIRECTORY | /backup | The directory (within the docker container) where the backup files are stored. This should usually be configured by changing the volume mount instead of this variable. |
MAX_DAILY_BACKUP_AGE | 7 | Only for mode backup. The number of days to keep daily backups. |
MAX_HOURLY_BACKUP_COUNT | 3 | Only for mode backup. The number backup files to keep for hourly backups. |
BACKUP_RESTORE_NAME | latest | Only for mode restore. The filename of the backup to restore. The filename must be relative to BACKUP_DIRECTORY |
Example creating and restoring a backup using docker run:
# Create a backup. It will automatically create a link called `latest` to that backup.
docker run -it --rm -e "MODE=backup" -e "DATABASE_DSN=mysql://MyDbUser:[email protected]/my-database" -v "$(pwd)/backup:/backup" brainbitsgmbh/mysql-backup:latest
# Restore the `latest` backup.
docker run -it --rm -e "MODE=restore" -e "DATABASE_DSN=mysql://MyDbUser:[email protected]/my-database" -v "$(pwd)/backup:/backup" brainbitsgmbh/mysql-backup:latest
Make sure that you enter a valid DSN that can also be reached from withing the docker container the script is running in.
If your DSN includes localhost it will likely not work, because the container cannot reach the database on your local
machine via localhost. In that case you can try host.docker.internal instead, as seen in the example above.
Content type
Image
Digest
sha256:60fb22c58…
Size
117.9 MB
Last updated
over 2 years ago
docker pull brainbitsgmbh/mysql-backup