Download the PHP package indiehd/mysql-db-backup without Composer
On this page you can find all versions of the php package indiehd/mysql-db-backup. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package mysql-db-backup
MySQL Database Backup
A PHP CLI tool for automated MySQL/MariaDB database backups with intelligent deduplication and compression.
Features
- ✅ Automated backups of all databases (excluding system databases)
- ✅ Intelligent deduplication - skips backups if database content hasn't changed (SHA1 hash comparison)
- ✅ Automatic compression - gzip compression of backup files
- ✅ Organized storage - separate directories for each database
- ✅ Cron-ready - designed for scheduled execution
- ✅ Docker support - includes Dockerfile for containerized usage
- ✅ Flexible configuration - INI file or environment variables
Requirements
- PHP 8.0 or higher (for native installation)
mysqliPHP extension (for native installation)- Docker (for containerized installation - recommended)
- MySQL or MariaDB server
- System executables:
mysqldump,gzip,gunzip,sha1sum(included in Docker image)
Docker Setup Prerequisites
If using Docker (recommended), ensure your user has Docker permissions:
Database User Setup
Choose Your Deployment Scenario
Pick the option that matches your setup:
| Scenario | User Setup | Network Mode | Best For |
|---|---|---|---|
| A: Localhost MySQL | 'backup'@'localhost' |
--network host |
Single server, MySQL on localhost (simplest) |
| B: Isolated Container | 'backup'@'%' |
bridge (default) |
Better isolation, any Docker setup |
| C: Multi-Container | 'backup'@'%' |
Custom network | MySQL in another container |
Scenario A: Localhost MySQL (Recommended for Single Server)
Best for: MySQL/MariaDB running on the same server as Docker
Configuration (.env):
Important: Use 127.0.0.1, NOT localhost! See .env.example for explanation.
Security: Most secure - only accepts connections from localhost
Scenario B: Bridge Network (Better Isolation)
Best for: When you want container isolation or don't want to use --network host
Configuration (.env):
Security: Good - relies on password auth and firewall. Ensure MySQL is not exposed to internet!
Scenario C: Multi-Container Setup
Best for: MySQL running in another Docker container
Configuration (.env):
Quick Reference: Permission Grants
The minimum permissions needed for backups:
Quick Start (Docker - Recommended)
Complete setup in 5 minutes for localhost MySQL:
Done! Your backups will run daily at 2 AM. ✅
Installation
Via Composer (Recommended)
Manual Installation
Configuration
Option 1: Configuration File (Recommended)
Copy the example configuration file and customize it:
Edit db-backup.ini:
Note: The password field is optional if you're using socket-based authentication (e.g., auth_socket plugin in MariaDB).
Option 2: Environment Variables
You can also configure using environment variables:
Usage
Command Line
If installed via Composer:
If installed globally or from project directory:
Cron Job Setup
To run automated backups daily at 2 AM:
Add this line:
Or if using environment variables:
Docker Usage
For complete Docker deployment guide, see DOCKER.md
Quick Start with Docker
The run-backup.sh script automatically handles different network modes based on your .env configuration.
Manual Docker Run (if not using run-backup.sh)
Scenario A - Host Network:
Scenario B - Bridge Network:
Scenario C - Custom Network:
Using docker-compose
How It Works
- Connect to MySQL/MariaDB server
- List all databases (excluding system databases:
mysql,information_schema,performance_schema,sys) - Dump each database using
mysqldumpwith optimized flags - Compare the new backup hash with the previous backup
- Skip if identical (no changes detected)
- Compress with gzip if new data is present
- Store in organized directory structure:
<dumpdir>/<database>/<YYYYMMDDHHmm>.sql.gz
Backup Optimization
The tool uses SHA1 hash comparison to avoid storing duplicate backups when database content hasn't changed. This saves significant storage space for databases that don't change frequently.
The dump files are created without comments (via --skip-comments) to ensure hash comparison works correctly, as comments include timestamps that would always differ.
Directory Structure
Backup Retention
Important: This tool does NOT automatically delete old backups. Backups will accumulate over time.
Recommended: Add a Cleanup Cron Job
To prevent unlimited backup growth, add a retention policy:
Common retention periods:
- Development: 7-14 days
- Production: 30-90 days
- Compliance: May require longer (consult your requirements)
Future Enhancement: Built-in retention policies are planned for a future release.
Troubleshooting
Permission Issues
Ensure the backup directory is writable:
MySQL Connection Issues
Test your connection:
Missing Dependencies
Verify required executables are available:
License
GNU General Public License v3.0 or later (GPL-3.0-or-later)
Author
Ben Johnson ([email protected])
Copyright (c) 2012-2026, Ben Johnson
All versions of mysql-db-backup with dependencies
ext-mysqli Version *