Go-Devops-Cutter is a lightweight CLI tool built in Go for backing up PostgreSQL and MySQL databases to your local machine. It uses Docker-based database clients, so you don't need to install database tools locally.
Perfect for DevOps engineers who need quick, reliable database backups without installing database clients or managing complex tooling.
- ποΈ Database Backup - Backup PostgreSQL and MySQL databases to local machine
- π³ Docker-based Clients - No need to install
pg_dumpormysqldumplocally - π SSH Jump Host Support - Secure access to databases behind firewalls via SSH tunneling
- π¦ Auto Compression - Built-in gzip compression for backups
- π Backup Listing - List backup files in current directory
- β‘ Fast & Lightweight - Single binary, minimal dependencies
- π οΈ Simple CLI - Easy to use command-line interface
- Language: Go 1.24
- CLI Framework: Cobra
- Containerization: Docker (for database clients)
github.com/spf13/cobra v1.10.1 // CLI framework
github.com/gin-gonic/gin v1.11.0 // HTTP framework (for health API)- Go 1.24 or higher
- Docker (for running database clients)
- Make
- SSH client (for SSH jump host feature)
# Clone the repository
git clone https://github.com/PandhuWibowo/go-devops-cutter.git
cd go-devops-cutter
# Install dependencies
make deps
# Install git hooks (recommended for development)
./scripts/install-hooks.sh
# Build the CLI
make build-cli
# Install CLI system-wide (optional)
make install-clicutter db backup - Backup database to local machine
Required Flags:
--database- Database name--username- Database username
Optional Flags:
--type- Database type:postgresormysql(default: postgres)--host- Database host (default: localhost)--port- Database port (default: 5432 for postgres, 3306 for mysql)--password- Database password (prompted if not provided)--output- Output file path (auto-generated if not specified)--compress- Compress with gzip (default: true)--ssh-jump- SSH jump host for accessing databases behind firewalls (format: user@host)
cutter db list - List backup files (.sql) in current directory
# PostgreSQL backup (direct connection)
cutter db backup \
--type postgres \
--host localhost \
--port 5432 \
--username dbuser \
--password dbpass \
--database myapp
# MySQL backup with custom output
cutter db backup \
--type mysql \
--host 192.168.1.100 \
--port 3306 \
--username root \
--password secret \
--database production \
--output ~/backups/prod_backup.sql.gz
# Backup via SSH jump host (for databases behind firewalls)
cutter db backup \
--type postgres \
--host 10.0.1.50 \
--port 5432 \
--username appuser \
--password dbpass \
--database internal_db \
--ssh-jump devops@jumphost.company.com
# List all backup files
cutter db listThe --ssh-jump flag enables access to databases behind firewalls or in private networks through an SSH bastion/jump host.
How it works:
- Creates an SSH tunnel from your local machine to the database through the jump host
- Automatically selects an available local port for the tunnel
- Runs the database backup through the tunnel
- Cleans up the SSH connection after backup completes
Requirements:
- SSH access to the jump host must be configured (SSH key-based authentication recommended)
- Jump host must have network access to the target database
- Format:
user@jumphostoruser@jumphost:port
Example:
# Ensure your SSH key is loaded
ssh-add ~/.ssh/id_rsa
# Backup database behind firewall
cutter db backup \
--type postgres \
--host 10.0.1.50 \
--port 5432 \
--username dbuser \
--password dbpass \
--database production \
--ssh-jump devops@jumphost.company.comThe project includes a minimal health check API server for monitoring.
# Build and run
make build-api
./build/devops-cutter-api
# Or run directly
make run-api
# Custom port (default: 8080)
PORT=3000 ./build/devops-cutter-apiGET /health - Health check endpoint
Response:
{
"status": "ok",
"version": "0.1.0"
}Example:
curl http://localhost:8080/health.
βββ cmd/
β βββ api/
β β βββ main.go # Health check API server
β β βββ main_test.go # API tests
β βββ cutter/
β βββ main.go # CLI entry point
βββ internal/
β βββ cli/
β βββ commands/
β βββ db.go # Database backup commands
β βββ db_test.go # Command tests
βββ pkg/
β βββ client/
β βββ client.go # HTTP client utilities
β βββ client_test.go # Client tests
βββ build/ # Build artifacts (generated)
β βββ cutter # CLI binary
β βββ devops-cutter-api # API binary
βββ Makefile
βββ go.mod
βββ go.sum
βββ LICENSE
βββ README.md
Install git hooks to automatically run tests before commits and pushes:
# Install hooks (run once after cloning)
./scripts/install-hooks.shPre-commit hook:
- Checks code formatting
- Runs
go vet - Verifies
go.modis tidy - Runs all tests
- Builds project
Pre-push hook:
- Runs tests with coverage
- Builds all binaries
- Warns about TODO/FIXME comments
- Confirms push to main branch
Skip hooks when needed:
git commit --no-verify # Skip pre-commit
git push --no-verify # Skip pre-pushSee scripts/README.md for more details.
# Development
make deps # Download and tidy dependencies
make build # Build all binaries (API + CLI)
make build-cli # Build CLI only
make build-api # Build API server only
make run-api # Run API server locally
make test # Run tests
make clean # Clean build artifacts
# Installation
make install-cli # Install CLI to /usr/local/bin-
Install Go 1.24+
go version
-
Install Docker
docker --version
-
Install Dependencies
make deps
-
Build and Test
make build-cli ./build/cutter --help ./build/cutter db --help
# Run all tests
make test
# Run tests with coverage
go test -v -cover ./...
# Run specific package tests
go test -v ./internal/cli/commands
go test -v ./cmd/api
go test -v ./pkg/client# Build for production
make build-cli
# Deploy to remote server
scp build/cutter user@server:/usr/local/bin/
# Or install locally
sudo cp build/cutter /usr/local/bin/# Build for production
make build-api
# Deploy to server
scp build/devops-cutter-api user@server:/opt/devops-cutter/
# Run with systemd (example)
# /etc/systemd/system/devops-cutter-api.service:
# [Unit]
# Description=DevOps Cutter Health Check API
#
# [Service]
# ExecStart=/opt/devops-cutter/devops-cutter-api
# Environment=PORT=8080
# Restart=always
#
# [Install]
# WantedBy=multi-user.targetContributions are welcome! Here's how you can help:
- Fork the repository
- Create a new branch:
git checkout -b feature/your-feature - Make your changes and add tests
- Run tests:
make test - Commit your changes:
git commit -am 'Add feature' - Push to your branch:
git push origin feature/your-feature - Open a pull request
Please ensure your code:
- Follows Go best practices
- Includes appropriate tests
- Has clear commit messages
- Updates documentation as needed
This project is licensed under the MIT License. See LICENSE file for details.
- Cobra - CLI framework for Go
- Gin - HTTP web framework
- Docker - Container platform for database clients
Made with β€οΈ by Pandhu Wibowo