# db-remote-backup **Repository Path**: nosun/db-remote-backup ## Basic Information - **Project Name**: db-remote-backup - **Description**: mysql backup 工具,使用 go 语言开发,支持 ssh 远程备份 - **Primary Language**: Go - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-10 - **Last Updated**: 2026-03-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # dbbackup MySQL remote backup tool with cron-friendly run-once execution, SSH transfer, retention policy, and Feishu failure notification. ## Features - Run-once command for cron/system scheduler - MySQL dump and gzip compression - SHA256 checksum generation and remote verification - SSH private-key transfer with known_hosts verification - Retention policy: `days + min_keep` for local and remote files - Feishu failure-only notification - JSON logs for easy ingestion ## Commands - `dbbackup run --config ./config.yaml` - `dbbackup validate --config ./config.yaml` - `dbbackup test-notify --config ./config.yaml` ## Build ```bash go mod tidy go build -o dbbackup ./cmd/dbbackup ``` ### One-command package (local + amd64) ```bash make package ``` This command generates: - `./dbbackup` (current machine) - `./dbbackup-linux-amd64` (Linux x86_64 server) - `./dbbackup-linux-arm64` (Linux ARM64 server) ## Quick Deploy 1. Build binaries in project root: `make package` 2. Create `./config.yaml` in project root (copy from `config.example.yaml`) 3. Ensure MySQL client (`mysqldump`) is installed 4. Set MySQL password env variable from config `mysql.password_env` 5. Add cron: ```cron 0 2 * * * cd /path/to/db-remote-backup && ./dbbackup run --config ./config.yaml >> ./dbbackup.log 2>&1 ``` ## Config Example See [`config.example.yaml`](./config.example.yaml). Recommended: copy it to `./config.yaml` and keep real secrets in environment variables. `mysql.password_env` is optional. - Set it when MySQL requires password auth (for example `DBBACKUP_MYSQL_PASSWORD`). - Leave it empty (`""`) when using passwordless local account. - Or set `mysql.password` directly in config when you prefer inline password. `notify.feishu.key` is recommended. - Only set the bot key (UUID-like value), program will build webhook URL internally. - `notify.feishu.webhook` is still supported for backward compatibility. `ssh` config is optional when you only need local backups. - Set `retention.apply_remote: false` - Leave `ssh.host` empty (then upload/remote-verify/remote-retention are skipped) Backup file layout: - Local: `//_.sql.gz` - Remote: `//_.sql.gz` Disk safety check: - `runtime.min_free_gb` (default `5`) is enforced before backup starts. - If free disk on `local.base_dir` is lower than this threshold, job fails and sends Feishu alert (when enabled). ## Ops Docs - Deployment runbook: [`docs/DEPLOYMENT.md`](./docs/DEPLOYMENT.md) - Ubuntu deploy script: [`scripts/deploy_ubuntu.sh`](./scripts/deploy_ubuntu.sh) - Release script: [`scripts/publish_release.sh`](./scripts/publish_release.sh) - Version installer: [`scripts/install_by_version.sh`](./scripts/install_by_version.sh) ## Release & Install - Publish one version (build + package + commit + tag + push): ```bash ./scripts/publish_release.sh v1.0.1 ``` - Server one-command install (only version is required): ```bash bash <(curl -fsSL https://gitee.com/nosun/db-remote-backup/raw/main/scripts/install_by_version.sh) v1.0.1 ``` Installer security: - It downloads `SHA256SUMS` from the same release path and verifies package hash before install.