PHPackages                             scottjs/db-sync - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. scottjs/db-sync

ActiveLibrary[Database &amp; ORM](/categories/database)

scottjs/db-sync
===============

Helper scripts to quickly synchronise a local MySQL database with a remote database, as well as prepare a local database for deployment to a remote server.

1.0.5(10y ago)422.3k20[2 issues](https://github.com/scottjs/db-sync/issues)1MITShell

Since Apr 2Pushed 7y ago6 watchersCompare

[ Source](https://github.com/scottjs/db-sync)[ Packagist](https://packagist.org/packages/scottjs/db-sync)[ RSS](/packages/scottjs-db-sync/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (1)Versions (19)Used By (1)

DB Sync
=======

[](#db-sync)

When working on an active project, your local database may become too out of date from the database in staging or production and make local development difficult or unpredictable.

DB Sync provides scripts to quickly update a local MySQL development database with a remote staging or production database, as well as the ability to run safe search/replace on your local database in preparation for deploying to a remote server. It assumes that your remote database is externally accessable via an IP whitelist or similar.

*Disclaimer: These scripts and commands were originally created for use internally within our development team to speed up common, repetitive tasks. However, they may be of some use to others. Feel free to use in your own projects, your mileage may vary.*

Requirements
------------

[](#requirements)

- Composer
- PHP &gt;= 5.3.0
- A local development environment, such as Vagrant.

Notes
-----

[](#notes)

- These scripts require a .env config file in the project root. If you're using WordPress, you can use [scottjs/wp-dotenv](https://github.com/scottjs/wp-dotenv) to allow WordPress to share the same .env file and avoid maintaining two config files.
- This script was designed with WordPress in mind, however it should work with other projects, such as Laravel 5.

Installation
------------

[](#installation)

Run `composer require "scottjs/db-sync:1.*" --dev` from the root of your project.

Alternatively, you can manually add `"scottjs/db-sync": "1.*"` to your `composer.json` file:

```
"require-dev": {
	"scottjs/db-sync": "1.*"
}

```

Then add the following scripts to your `composer.json` file:

```
"scripts": {
	"database-update" : [
		"vendor/scottjs/db-sync/database-update.sh"
	],
	"database-prepare" : [
		"vendor/scottjs/db-sync/database-prepare.sh"
	],
	"database-import" : [
		"vendor/scottjs/db-sync/database-import.sh"
	],
	"database-export" : [
		"vendor/scottjs/db-sync/database-export.sh"
	]
}

```

Run the `composer update` command from the root of your project.

Create a `.env` file in the root of your project and add/update the following configuration options:

```
DOMAIN_REMOTE=www.example.com
DOMAIN_LOCAL=www.example.local

DB_HOST=localhost
DB_DATABASE=example
DB_USERNAME=root
DB_PASSWORD=password

REMOTE_DB_HOST=123.123.123.123
REMOTE_DB_DATABASE=example
REMOTE_DB_USERNAME=root
REMOTE_DB_PASSWORD=password

```

Usage
-----

[](#usage)

From the root of your project, you will be able to run the following composer commands:

- ***composer database-update*** - When working on an active project, your local database might become too out of date from the database in staging or production. This command will backup and empty your locally configured database and update it with a copy of your remote or production database. This requires all `DB_*` and `REMOTE_DB_*` options to be set in the .env file and also assumes your remote database is accessible externally.
- ***composer database-prepare*** - When developing locally, links to images and assets created within a CMS might be referencing your local development web address and won't work in staging or production. This command will run a safe search/replace script on your locally configured database, replacing all instances of `DOMAIN_LOCAL` with `DOMAIN_REMOTE` configured in the .env file. The database will then be exported to `dumps/prepared-database-YYYY.MM.DD-HH.MM.SS.sql` ready for deployment.
- ***composer database-import*** - If the file `setup/database.sql` exists in the project root, this command will import the file into your local database configured in the .env file. This is useful if you're working on a project and want another member of the team to get quickly set up with working copy of the database.
- ***composer database-export*** - This command will export a copy of your local database configured in the .env file and save it to `setup/database.sql`. If this file exists it will be overwritten. This is useful to quickly take a snapshot of your current development database to be shared with others.

Config
------

[](#config)

See below for an explanation of each configuration option used within the .env file.

- ***DOMAIN\_REMOTE*** - It should point to your remote or production environment (if available) and not include http:// or trailing slashes. Example: `www.example.com` or `subdomain.example.com`.
- ***DOMAIN\_LOCAL*** - It should not include http:// or trailing slashes. Example: `www.example.local` or `subdomain.example.local`.
- ***DB\_***\* - Provides options to set the local database connection details.
- ***REMOTE\_DB\_***\* - Provides options to set the remote staging or production database connection details.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

17

Last Release

3731d ago

Major Versions

0.5.2 → 1.0.02016-04-05

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/994732?v=4)[Scott Salisbury](/maintainers/scottjs)[@scottjs](https://github.com/scottjs)

---

Top Contributors

[![scottjs](https://avatars.githubusercontent.com/u/994732?v=4)](https://github.com/scottjs "scottjs (52 commits)")

### Embed Badge

![Health badge](/badges/scottjs-db-sync/health.svg)

```
[![Health](https://phpackages.com/badges/scottjs-db-sync/health.svg)](https://phpackages.com/packages/scottjs-db-sync)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k116.5M113](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
