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
.envconfiguration- Docker support
- Cron compatibility
- Compressed backups (
.gz/.tar.gz)
Designed for servers, VPS, Docker containers, and automated CI backup workflows.
- ✔ 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
auto-database-backuper/
├── backup.sh
├── .env.example
├── docker-compose.yml
├── scripts/
│ ├── backup_mysql.sh
│ ├── backup_postgres.sh
│ ├── backup_mongo.sh
│ └── rotate.sh
└── README.md
Clone the repo:
git clone https://github.com/BaseMax/auto-database-backuper.git
cd auto-database-backuperCopy environment template:
cp .env.example .envEdit .env and configure your DB settings.
MYSQL_HOST=127.0.0.1
MYSQL_PORT=3306
MYSQL_USER=max
MYSQL_PASS=maxpassword
MYSQL_DBS="db1 db2 db3"POSTGRES_HOST=127.0.0.1
POSTGRES_PORT=5432
POSTGRES_USER=max
POSTGRES_PASS=maxpassword
POSTGRES_DBS="db1 db2 db3"MONGO_HOST=127.0.0.1
MONGO_PORT=27017
MONGO_USER=
MONGO_PASS=
MONGO_AUTH_DB=admin
MONGO_DBS="db1 db2 db3"BACKUP_DIR=/var/backups/db
KEEP_BACKUPS=200./backup.shBackups are stored in:
/var/backups/db/
Run once:
docker compose run --rm backupOr schedule it via cron inside host.
Run every day at 3 AM:
0 3 * * * cd /root/auto-database-backuper && ./backup.sh >> backup.log 2>&1
MySQL:
project_mysql_20250101_030000.sql.gz
PostgreSQL:
mydb_pgsql_20250101_030000.sql.gz
MongoDB:
mongo_orders_20250101_030000.tar.gz
Automatically keeps only the latest N backups:
KEEP_BACKUPS=200
Older backups are removed automatically.
MIT License
Copyright © 2025
Seyyed Ali Mohammadiyeh (Max Base) https://github.com/BaseMax
PRs are welcome!
Feel free to add:
- New database drivers
- Cloud upload (S3, Backblaze, FTP)
- Notifications (Telegram/Discord)
- Encryption support (AES-256)