mariadb-backup with restore
10K+
This image allows a simple backup strategy for mysql and mariadb databases. Backups are created via mariadb-dump
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 |
S3_BUCKET | The S3 bucket to store and load backups from. If this variable is set the script will try to use S3 instead of the filesystem to store backups. | |
S3_BACKUP_PATH | A path within the specified S3 bucket where backups will be stored or loaded from. |
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/mariadb-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/mariadb-backup:latest
This script uses the aws cli to interact with S3. Please consult the official documentation on how to configure the aws cli. But some of the more common variants to authenticate are:
-v ~/.aws:/root/.aws.AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to the container to
authenticate with S3.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:6a77756f5…
Size
201.4 MB
Last updated
about 12 hours ago
docker pull brainbitsgmbh/mariadb-backup