dbtool-cli: Automating Database Ops with Go

dbtool-cli: Automating Database Ops with Go

Table of Contents

In the world of DevOps, “Toil” (manual, repetitive work) is the enemy. I found myself manually creating database users for developers and writing brittle shell scripts for backups that eventually filled up the disk space.

To solve this, I built dbtool-cli, a unified command-line interface written in Go (Golang) that treats database management as code.

The Problems Solved

  1. Developer Bottlenecks: Developers waiting for Ops to create database users/schemas.
  2. Storage Exhaustion: Standard cron jobs keeping backups indefinitely until the disk is full.
  3. Context Switching: Remembering the syntax differences between CREATE USER in Postgres vs MariaDB.

Key Capabilities

⚑ Automated Provisioning (Productivity)

When a new project starts, dbtool-cli handles the setup in seconds. It abstracts the complexity of different database drivers:

  • Modular Architecture: Designed with Go interfaces to support multiple drivers (PostgreSQL, MariaDB) seamlessly.
  • Secure Defaults: Auto-generates users with strictly scoped privileges.

πŸ›‘οΈ Smart Backup & Retention (Health)

The tool implements a “Backup Health Check” logic directly in Go:

  • Verification: Validates archive integrity before success confirmation.
  • Retention Policy: Automatically applies rotation (e.g., “Keep 7 Daily, 4 Weekly”) to prevent storage exhaustion.

Technical Implementation

I chose Go (Golang) and the Cobra library for this project to ensure:

  • Portability: Compiled into a single static binary that runs on Linux servers, macOS workstations, and Windows.
  • Performance: High-speed execution compared to interpreted bash scripts.
  • Maintainability: Strongly typed code that is easier to extend than complex shell scripts.

Impact & Results

  • 30% Increase in Productivity: Developers can provision their own local environments instantly using the CLI.
  • Zero Storage Incidents: Smart retention policies ensure disk usage remains constant and predictable.
  • Standardized Workflows: Unified command syntax across all database types.

View the Source Code on GitHub

call to action

Ready to build your next project with me?

I’m ready to help you build, improve, and launch your next project β€” just drop a message and let’s get started.

Get Started Now