- Shell 95.4%
- Dockerfile 4.6%
|
All checks were successful
Release / Release (push) Successful in 17s
Reviewed-on: #4 |
||
|---|---|---|
| .forgejo/workflows | ||
| .idea | ||
| Dockerfile | ||
| entrypoint.sh | ||
| LICENSE | ||
| README.md | ||
mysql-backup is a MySQL backup helper that:
- Takes the dump of one or more MySQL databases
- Uploads it to either AWS S3 or SFTP destination
- Reports to WebGazer (optional)
Usage
Environment variables
Required variables
| Variable | Required | Description |
|---|---|---|
| DESTINATION_KIND | ✔ | Destination type: s3 or sftp |
| MYSQL_DATABASES | ✔ | Space-separated MySQL database name(s) |
| MYSQL_PASSWORD | ✔ | MySQL server password |
MySQL configuration
| Variable | Required | Default value | Description |
|---|---|---|---|
| MYSQL_HOST | mysql | MySQL server host | |
| MYSQL_PORT | 3306 | MySQL server port | |
| MYSQL_USER | root | MySQL server user |
S3 destination (when DESTINATION_KIND=s3)
| Variable | Required | Default value | Description |
|---|---|---|---|
| S3_ACCESS_KEY_ID | ✔ | Access key id for the AWS account | |
| S3_REGION | ✔ | Region for the AWS bucket | |
| S3_SECRET_ACCESS_KEY | ✔ | Secret access key for the AWS account | |
| DESTINATION_PATH | ✔ | S3 bucket and path (e.g. "my-bucket/mysql-backup") | |
| S3_PROVIDER | AWS | S3 provider (AWS, MinIO, etc.) | |
| S3_STORAGE_CLASS | STANDARD_IA | AWS S3 storage class (see https://aws.amazon.com/s3/storage-classes/ and https://rclone.org/s3/#s3-storage-class for options) |
SFTP destination (when DESTINATION_KIND=sftp)
| Variable | Required | Default value | Description |
|---|---|---|---|
| SFTP_HOST | ✔ | SFTP server hostname | |
| SFTP_USER | ✔ | SFTP username | |
| DESTINATION_PATH | ✔ | SFTP destination path | |
| SFTP_PORT | 22 | SFTP server port | |
| SFTP_PASSWORD | ⚠ | SFTP password (either this or SFTP_PRIVATE_KEY must be set) | |
| SFTP_PRIVATE_KEY | ⚠ | Base64-encoded private key (either this or SFTP_PASSWORD must be set) |
Optional variables
| Variable | Required | Description |
|---|---|---|
| WEBGAZER_HEARTBEAT_URL | WebGazer Heartbeat Monitor URL |
Note: For SFTP authentication, you must provide either SFTP_PASSWORD or SFTP_PRIVATE_KEY, but not both.
Running
S3 Example
$ docker run \
-e DESTINATION_KIND=s3 \
-e S3_ACCESS_KEY_ID=<aws_access_key_id> \
-e S3_REGION=<aws_region> \
-e S3_SECRET_ACCESS_KEY=<aws_secret_access_key> \
-e DESTINATION_PATH=<bucket/path> \
-e S3_STORAGE_CLASS=<aws_s3_storage_class[STANDARD_IA]> \
-e MYSQL_DATABASES="<database1 database2 ...>" \
-e MYSQL_HOST=<mysql_hostname[mysql]> \
-e MYSQL_PASSWORD=<mysql_password> \
-e MYSQL_PORT=<mysql_port[3306]> \
-e MYSQL_USER=<mysql_user[root]> \
-e WEBGAZER_HEARTBEAT_URL=<webgazer_heartbeat_url> \
th0th/mysql-backup
SFTP Example
$ docker run \
-e DESTINATION_KIND=sftp \
-e SFTP_HOST=<sftp_host> \
-e SFTP_USER=<sftp_user> \
-e SFTP_PASSWORD=<sftp_password> \
-e DESTINATION_PATH=<sftp_path> \
-e SFTP_PORT=<sftp_port[22]> \
-e MYSQL_DATABASES="<database1 database2 ...>" \
-e MYSQL_HOST=<mysql_hostname[mysql]> \
-e MYSQL_PASSWORD=<mysql_password> \
-e MYSQL_PORT=<mysql_port[3306]> \
-e MYSQL_USER=<mysql_user[root]> \
-e WEBGAZER_HEARTBEAT_URL=<webgazer_heartbeat_url> \
th0th/mysql-backup
SFTP with Private Key Example
$ docker run \
-e DESTINATION_KIND=sftp \
-e SFTP_HOST=<sftp_host> \
-e SFTP_USER=<sftp_user> \
-e SFTP_PRIVATE_KEY=<base64_encoded_private_key> \
-e DESTINATION_PATH=<sftp_path> \
-e SFTP_PORT=<sftp_port[22]> \
-e MYSQL_DATABASES="<database1 database2 ...>" \
-e MYSQL_HOST=<mysql_hostname[mysql]> \
-e MYSQL_PASSWORD=<mysql_password> \
-e MYSQL_PORT=<mysql_port[3306]> \
-e MYSQL_USER=<mysql_user[root]> \
-e WEBGAZER_HEARTBEAT_URL=<webgazer_heartbeat_url> \
th0th/mysql-backup
Examples
S3 Example
$ docker run \
-e DESTINATION_KIND=s3 \
-e S3_ACCESS_KEY_ID=g9XqNnqKmUk6xqwkStkN \
-e S3_REGION=eu-west-1 \
-e DESTINATION_PATH=my-bucket/mysql-backup \
-e S3_STORAGE_CLASS=GLACIER \
-e S3_SECRET_ACCESS_KEY=GLBZ8mQf27UL57YHbkLhXWtfJWVwtUBbQup6mFzw \
-e MYSQL_DATABASES="database1 database2" \
-e MYSQL_HOST=mysql \
-e MYSQL_PASSWORD=mysql_password \
-e MYSQL_PORT=3306 \
-e MYSQL_USER=mysql_user \
-e WEBGAZER_HEARTBEAT_URL=https://heartbeat.webgazer.io/1-8f713c75d659 \
th0th/mysql-backup
SFTP Example
$ docker run \
-e DESTINATION_KIND=sftp \
-e SFTP_HOST=sftp.example.com \
-e SFTP_USER=backup_user \
-e SFTP_PASSWORD=secure_password \
-e DESTINATION_PATH=/backups/mysql \
-e SFTP_PORT=22 \
-e MYSQL_DATABASES="database1 database2" \
-e MYSQL_HOST=mysql \
-e MYSQL_PASSWORD=mysql_password \
-e MYSQL_PORT=3306 \
-e MYSQL_USER=mysql_user \
-e WEBGAZER_HEARTBEAT_URL=https://heartbeat.webgazer.io/1-8f713c75d659 \
th0th/mysql-backup
Shameless plug
I am an indie hacker, and I am running two services that might be useful for your business. Check them out :)
WebGazer
WebGazer is a monitoring service that checks your website, cron jobs, or scheduled tasks on a regular basis. It notifies you with instant alerts in case of a problem. That way, you have peace of mind about the status of your service without manually checking it.
PoeticMetric
PoeticMetric is a privacy-first, regulation-compliant, blazingly fast analytics tool.
No cookies or personal data collection. So you don't have to worry about cookie banners or GDPR, CCPA, and PECR compliance.
License
Copyright © 2022, Gokhan Sari. Released under the MIT License.

