Skip to content

geo-mena/backup

Repository files navigation

Database Backup Utility

Docker Badge Laravel-zero Badge PHP Badge PostgreSQL Badge MySQL Badge MongoDB Badge

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.


πŸ“‘ Table of Contents

  1. ✨ Features

  2. πŸš€ Installation

  3. πŸ“‹ Requirements

  4. πŸ’» Usage

  5. πŸ–₯️ Interactive Mode

  6. πŸ”§ Available Options

  7. πŸ“ File Structure

  8. 🐳 Container Information

  9. πŸ“Œ Important Notes

  10. πŸ› Troubleshooting

  11. πŸ“‚ Project Structure

  12. πŸ“ License

  13. ✨ Contributing

✨ Features

Support for multiple databases:

Advanced backup options:

  • Automatic compression (.gz)
  • Timestamped backups
  • Generated file validation
  • Detailed process information

πŸš€ Installation

  1. Clone the repository:
git clone https://github.com/geo-mena/backup.git
  1. Install the dependencies:
cd backup
  1. Initialize with Docker:
./init.sh
  1. Build the Docker image:
docker compose build --no-cache
  1. Start the Docker container:
docker compose up -d
  1. Access the container:
docker compose exec app sh

πŸ“‹ Requirements

πŸ’» Usage

PostgreSQL

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

MySQL

docker compose run --rm app php application backup \
    --type=mysql \
    --host=your-host \
    --port=3306 \
    --database=your-db \
    --user=root \
    --password=your-password \
    --compress

MongoDB

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

πŸ–₯️ Interactive Mode

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

TUI Features

  • 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

πŸ”§ Available Options

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

πŸ“ File Structure

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

🐳 Container Information

The container includes:

  • PHP 8.2
  • PostgreSQL Client 16
  • MySQL Client
  • MongoDB Tools

πŸ“Œ Important Notes

  • Compressed backups use gzip (.gz)
  • Using environment variables for passwords is recommended in production
  • Timestamps are in UTC format

πŸ› Troubleshooting

Permission Error

If you encounter a permission error, run the following command:

chmod -R 755 storage

Connection Error

Verify that the host and port are accessible from the Docker container

πŸ“‚ Project Structure

Directory Layout

backup-utility/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ Commands/
β”‚   β”‚   β”œβ”€β”€ BackupCommand.php
β”‚   β”‚   └── BackupTUICommand.php
β”‚   └── Providers/
β”œβ”€β”€ config/
β”œβ”€β”€ docker/
β”‚   └── php/
β”‚       └── Dockerfile
β”œβ”€β”€ storage/
β”‚   └── backups/
β”œβ”€β”€ tests/
β”œβ”€β”€ composer.json
└── docker-compose.yml

Key Files

  • app/Commands/BackupCommand.php: Core backup functionality implementation
  • app/Commands/BackupTUICommand.php: Interactive TUI implementation
  • docker/php/Dockerfile: Docker container configuration
  • docker-compose.yml: Docker services configuration
  • composer.json: PHP dependencies and project configuration
  • config/backup.php: Backup configuration settings
  • storage/backups/: Default backup storage directory
  • tests/: Test suite directory

Key Directories

  • app/: Contains the main application code
  • config/: Configuration files
  • docker/: Docker-related files
  • storage/: Storage for backups and logs
  • tests/: Test files

πŸ“ License

The Database Backup Utility is an open-source software licensed under the MIT license.

✨ Contributing

Contributions are welcome! Please open an issue first to discuss any changes you'd like to make.

About

πŸ“¦ Database backup utility that can backup and restore any DB

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published