Skip to content

auto-database-backuper is a flexible, production-ready backup system designed to automatically create compressed backups of MySQL/MariaDB, PostgreSQL, and MongoDB databases. It supports multiple databases per engine, custom host/port settings, environment-based configuration, Docker integration, and automated backup rotation.

License

Notifications You must be signed in to change notification settings

BaseMax/auto-database-backuper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📦 auto-database-backuper

A simple, production-ready tool that automatically creates compressed backups of MySQL/MariaDB, PostgreSQL, and MongoDB databases. It supports multiple databases, custom hosts and ports, .env configuration, Docker usage, and automatic backup rotation making it ideal for servers, VPS setups, cron jobs, and CI pipelines.

A lightweight, production-ready, multi-database backup system with support for:

  • MySQL / MariaDB
  • PostgreSQL
  • MongoDB
  • Automatic backup rotation
  • .env configuration
  • Docker support
  • Cron compatibility
  • Compressed backups (.gz / .tar.gz)

Designed for servers, VPS, Docker containers, and automated CI backup workflows.


🚀 Features

  • ✔ Backup multiple MySQL/MariaDB databases
  • ✔ Backup multiple PostgreSQL databases
  • ✔ Backup multiple MongoDB databases
  • ✔ Configurable through .env
  • ✔ Supports custom host, port, username/password
  • ✔ Fully automatic rotation (keep N recent backups)
  • ✔ Clean logs & error handling
  • ✔ Works standalone or inside Docker
  • ✔ Simple structure & easy customization

📁 Project Structure

auto-database-backuper/
├── backup.sh
├── .env.example
├── docker-compose.yml
├── scripts/
│   ├── backup_mysql.sh
│   ├── backup_postgres.sh
│   ├── backup_mongo.sh
│   └── rotate.sh
└── README.md

⚙️ Installation

Clone the repo:

git clone https://github.com/BaseMax/auto-database-backuper.git
cd auto-database-backuper

Copy environment template:

cp .env.example .env

Edit .env and configure your DB settings.


🔧 Configuration (.env)

MySQL / MariaDB

MYSQL_HOST=127.0.0.1
MYSQL_PORT=3306
MYSQL_USER=max
MYSQL_PASS=maxpassword
MYSQL_DBS="db1 db2 db3"

PostgreSQL

POSTGRES_HOST=127.0.0.1
POSTGRES_PORT=5432
POSTGRES_USER=max
POSTGRES_PASS=maxpassword
POSTGRES_DBS="db1 db2 db3"

MongoDB

MONGO_HOST=127.0.0.1
MONGO_PORT=27017
MONGO_USER=
MONGO_PASS=
MONGO_AUTH_DB=admin
MONGO_DBS="db1 db2 db3"

Backup settings

BACKUP_DIR=/var/backups/db
KEEP_BACKUPS=200

🧪 Run Backup Manually

./backup.sh

Backups are stored in:

/var/backups/db/

🐳 Docker Usage

Run once:

docker compose run --rm backup

Or schedule it via cron inside host.


⏰ Cron Usage (Recommended)

Run every day at 3 AM:

0 3 * * * cd /root/auto-database-backuper && ./backup.sh >> backup.log 2>&1

🗃 Backup Output Examples

MySQL:

project_mysql_20250101_030000.sql.gz

PostgreSQL:

mydb_pgsql_20250101_030000.sql.gz

MongoDB:

mongo_orders_20250101_030000.tar.gz

🔄 Backup Rotation

Automatically keeps only the latest N backups:

KEEP_BACKUPS=200

Older backups are removed automatically.


📜 License

MIT License

Copyright © 2025

Seyyed Ali Mohammadiyeh (Max Base) https://github.com/BaseMax


⭐ Contributing

PRs are welcome!

Feel free to add:

  • New database drivers
  • Cloud upload (S3, Backblaze, FTP)
  • Notifications (Telegram/Discord)
  • Encryption support (AES-256)

About

auto-database-backuper is a flexible, production-ready backup system designed to automatically create compressed backups of MySQL/MariaDB, PostgreSQL, and MongoDB databases. It supports multiple databases per engine, custom host/port settings, environment-based configuration, Docker integration, and automated backup rotation.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages