A robust and flexible command-line utility for backing up MySQL, PostgreSQL, and MongoDB databases. Built with simplicity and power in mind, this tool offers a streamlined approach to database backups while providing advanced features for more complex requirements.
Support for multiple databases:
Advanced backup options:
- Automatic compression (.gz)
- Timestamped backups
- Generated file validation
- Detailed process information
- Clone the repository:
git clone https://github.com/geo-mena/backup.git
- Install the dependencies:
cd backup
- Initialize with Docker:
./init.sh
- Build the Docker image:
docker compose build --no-cache
- Start the Docker container:
docker compose up -d
- Access the container:
docker compose exec app sh
docker compose run --rm app php application backup \
--type=postgres \
--host=your-host \
--port=5432 \
--database=your-db \
--user=your-user \
--password=your-password \
--compress
docker compose run --rm app php application backup \
--type=mysql \
--host=your-host \
--port=3306 \
--database=your-db \
--user=root \
--password=your-password \
--compress
docker compose run --rm app php application backup \
--type=mongodb \
--host=your-host \
--port=27017 \
--database=your-db \
--user=your-user \
--password=your-password \
--compress
The utility includes a user-friendly Terminal User Interface (TUI) that makes it easier to configure and execute backups. To use the interactive mode:
docker compose run --rm app php application backup:tui
The TUI provides:
- Easy database type selection
- Interactive configuration menus
- Real-time validation
- Visual feedback
- Configuration preview
- Step-by-step guidance
-
Main Menu:
- Database type selection (MySQL, PostgreSQL, MongoDB)
- Visual ASCII art interface
- Color-coded options
-
Configuration Sections:
- Connection Settings
- Database Settings
- Output Settings
-
Real-time display of:
- Current configuration
- Validation status
- Process feedback
Option | Description | Default Value |
---|---|---|
--type |
Database type (mysql /postgres /mongodb ) |
mysql |
--host |
Database host | localhost |
--port |
Database port | [depends on type] |
--database |
Database name | required |
--user |
Database user | - |
--password |
Database password | - |
--output |
Output directory | app/storage/backups |
--compress |
Compress the backup | false |
Backups are stored in the storage/backups/ directory with the following format:
{database}_{type}_{date}.{extension}[.gz]
Example:
mydb_postgres_2024-12-31_18-30-00.sql.gz
The container includes:
- PHP 8.2
- PostgreSQL Client 16
- MySQL Client
- MongoDB Tools
- Compressed backups use gzip (.gz)
- Using environment variables for passwords is recommended in production
- Timestamps are in UTC format
If you encounter a permission error, run the following command:
chmod -R 755 storage
Verify that the host and port are accessible from the Docker container
backup-utility/
βββ app/
β βββ Commands/
β β βββ BackupCommand.php
β β βββ BackupTUICommand.php
β βββ Providers/
βββ config/
βββ docker/
β βββ php/
β βββ Dockerfile
βββ storage/
β βββ backups/
βββ tests/
βββ composer.json
βββ docker-compose.yml
app/Commands/BackupCommand.php
: Core backup functionality implementationapp/Commands/BackupTUICommand.php
: Interactive TUI implementationdocker/php/Dockerfile
: Docker container configurationdocker-compose.yml
: Docker services configurationcomposer.json
: PHP dependencies and project configurationconfig/backup.php
: Backup configuration settingsstorage/backups/
: Default backup storage directorytests/
: Test suite directory
app/
: Contains the main application codeconfig/
: Configuration filesdocker/
: Docker-related filesstorage/
: Storage for backups and logstests/
: Test files
The Database Backup Utility is an open-source software licensed under the MIT license.
Contributions are welcome! Please open an issue first to discuss any changes you'd like to make.