Download the PHP package amitdugar/db-tools without Composer
On this page you can find all versions of the php package amitdugar/db-tools. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download amitdugar/db-tools
More information about amitdugar/db-tools
Files in amitdugar/db-tools
Package db-tools
Short Description Database backup/restore/export/verify/pitr/collation console toolkit
License MIT
Homepage https://github.com/amitdugar/db-tools
Informations about the package db-tools
db-tools
MySQL/MariaDB backup, restore, and recovery toolkit.
Installation
Quick Start
Setup
If your project already has a .env file (Laravel, Symfony, etc.)
You're done! db-tools automatically reads DB_* variables from your .env file.
If your .env doesn't have database variables yet, run setup:
This will prompt for credentials and add them to your .env file.
If you're starting fresh
Choose where to save config:
.envfile (recommended) - addsDB_HOST,DB_DATABASE, etc.- Profile file - saves to
~/.config/db-tools/profiles.php
Verify your setup
Commands
Backup & Restore
Backup Management
Database Maintenance
Point-in-Time Recovery
Configuration
Profiles (Multiple Databases)
If you manage multiple databases, use profiles. Each profile is a named database configuration that you can switch between.
When to use profiles
- You have separate databases (e.g., main app + analytics)
- You need different backup settings per database
- You want to manage multiple projects from one machine
Quick setup with profiles
Using profiles
How profiles are stored
In .env file (default) - profiles use prefixed variable names:
In db-tools.php - profiles are array keys:
Cron Jobs
db-tools is designed for cron. Just cd to your project and run:
No environment setup needed in cron - db-tools reads directly from your project's .env file.
Non-Interactive Setup
For deploy scripts and CI/CD pipelines, use --no-prompt mode:
| Option | Default | Description |
|---|---|---|
--no-prompt |
Run without prompts (required) | |
-o, --output |
env |
Output format: env, config, or profile |
-p, --profile |
default |
Profile name for multiple databases |
--database |
Database name (required) | |
--host |
localhost |
Database host |
--port |
3306 |
Database port |
--user |
root |
Database user |
--password |
Database password | |
--output-dir |
./backups |
Backup directory |
--retention |
7 |
Retention count |
Config Files
Most projects don't need a config file - db-tools reads your .env automatically. Use config files when you need:
- Multiple databases or profiles
- Custom
output_dir,retention, or other options - Non-standard environment variable names
db-tools.php (commit to repo)
db-tools.local.php (gitignore, local overrides)
Configuration Reference
Auto-detected environment variables
db-tools automatically reads these from your .env file:
Config file locations (first found wins)
DBTOOLS_CONFIGenv vardb-tools.local.php(project root)db-tools.php(project root)~/.config/db-tools/profiles.php
Profile options
| Option | Type | Description |
|---|---|---|
host |
string | Database host (default: localhost) |
port |
int | Database port (default: 3306) |
database |
string | Database name |
user |
string | Database user |
password |
string | Database password |
output_dir |
string | Backup directory |
retention |
int | Keep last N backups |
compression |
string | zstd, pigz, gzip, or zip |
encryption_password |
string | Encrypt backups (AES-256) |
label |
string | Filename prefix |
Command-line overrides
Any option can be overridden via CLI or environment:
Encrypted Backups
All compression backends support encryption using GPG with AES-256. There are two ways to encrypt:
Auto-generated password (recommended)
Use --encrypt to automatically generate a secure password. The password is derived from your database password plus a random string embedded in the filename:
How it works: The encryption password is DB_PASSWORD + randomString. Since the random string is embedded in the filename, restore automatically derives the correct password when you provide your database credentials.
Manual password
Use --encryption-password to specify your own password:
Store the password securely (e.g., in environment variable):
How encryption works
- ZIP (
--compression=zip): Native ZIP encryption (AES-256) - Other backends (zstd, gzip, pigz): File is compressed, then encrypted with GPG symmetric AES-256 →
.sql.zst.gpg
Collation Conversion
The collation command converts database tables and columns to utf8mb4 with automatic MySQL version detection:
- MySQL 8+: Uses
utf8mb4_0900_ai_ci - MySQL 5.x/MariaDB: Uses
utf8mb4_unicode_ci
The command preserves all column attributes: NULL/NOT NULL, DEFAULT values, AUTO_INCREMENT, COMMENT, etc.
Import Formats
The import command handles various file formats:
| Extension | Description |
|---|---|
.sql |
Plain SQL file |
.sql.gz |
Gzip compressed |
.sql.zst |
Zstandard compressed |
.zip |
ZIP archive (with optional password) |
.sql.gpg |
GPG encrypted |
.sql.zst.gpg |
Compressed + encrypted |
Requirements
- PHP 8.2+
mysqldump,mysqlCLI tools- Compression:
zstd(preferred),pigz, orgzip - Encryption:
gpg(for non-ZIP encrypted backups)
License
MIT
All versions of db-tools with dependencies
symfony/console Version ^8.1
symfony/process Version ^8.1
psr/log Version ^3.0
amitdugar/archiveutil Version ^2.0