Skip to content

Introduction

php-sync-tool is a PHP CLI tool for synchronizing MySQL, MariaDB or PostgreSQL databases — and optionally files — between systems over SSH. It automatically extracts database credentials from popular PHP frameworks and supports a range of sync modes for different use cases.

It is a PHP port of the Python db-sync-tool, designed to run wherever PHP already runs, without an additional Python runtime.

Features

  • Database sync from and to remote systems
  • Proxy mode between two remote systems (two-hop transfer)
  • Nine synchronization modes selected automatically from your config
  • Automatic database credential detection for supported frameworks:
  • File synchronization alongside or instead of the database
  • Dump creation (database backup) with optional retention/cleanup
  • Lifecycle scripts (before / after / error) and post-import SQL
  • Structured logging (plain or JSON) for CI and log aggregation
  • Many more configuration options

Requirements

  • PHP 8.2 or higher (~8.2 || ~8.3 || ~8.4 || ~8.5)
  • mysql / mysqldump (or psql / pg_dump for PostgreSQL) and gzip / gunzip on the executing host(s)
  • rsync for the default transfer method (SFTP is used automatically as a fallback)
  • Optionally sshpass for password-based rsync
  • SSH access to remote systems (for remote syncs)

How It Works

  1. Resolve configuration — origin and target are read from a config file, host definitions, or CLI arguments.
  2. Detect credentials — for a supported framework, database credentials are parsed from its config file (locally or over SSH).
  3. Export — a gzip-compressed mysqldump (or pg_dump for PostgreSQL) is created on the origin system.
  4. Transfer — the dump is moved via rsync (or SFTP fallback, or a local proxy).
  5. Import — the dump is imported on the target system.
  6. Finalize — post-import SQL runs, lifecycle scripts fire, and temporary files and credential files are cleaned up.

Next Steps

Released under the GPL-3.0-or-later License.