A PHP script to automate the process of exporting a database from a remote server and downloading it locally. It supports multiple projects and environments, allowing you to easily switch between them using CLI arguments or an interactive prompt.
Important
REQUIREMENTS
- PHP: ^8.1
- Dependencies:
-
phpseclib/phpseclib
^3.0
ASSUMPTIONS
- This script assumes that
pg_dump
is being used on the server.
- Clone the repository:
git clone git@github.com:PG-Momik/DB-Dumper.git
cd db-dumper
- Install dependencies:
composer install
- Define environment configurations in
env.json
. (Useenv.example.json
as a reference). env.json
will be validated againstschema.json
automatically when executing the script.
You can specify the project and environment directly via CLI flags.
php index.php -p "My project name" -e "develop"
Run the script without arguments to use the interactive mode. You'll be prompted to select a project and environment.
php index.php
- Validation: Validates env.json against schema.json using EnvValidator.
- Argument Extraction: Extracts CLI arguments (-p for project, -e for environment) or enters interactive mode.
- Database Dump: Initiates the database dump on the specified server using DatabaseDumper class.
- Completion: Downloads the dump file locally and provides details.
db-dumper/
│
├── classes/
│ ├── DatabaseDumper.php # Handles the database dump process
│ ├── EnvValidator.php # Validates env.json against schema.json
│
├── index.php # Main script
├── composer.json # Composer configuration
├── env.json # User-defined configuration file
├── env.example.json # env.json example
├── schema.json # Defines structure of env.json
└── README.md # Documentation