PHPackages                             jairocgr/datashot - 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. jairocgr/datashot

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

jairocgr/datashot
=================

A tool for taking partial database dumps and scripting datbases

3.0.5(2y ago)360MITPHPPHP &gt;=7.0CI failing

Since Dec 17Pushed 2y ago1 watchersCompare

[ Source](https://github.com/jairocgr/datashot)[ Packagist](https://packagist.org/packages/jairocgr/datashot)[ Docs](https://github.com/jairocgr/datashot)[ RSS](/packages/jairocgr-datashot/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (6)Versions (14)Used By (0)

Datashot Database Snapper
=========================

[](#datashot-database-snapper)

A tool for taking partial and minified database snapshots for testing and development purpose.

Instead of taking a full database dump, you can filter which rows you want to dump in order to come up with a downsized database snapshot.

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

[](#requirements)

To install and run **datashot** you must have:

- PHP &gt;= 5.6 with PDO extension
- `zlib` PHP extension for gzip compression
- MySQL client (`mysql` and `mysqldump` on path)
- Gzip on path
- [Composer](https://getcomposer.org/) dependency manager

Installing
----------

[](#installing)

Install it as a regular package via composer:

```
composer require jairocgr/datashot

```

Usage
-----

[](#usage)

You can call it as a command line tool:

```
php vendor/bin/datashot --help

```

Getting Started
---------------

[](#getting-started)

With `datashot` you can filter which rows you want to dump to come up with a much smaller database dump.

You can reduce ginormous multi-gigabyte databases in to a small gziped file ready to be restored in to staging and local develoment environments.

This kind of power come up handy for troubleshooting production bugs and all arround better development experience with real life data that best reflects your application usage than a mocked or seeded schema.

With `datashot` you can for instance take a database dump with only the orders from the current quarter.

You can also perform other operations like:

- Fully `replicate` databases from a host to another,
- `restore` existant dumps to a database hosts, and
- upload/download dumps from a SFTP or S3 repositories via `cp` command.

### Configuration

[](#configuration)

The first step is to setup the `datashot.config.php` file in the root of your application repository.

This is the configuration file where you set the database hosts, passwords and the *SQL* `WHERE` clauses in order to slice the database down.

> For a more complete and commented and configuration file see the sample `datashot.config.php` file inside this repository root directory

#### Database Hosts

[](#database-hosts)

You have to configure all your database in order to be able to work with it.

```
return [

  'database_servers' => [

    // A database server called 'live1'
    'live1' => [
      // Only mysql for now, maby postgres in the future
      'driver'   => 'mysql',

      // The env function will read from the environment or .env file
      'socket'   => env('MYSQL56_SOCKET', ''),
      'host'     => env('MYSQL56_HOST', 'localhost'),
      'port'     => env('MYSQL56_PORT', 3306),

      'user'     => env('MYSQL56_USER', 'root'),
      'password' => env('MYSQL56_PASSWORD', 'root'),

      // If you mark it as a 'production' server, a confirmation question
      // will be pronted in every execution and no drop action will
      // be performed for safety reasons
      'production' => TRUE
    ]
  ]
];
```

#### Repositories

[](#repositories)

You have to set the repositories where you will store the dumps.

```
return [

  'repositories' => [
    'local' => [
      'driver' => 'fs',
      'path' => __DIR__ . '/snaps' // Local snaps directory
    ],

    'remote' => [
      'driver'     => 's3',
      'bucket'     => env('S3_BUCKET'),
      'region'     => env('S3_REGION'),
      // 'profile'    => 'remote',
      'access_key' => env('S3_ACESS_KEY'),
      'secret_key' => env('S3_SECRET_ACESS_KEY'),
      'base_path'  => 'snaps' // Remote path will be like s3://bucket-name/snaps
    ],
  ],

];
```

#### Snappers

[](#snappers)

The snappers tell `datashot` how to slice down the database.

```
return [

  'snappers' => [
     'quick' => [

       // If you want to snap the rows only
       // 'data_only' => TRUE,

       // If you wanna dump only the ddl, triggers, functions, etc.
       // 'no_data' => TRUE,

       // Custom made user-defined property for later interpolation
       'cutoff' => '(NOW() - INTERVAL 3 MONTH)',

       // Table-specific where used to filter the rows witch will be dumped
       'wheres' => [

         // Interpolate the 'cutoff' parameter in the where clause for the
         // "logs" table
         'logs' => "created_at > '{cutoff}'",

         // Bring only the active users
         'users' => 'active = TRUE',
       ],

     ]
  ]

];
```

### Your First Snapshot

[](#your-first-snapshot)

To take a database snapshot using the previously configured file:

```
php vendor/bin/datashot snap myerp --from live1 --to remote:quick_snap --snapper quick

```

Then `datashot` will take a proper `mysqldump` from the scheme `myerp` that is running inside the production server `live1` and it will be using the `quick`snapper to cut the `logs` and `users` table down.

Then it will upload a file called `quick.gz` to the remote s3 repository called `remote` previously configured in the `datashot.config.php` configuration file.

Restoring Snapshots
-------------------

[](#restoring-snapshots)

You can use `datashot` to download and `restore` your snapshots:

```
php vendor/bin/datashot restore remote:quick --to dev --database myerp_dev

```

The command above will download the `quick` snapshot previously taken, restore the dump as `myerp_dev` schema at `dev` databaser server.

You can also restore the snapshot like a regular gziped *SQL* dump file:

```
gunzip < path/to/quick.gz | mysql -h localhost myerp

```

Hat Tipping
-----------

[](#hat-tipping)

I tip my hat to [ifsnop/mysqldump-php](https://github.com/ifsnop/mysqldump-php)for providing insights on how to dump a mysql database via PHP/PDO.

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

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

Recently: every ~260 days

Total

13

Last Release

1060d ago

Major Versions

0.1.3 → v1.x-dev2019-04-10

1.0.0 → 2.0.02019-12-10

2.0.0 → 3.0.02020-08-09

PHP version history (2 changes)0.1.0PHP &gt;=5.6

3.0.0PHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9d9264f8189ddae303c7c2b423c0ec46a506ad7666999cfa8aa3de2554a17055?d=identicon)[jairocgr](/maintainers/jairocgr)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jairocgr-datashot/health.svg)

```
[![Health](https://phpackages.com/badges/jairocgr-datashot/health.svg)](https://phpackages.com/packages/jairocgr-datashot)
```

###  Alternatives

[laravel/vapor-cli

The Laravel Vapor CLI

31310.7M8](/packages/laravel-vapor-cli)[magento/community-edition

Magento 2 (Open Source)

12.1k52.1k10](/packages/magento-community-edition)[kimai/kimai

Kimai - Time Tracking

4.6k7.4k1](/packages/kimai-kimai)[laravel-zero/framework

The Laravel Zero Framework.

3371.4M368](/packages/laravel-zero-framework)[rector/rector-src

Instant Upgrade and Automated Refactoring of any PHP code

134391.5k12](/packages/rector-rector-src)[guikingone/scheduler-bundle

A Symfony bundle that allows to schedule and create repetitive tasks

114217.4k](/packages/guikingone-scheduler-bundle)

PHPackages © 2026

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