dbbackup

command module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 1 Imported by: 0

README

dbbackup

CI Release Go Report Card GitHub release

A CLI tool for backing up databases to cloud storage. Currently supports MySQL → Cloudflare R2, designed to be extensible for additional databases and storage backends.

Features

  • MySQL backup via pure Go library (no external dependencies) or mysqldump binary
  • Cloudflare R2 storage (S3-compatible)
  • Gzip compression (optional)
  • Retention policies — keep N latest backups or delete older than X days
  • Telegram notifications on success/failure
  • TOML configuration with CLI flag overrides
  • Extensible architecture — easy to add new DB engines, storage backends, or notification channels

Installation

From releases

Download the latest binary from the Releases page.

From source
go install github.com/thanhtaivtt/dbbackup@latest
Build locally
make build

Usage

# Copy and edit config
cp config.example.toml config.toml

# Run backup
dbbackup backup --config config.toml

# With CLI overrides
dbbackup backup --config config.toml --compress --retention-count 5

# Verbose output
dbbackup backup --config config.toml -v
Cron setup (daily at 2AM)
0 2 * * * /usr/local/bin/dbbackup backup --config /etc/dbbackup/config.toml

Configuration

See config.example.toml for a full example.

[backup]
Key Type Default Description
compress bool false Enable gzip compression for backup files
dump_method string "go" MySQL dump method: "go" (pure Go library, supports remote DB) or "binary" (requires mysqldump CLI installed on host)
[database.mysql]
Key Type Default Description
host string "localhost" MySQL server hostname or IP
port int 3306 MySQL server port
user string required MySQL user
password string required MySQL password
databases []string required List of database names to back up
[storage.r2]
Key Type Default Description
account_id string required Cloudflare account ID
access_key_id string required R2 API token Access Key ID
access_key_secret string required R2 API token Secret Access Key
bucket string required R2 bucket name
path_prefix string "" Prefix for object keys (e.g. "mysql/"mysql/mydb_20240101_020000.sql.gz)
[retention]
Key Type Default Description
strategy string "count" Retention strategy: "count" (keep N latest) or "days" (keep for N days)
count int 7 Number of backups to keep (when strategy = "count")
days int 30 Days to keep backups (when strategy = "days")
[notification.telegram]
Key Type Default Description
enabled bool false Enable Telegram notifications
bot_token string required Telegram Bot API token (from @BotFather)
chat_id string required Target chat/group ID (use @userinfobot to find)
Minimal config example
[database.mysql]
user = "root"
password = "secret"
databases = ["mydb"]

[storage.r2]
account_id = "your-account-id"
access_key_id = "your-access-key-id"
access_key_secret = "your-access-key-secret"
bucket = "db-backups"
Full config example
[backup]
compress = true
dump_method = "go"

[database.mysql]
host = "localhost"
port = 3306
user = "root"
password = "secret"
databases = ["mydb", "analytics"]

[storage.r2]
account_id = "your-account-id"
access_key_id = "your-access-key-id"
access_key_secret = "your-access-key-secret"
bucket = "db-backups"
path_prefix = "mysql/"

[retention]
strategy = "count"
count = 7

[notification.telegram]
enabled = true
bot_token = "123456:ABC-DEF"
chat_id = "-1001234567890"

CLI Flags

Flag Description
--config Config file path (default: config.toml)
--compress Enable gzip compression
--retention-count N Keep N latest backups
--retention-days N Keep backups for N days
-v, --verbose Enable debug logging
--version Print version info

Commands

Command Description
backup Run database backup
update Check for new version on GitHub

Extending

Add a new database

Implement the Dumper interface in internal/dumper/:

type Dumper interface {
    Dump(ctx context.Context, database string) (io.ReadCloser, error)
    Name() string
}
Add a new storage backend

Implement the Storage interface in internal/storage/:

type Storage interface {
    Upload(ctx context.Context, key string, reader io.Reader) error
    List(ctx context.Context, prefix string) ([]Object, error)
    Delete(ctx context.Context, keys []string) error
    Name() string
}
Add a new notification channel

Implement the Notifier interface in internal/notifier/:

type Notifier interface {
    Notify(ctx context.Context, msg Message) error
    Name() string
}

License

MIT — see LICENSE.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL