PHPackages                             inigopascall/clone-db - 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. inigopascall/clone-db

ActiveLaravel-package[Database &amp; ORM](/categories/database)

inigopascall/clone-db
=====================

Package for cloning medium-size databases by ordering tables by foreign-key dependencies and running batch inserts

1.0.1(1y ago)086↓70%PHP

Since Nov 1Pushed 1y ago1 watchersCompare

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

READMEChangelog (2)DependenciesVersions (3)Used By (0)

A Laravel package for cloning medium-size databases
===================================================

[](#a-laravel-package-for-cloning-medium-size-databases)

This package was created as a solution to the problem of cloning medium/large databases between connections, for example pulling in a live database (or a subet of one) to staging or development environments where there is a need to play with real data. Large sql dump files are often too big to import in one go and can hit issues with memory limits (packet size), especially on micro servers. While [this is an old problem](https://stackoverflow.com/questions/13717277/how-can-i-import-a-large-14-gb-mysql-dump-file-into-a-new-mysql-database), there are still surprisingly few straightforward ways to go about it. This package is an attempt at an out-of-the-box solution in the form of a Laravel package which provides a new artisan command for cloning one database to another.

- Attempts to preserve data integrity and avoid foreign-key constraint errors by automatically ordering tables by foreign key dependencies, creating the 'master' tables first, and dependent tables sequentially afterwards, ignoring new rows added to the latter tables since the script was initiated. (Note that mutually-dependent data sets are not supported).
- Avoids php/mysql memory limits by 'chunking' data, i.e. selecting &amp; inserting in configurable batch sizes.

Obviously, running this script is destructive. Please ensure backups of all relevant databases have been taken before starting.

Instructions
============

[](#instructions)

`composer require inigopascall/clone-db`

`php artisan vendor:publish --provider="InigoPascall\CloneDB\Providers\CloneDBProvider"`

### 1. Configure the config file as needed

[](#1-configure-the-config-file-as-needed)

**app/config/clone-db.php**

Sensible defaults have been pre-set, with examples given in the comments in this file of how to fine-tune things to suit your needs.

### 2. Make sure the source &amp; target databases are configured correctly in your app's config

[](#2-make-sure-the-source--target-databases-are-configured-correctly-in-your-apps-config)

**app/config/database.php**

```
'my_source_db_connection' => [
	'driver' => 'mysql',
	'host' => env('SOURCE_DB_HOST', '127.0.0.1'),
	'port' => env('SOURCE_DB_PORT', '3306'),
	'database' => env('SOURCE_DB_DATABASE', 'forge'),
	'username' => env('SOURCE_DB_USERNAME', 'forge'),
	'password' => env('SOURCE_DB_PASSWORD', '')
],
'my_target_db_connection' => [
	'driver' => 'mysql',
	'host' => env('TARGET_DB_HOST', '127.0.0.1'),
	'port' => env('TARGET_DB_PORT', '3306'),
	'database' => env('TARGET_DB_DATABASE', 'forge'),
	'username' => env('TARGET_DB_USERNAME', 'forge'),
	'password' => env('TARGET_DB_PASSWORD', '')
]

```

**.env**

```
SOURCE_DB_HOST=localhost
SOURCE_DB_PORT=3306
SOURCE_DB_DATABASE=source_database_name
SOURCE_DB_USERNAME=mysqlusername
SOURCE_DB_PASSWORD=mysluserpass

TARGET_DB_HOST=localhost
TARGET_DB_PORT=3306
TARGET_DB_DATABASE=target_database_name
TARGET_DB_USERNAME=mysqlusername
TARGET_DB_PASSWORD=mysqluserpass

```

3. run the command with the source &amp; target connection names as parameters. Check &amp; confirm output.
===========================================================================================================

[](#3-run-the-command-with-the-source--target-connection-names-as-parameters-check--confirm-output)

`php artisan clone:db my_source_db_connection my_target_db_connection`

Cloning a remote database via SSH
---------------------------------

[](#cloning-a-remote-database-via-ssh)

SSH config for your server pointing to the private key location

**~/.ssh/config**

```
Host remoteservername
Hostname {server ip address}
User username
IdentityFile ~/.ssh/remoteservernameprivatekey

```

Open SSH connection with `ssh remoteservername -N -L 13306:localhost:3306 username@{server ip address}`

`app/config/database.php` entry for the connection would then be set with localhost and the local port number specified in the above command (13306):

```
'my_source_db_connection' => [
    'driver' => 'mysql',
    'host' => env('SOURCE_DB_HOST', '127.0.0.1'),
    'port' => env('SOURCE_DB_PORT', '13306'),
    'database' => env('SOURCE_DB_DATABASE', 'remotedb'),
    'username' => env('SOURCE_DB_USERNAME', 'remotedbuser'),
    'password' => env('SOURCE_DB_PASSWORD', 'remotedbpass')
]

```

###  Health Score

26

—

LowBetter than 40% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 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 ~344 days

Total

2

Last Release

676d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8db9fa343831fbb55e5cf8c477fe978157731abfe5397ca46f8c9996ae31c27a?d=identicon)[Inigo Pascall](/maintainers/Inigo%20Pascall)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/inigopascall-clone-db/health.svg)

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.8k117.8M121](/packages/jdorn-sql-formatter)[backup-manager/backup-manager

A framework agnostic database backup manager with user-definable procedures and support for S3, Dropbox, FTP, SFTP, and more with drivers for popular frameworks.

1.7k1.6M11](/packages/backup-manager-backup-manager)[propel/propel1

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

8351.6M88](/packages/propel-propel1)[insolita/yii2-migration-generator

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

108508.0k5](/packages/insolita-yii2-migration-generator)[xpdo/xpdo

A PDO-based Object/Relational Bridge Library

7088.4k4](/packages/xpdo-xpdo)[voku/session2db

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

2920.0k](/packages/voku-session2db)

PHPackages © 2026

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