mirror of
https://github.com/jkaninda/mysql-bkup.git
synced 2025-12-11 16:09:40 +01:00
Compare commits
32 Commits
ba7c096bf3
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 8ac6ffc394 | |||
| 59296c0c17 | |||
| 19b64bbad1 | |||
| 640e11b924 | |||
|
|
a746366348 | ||
|
|
64d57a077e | ||
|
|
995db83b7c | ||
| 5d5cbea60b | |||
|
|
2cb5603b88 | ||
| 548de725dd | |||
|
|
37b2867974 | ||
| d6c01c9a4a | |||
|
|
bd92cc6844 | ||
| 3006abac3e | |||
|
|
3a16f6929c | ||
| 2f3ed7d0d8 | |||
|
|
a92bba05e4 | ||
| 7b565d54bd | |||
|
|
d10321dac6 | ||
| d151c50caa | |||
| 07ecec57b3 | |||
| bc4aab6ed0 | |||
| 12c17c18d6 | |||
| 80cd70e153 | |||
|
|
80abdb4299 | ||
| 72b21f00e6 | |||
| 3439c74257 | |||
| 4110ff4e64 | |||
| cb299a35bf | |||
| 23cce10e8c | |||
| 36bca254a9 | |||
| ad18d42145 |
13
Dockerfile
13
Dockerfile
@@ -1,4 +1,4 @@
|
||||
FROM golang:1.24.1 AS build
|
||||
FROM golang:1.25.1 AS build
|
||||
WORKDIR /app
|
||||
ARG appVersion=""
|
||||
|
||||
@@ -10,7 +10,7 @@ RUN go mod download
|
||||
# Build
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-X 'github.com/jkaninda/mysql-bkup/utils.Version=${appVersion}'" -o /app/mysql-bkup
|
||||
|
||||
FROM alpine:3.21.3
|
||||
FROM alpine:3.22.1
|
||||
ENV TZ=UTC
|
||||
ARG WORKDIR="/config"
|
||||
ARG BACKUPDIR="/backup"
|
||||
@@ -18,9 +18,12 @@ ARG BACKUP_TMP_DIR="/tmp/backup"
|
||||
ARG TEMPLATES_DIR="/config/templates"
|
||||
ARG appVersion=""
|
||||
ENV VERSION=${appVersion}
|
||||
LABEL author="Jonas Kaninda"
|
||||
LABEL version=${appVersion}
|
||||
LABEL github="github.com/jkaninda/mysql-bkup"
|
||||
LABEL org.opencontainers.image.title="mysql-bkup"
|
||||
LABEL org.opencontainers.image.description="A lightweight MySQL backup and restore tool"
|
||||
LABEL org.opencontainers.image.licenses="MIT"
|
||||
LABEL org.opencontainers.image.authors="Jonas Kaninda <me@jonaskaninda.com>"
|
||||
LABEL org.opencontainers.image.version=${appVersion}
|
||||
LABEL org.opencontainers.image.source="https://github.com/jkaninda/mysql-bkup"
|
||||
|
||||
RUN apk --update add --no-cache mysql-client mariadb-connector-c tzdata ca-certificates
|
||||
RUN mkdir -p $WORKDIR $BACKUPDIR $TEMPLATES_DIR $BACKUP_TMP_DIR && \
|
||||
|
||||
89
README.md
89
README.md
@@ -3,6 +3,13 @@
|
||||
**MYSQL-BKUP** is a Docker container image designed to **backup, restore, and migrate MySQL databases**.
|
||||
It supports a variety of storage options and ensures data security through GPG encryption.
|
||||
|
||||
MYSQL-BKUP is designed for seamless deployment on **Docker** and **Kubernetes**, simplifying MySQL backup, restoration, and migration across environments.
|
||||
It is a lightweight, multi-architecture solution compatible with **Docker**, **Docker Swarm**, **Kubernetes**, and other container orchestration platforms.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[](https://github.com/jkaninda/mysql-bkup/actions/workflows/tests.yml)
|
||||
[](https://github.com/jkaninda/mysql-bkup/actions/workflows/release.yml)
|
||||
[](https://goreportcard.com/report/github.com/jkaninda/mysql-bkup)
|
||||
@@ -12,9 +19,9 @@ It supports a variety of storage options and ensures data security through GPG e
|
||||
|
||||
## Features
|
||||
|
||||
- **Storage Options:**
|
||||
- Local storage
|
||||
- AWS S3 or any S3-compatible object storage
|
||||
- **Flexible Storage Backends:**
|
||||
- Local filesystem
|
||||
- Amazon S3 & S3-compatible storage (e.g., MinIO, Wasabi)
|
||||
- FTP
|
||||
- SSH-compatible storage
|
||||
- Azure Blob storage
|
||||
@@ -34,16 +41,19 @@ It supports a variety of storage options and ensures data security through GPG e
|
||||
- **Telegram**
|
||||
- **Email**
|
||||
|
||||
## Use Cases
|
||||
## 💡Use Cases
|
||||
|
||||
- **Automated Recurring Backups:** Schedule regular backups for MySQL databases.
|
||||
- **Cross-Environment Migration:** Easily migrate MySQL databases across different environments using `migration` feature.
|
||||
- **Secure Backup Management:** Protect your data with GPG encryption.
|
||||
- **Scheduled Backups**: Automate recurring backups using Docker or Kubernetes.
|
||||
- **Disaster Recovery:** Quickly restore backups to a clean MySQL instance.
|
||||
- **Database Migration**: Seamlessly move data across environments using the built-in `migrate` feature.
|
||||
- **Secure Archiving:** Keep backups encrypted and safely stored in the cloud or remote servers.
|
||||
|
||||
|
||||
Successfully tested on:
|
||||
## ✅ Verified Platforms:
|
||||
MYSQL-BKUP has been tested and runs successfully on:
|
||||
|
||||
- Docker
|
||||
- Docker in Swarm mode
|
||||
- Docker Swarm
|
||||
- Kubernetes
|
||||
- OpenShift
|
||||
|
||||
@@ -59,12 +69,6 @@ Successfully tested on:
|
||||
|
||||
- [PostgreSQL](https://github.com/jkaninda/pg-bkup)
|
||||
|
||||
## Storage:
|
||||
- Local
|
||||
- AWS S3 or any S3 Alternatives for Object Storage
|
||||
- SSH remote storage server
|
||||
- FTP remote storage server
|
||||
- Azure Blob storage
|
||||
|
||||
## Quickstart
|
||||
|
||||
@@ -194,10 +198,7 @@ spec:
|
||||
# Pin the image tag to a specific release version in production.
|
||||
# See available releases: https://github.com/jkaninda/mysql-bkup/releases
|
||||
image: jkaninda/mysql-bkup
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- backup -d dbname
|
||||
command: ["backup", "-d", "dbname"]
|
||||
resources:
|
||||
limits:
|
||||
memory: "128Mi"
|
||||
@@ -238,10 +239,7 @@ spec:
|
||||
containers:
|
||||
- name: pg-bkup
|
||||
image: jkaninda/mysql-bkup
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- backup -d dbname
|
||||
command: ["backup", "-d", "dbname"]
|
||||
env:
|
||||
- name: DB_HOST
|
||||
value: "mysql"
|
||||
@@ -260,6 +258,51 @@ spec:
|
||||
restartPolicy: OnFailure
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Why Use MYSQL-BKUP?
|
||||
|
||||
**MYSQL-BKUP** isn't just another MySQL backup tool, it's a robust, production-ready solution purpose-built for modern DevOps workflows.
|
||||
|
||||
Here’s why developers, sysadmins, and DevOps choose **MYSQL-BKUP**:
|
||||
|
||||
### ✅ All-in-One Backup, Restore & Migration
|
||||
|
||||
Whether you're backing up a single database, restoring critical data, or migrating across environments, MYSQL-BKUP handles it all with a **single, unified CLI** no scripting gymnastics required.
|
||||
|
||||
|
||||
### 🔄 Works Everywhere You Deploy
|
||||
|
||||
Designed to be cloud-native:
|
||||
|
||||
* **Runs seamlessly on Docker, Docker Swarm, and Kubernetes**
|
||||
* Supports **CronJobs** for automated scheduled backups
|
||||
* Compatible with GitOps and CI/CD workflows
|
||||
|
||||
### ☁️ Flexible Storage Integrations
|
||||
|
||||
Store your backups **anywhere**:
|
||||
|
||||
* Local disks
|
||||
* Amazon S3, MinIO, Wasabi, Azure Blob, FTP, SSH
|
||||
|
||||
### 🔒 Enterprise-Grade Security
|
||||
|
||||
* **GPG Encryption**: Protect sensitive data with optional encryption before storing backups locally or in the cloud.
|
||||
* **Secure Storage** Options: Supports S3, Azure Blob, SFTP, and SSH with encrypted transfers, keeping backups safe from unauthorized access.
|
||||
|
||||
### 📬 Instant Notifications
|
||||
|
||||
Stay in the loop with real-time notifications via **Telegram** and **Email**. Know immediately when a backup succeeds—or fails.
|
||||
|
||||
### 🏃♂️ Lightweight and Fast
|
||||
|
||||
Written in **Go**, MYSQL-BKUP is fast, multi-arch compatible (`amd64`, `arm64`, `arm/v7`), and optimized for minimal memory and CPU usage. Ideal for both cloud and edge deployments.
|
||||
|
||||
### 🧪 Tested. Verified. Trusted.
|
||||
|
||||
Actively maintained with **automated testing**, **Docker image size optimizations**, and verified support across major container platforms.
|
||||
|
||||
---
|
||||
## Available image registries
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ nav_order: 1
|
||||
**MYSQL-BKUP** is a Docker container image designed to **backup, restore, and migrate MySQL databases**.
|
||||
It supports a variety of storage options and ensures data security through GPG encryption.
|
||||
|
||||
**MYSQL-BKUP** is designed for seamless deployment on **Docker** and **Kubernetes**, simplifying MySQL backup, restoration, and migration across environments.
|
||||
It is a lightweight, multi-architecture solution compatible with **Docker**, **Docker Swarm**, **Kubernetes**, and other container orchestration platforms.
|
||||
---
|
||||
|
||||
## Key Features
|
||||
@@ -39,11 +41,21 @@ It supports a variety of storage options and ensures data security through GPG e
|
||||
|
||||
---
|
||||
|
||||
## Use Cases
|
||||
## 💡Use Cases
|
||||
|
||||
- **Automated Recurring Backups:** Schedule regular backups for MySQL databases.
|
||||
- **Cross-Environment Migration:** Easily migrate MySQL databases across different environments using `migration` feature.
|
||||
- **Secure Backup Management:** Protect your data with GPG encryption.
|
||||
- **Scheduled Backups**: Automate recurring backups using Docker or Kubernetes.
|
||||
- **Disaster Recovery:** Quickly restore backups to a clean MySQL instance.
|
||||
- **Database Migration**: Seamlessly move data across environments using the built-in `migrate` feature.
|
||||
- **Secure Archiving:** Keep backups encrypted and safely stored in the cloud or remote servers.
|
||||
|
||||
|
||||
## ✅ Verified Platforms:
|
||||
MYSQL-BKUP has been tested and runs successfully on:
|
||||
|
||||
- Docker
|
||||
- Docker Swarm
|
||||
- Kubernetes
|
||||
- OpenShift
|
||||
|
||||
---
|
||||
|
||||
|
||||
8
go.mod
8
go.mod
@@ -1,16 +1,16 @@
|
||||
module github.com/jkaninda/mysql-bkup
|
||||
|
||||
go 1.23.2
|
||||
go 1.24.5
|
||||
|
||||
require github.com/spf13/pflag v1.0.6 // indirect
|
||||
require github.com/spf13/pflag v1.0.9 // indirect
|
||||
|
||||
require (
|
||||
github.com/go-mail/mail v2.3.1+incompatible
|
||||
github.com/jkaninda/encryptor v0.0.0-20241111100652-926393c9437e
|
||||
github.com/jkaninda/go-storage v0.1.3
|
||||
github.com/jkaninda/go-utils v0.1.1
|
||||
github.com/jkaninda/go-utils v0.1.3
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
github.com/spf13/cobra v1.9.1
|
||||
github.com/spf13/cobra v1.10.1
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
|
||||
12
go.sum
12
go.sum
@@ -43,8 +43,8 @@ github.com/jkaninda/encryptor v0.0.0-20241111100652-926393c9437e h1:jtFKZHt/PLGQ
|
||||
github.com/jkaninda/encryptor v0.0.0-20241111100652-926393c9437e/go.mod h1:Y1EXpPWQ9PNd7y7E6ez3xgnzZc8fuDWXwX/1/dXNCE4=
|
||||
github.com/jkaninda/go-storage v0.1.3 h1:lEpHVgFLKSvjsi/6tAek96Y07za3vxmsXF2/+jiCMZU=
|
||||
github.com/jkaninda/go-storage v0.1.3/go.mod h1:zVRnLprBk/9AUz2+za6Y03MgoNYrqKLy3edVtjqMaps=
|
||||
github.com/jkaninda/go-utils v0.1.1 h1:PMrtXR9d51YzHo85y9Z6YVL0YyBURbRTPemHVbFDqZg=
|
||||
github.com/jkaninda/go-utils v0.1.1/go.mod h1:pf0/U6k4JbxlablM2G4eSTZdQ2LFshfAsCK5Q8qNfGo=
|
||||
github.com/jkaninda/go-utils v0.1.3 h1:BhVRHpR6JIGhE7JVgqOgiFketIqmNtvMvYpveVwDqqY=
|
||||
github.com/jkaninda/go-utils v0.1.3/go.mod h1:Aa54jEAcDykc3CnOdreqZG80UfSZOvrYecyusu+oPb4=
|
||||
github.com/jlaffaye/ftp v0.2.0 h1:lXNvW7cBu7R/68bknOX3MrRIIqZ61zELs1P2RAiA3lg=
|
||||
github.com/jlaffaye/ftp v0.2.0/go.mod h1:is2Ds5qkhceAPy2xD6RLI6hmp/qysSoymZ+Z2uTnspI=
|
||||
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
|
||||
@@ -68,10 +68,10 @@ github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzG
|
||||
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
|
||||
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
|
||||
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
|
||||
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
|
||||
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s=
|
||||
github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0=
|
||||
github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
|
||||
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
|
||||
@@ -117,6 +117,9 @@ func createBackupTask(db *dbConfig, config *BackupConfig) {
|
||||
if config.all && !config.allInOne {
|
||||
backupAll(db, config)
|
||||
} else {
|
||||
if db.dbName == "" && !config.all {
|
||||
utils.Fatal("Database name is required, use DB_NAME environment variable or -d flag")
|
||||
}
|
||||
backupTask(db, config)
|
||||
}
|
||||
}
|
||||
@@ -249,8 +252,10 @@ func BackupDatabase(db *dbConfig, backupFileName string, disableCompression, all
|
||||
|
||||
dumpArgs := []string{fmt.Sprintf("--defaults-file=%s", mysqlClientConfig)}
|
||||
if all && singleFile {
|
||||
utils.Info("Backing up all databases...")
|
||||
dumpArgs = append(dumpArgs, "--all-databases", "--single-transaction", "--routines", "--triggers")
|
||||
} else {
|
||||
utils.Info("Backing up %s database...", db.dbName)
|
||||
dumpArgs = append(dumpArgs, db.dbName)
|
||||
}
|
||||
|
||||
|
||||
@@ -251,12 +251,10 @@ func initBackupConfig(cmd *cobra.Command) *BackupConfig {
|
||||
utils.GetEnv(cmd, "cron-expression", "BACKUP_CRON_EXPRESSION")
|
||||
utils.GetEnv(cmd, "path", "REMOTE_PATH")
|
||||
utils.GetEnv(cmd, "config", "BACKUP_CONFIG_FILE")
|
||||
utils.GetEnv(cmd, "dbname", "DB_NAME")
|
||||
// Get flag value and set env
|
||||
remotePath := utils.GetEnvVariable("REMOTE_PATH", "SSH_REMOTE_PATH")
|
||||
storage = utils.GetEnv(cmd, "storage", "STORAGE")
|
||||
prune := false
|
||||
configFile := os.Getenv("BACKUP_CONFIG_FILE")
|
||||
backupRetention := utils.GetIntEnv("BACKUP_RETENTION_DAYS")
|
||||
if backupRetention > 0 {
|
||||
prune = true
|
||||
@@ -281,10 +279,6 @@ func initBackupConfig(cmd *cobra.Command) *BackupConfig {
|
||||
encryption = true
|
||||
usingKey = false
|
||||
}
|
||||
dbName := os.Getenv("DB_NAME")
|
||||
if dbName == "" && !all && configFile == "" {
|
||||
utils.Fatal("Database name is required, use DB_NAME environment variable or -d flag")
|
||||
}
|
||||
// Initialize backup configs
|
||||
config := BackupConfig{}
|
||||
config.backupRetention = backupRetention
|
||||
|
||||
Reference in New Issue
Block a user