Tools [active]

MariaDB Docker Manager

A Bash script that sets up MariaDB 11.4 LTS with Docker Compose from scratch, then manages databases, users, SSL, and backups through an interactive menu.

Tech
Bash · Docker Compose · MariaDB · OpenSSL
License
MIT
View on GitHub ↗

Problem

A database container is easy to start and easy to leave half-configured: no TLS, a shared superuser for every app, and backups that only exist as a plan. This script makes the safe setup the default and puts the day-to-day tasks behind one menu.

What it does

  • Sets up one MariaDB instance (mariadb:11.4) with Docker Compose: data, backup, and certificate directories, .env, and compose.yaml.
  • TLS required for TCP connections (require_secure_transport=ON) with a script-generated CA; root can only log in from inside the container.
  • Creates a database together with its own owner user, isolated from other databases.
  • Backs up with mariadb-dump to .sql.gz (validated), plus a backup of users and grants.
  • Restores from a list of available backups, locally or from Cloudflare R2.
  • Scheduled backups (systemd timer, or cron) with retention, stored locally, on R2, or both.
  • Password rotation, status, SSL checks, and logs.
  • Backup and restore of other MariaDB servers (another VPS or a managed service) through connection profiles, even without a local instance.

Usage

All generated files stay in the folder that holds the script, so use one folder per instance:

sudo mkdir -p /opt/mariadb
sudo cp mariadb-manager.sh /opt/mariadb/
sudo chmod +x /opt/mariadb/mariadb-manager.sh
sudo /opt/mariadb/mariadb-manager.sh

The first menu option runs the initial setup; the rest of the menu covers daily operations.

Notes

  • Docker Engine and the Compose plugin must already be installed; the script does not install them.
  • Runs as root (or with sudo).
  • R2 uploads use rclone in a container, so nothing extra needs to be installed on the host.