Automated backing up of mysql/mariadb to various sources
4.8K
db_backup.py is a Python script for backing up MySQL/MariaDB databases to an S3 bucket or a local directory. Databases are read using mysqldump , compressed with gzip and backed up using rclone.
In an attempt to complete as many backups as possible, the script will not exit on an error, but will report a non 0 exit code after all backups have been attempted.
Local logging is to standard out only, unless a log file is specified with the flag --log-file, in which case messages are also logged to the file. The configuration file is /etc/backups.yaml unless a file is specified with the flag --config.
Logging to Google Chat is supported. A separate loglevel can be configured. That loglevel must be higher than the general loglevel to have any restrictive effect. Setting the loglevel to WARNING(30), would post only warnings and above to Google Chat if the general loglevel is set to INFO(20).
Database backups are stored at the following sub path: rootdir/backup_name/year/month/database_name+timestamp.sql.gz on the destination.
The reporting of the size of backed up files, can be configured using bitmath_prefix (default: True) & bitmath_system (Default: SI). These values are parsed directly to the bitmap library. Read their documentation.
You can configure as many backups as you want. Each backup needs a source and a destination. A source can specify more than one database to be backed up.
rootdir: my_database_backups
rclone_config: /etc/rclone.conf
timeout: 600
loglevel: INFO
bitmath_system: SI
bitmath_bestprefix: yes
google_chat:
url: https://chat.googleapis.com/v1/spaces/XXX/messages?key=XXX
loglevel: WARNING
backups:
backup_01:
source:
type: mysql
host: db1.example.com
port: 3306
user: read_only_user
password: 123456
databases: [mysql, sys]
destination:
type: s3
access_key_id: my_access_key_id
bucket: my_bucket
endpoint: my_endpoint
secret_access_key: my_secret_access_key
backup_02:
source:
type: mysql
host: db2.example.com
port: 3306
user: read_only_user
password: 654321
databases: [sys]
single-transaction: No
destination:
type: local
path: /var/backups
Environment variables S3_BUCKET, S3_ENDPOINT, S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY will be used if matching parameters are not set in an S3 destination. This allows for simpler configuration if many sources are to be backed up to single S3 destination. That is, config file has highest precedence.
How to run db-backup.
You can download the Helm chart in this repository or you can install it by adding the Helm package repository as described below.
helm repo add charts.balle-petersen.org https://charts.balle-petersen.orghelm install my-db-backup charts.balle-petersen.org/db-backup -f my_values.yamlWhen updating configuration in my_values.local.yaml in the future, or the chart is updated, the following
command can be used to upgrade the running release:
helm upgrade my-db-backup charts.balle-petersen.org/db-backup -f my_values.yaml
docker build -t ddb .docker run -v /local/backups:/etc/backups --rm ddbdocker pull tobiasbp/db-backupdocker run -v /local/backups:/etc/backups --rm tobiasbp/db-backup./do-db-backup.py --config ./backups.local.yamlHere are some alternatives I am aware of
A Helm chart for setting up mysqldump to run as a cron job in Kubernetes.
A shell script with Dockerfile, for backing up MySQL databases with mysqldump and storing them on S3 storage og Google Cloud Storage.
A Helm chart for running database backups as a cron job in Kubernetes.
Content type
Image
Digest
Size
44.8 MB
Last updated
almost 6 years ago
docker pull tobiasbp/db-backup