PHPackages                             coderatio/simple-backup - 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. coderatio/simple-backup

ActiveLibrary

coderatio/simple-backup
=======================

A simple mysql database backup library for php.

v1.0.4(5y ago)566.3k↓100%13[1 PRs](https://github.com/coderatio/simple-backup/pulls)MITPHPPHP ^5.6|^7.0|^7.1|^7.2

Since Apr 2Pushed 1y agoCompare

[ Source](https://github.com/coderatio/simple-backup)[ Packagist](https://packagist.org/packages/coderatio/simple-backup)[ RSS](/packages/coderatio-simple-backup/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (7)Used By (0)

Simple-backup
=============

[](#simple-backup)

[![](/_docs/store_export.PNG)](/_docs/store_export.PNG)
A simple mysql database backup library for php. This library helps you backup your mysql database to a directory in your project or download it to your machine.

The library also allows you import or restore a database without stress. Follow the instructions below to get started.

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

[](#installation)

Open your terminal or command prompt and type the below command:

```
composer require coderatio/simple-backup
```

New in version 1.0.1
--------------------

[](#new-in-version-101)

1. You can now chain static `::start()` on `SimpleBackup class.
2. This version includes fluent chaining of database settings.
3. Added `->includeOnly(array $tables)` which allows you to export data for only tables mentioned in `$tables` variable.
4. Added `->excludeOnly(array $tables)` which removes the inclussion of tables mentioned in `$tables` variable during export.

#### (v1.0.1) Exporting specific tables only

[](#v101-exporting-specific-tables-only)

```
  SimpleBackup::start()
    ->setDbName('db_name')
    ->setDbUser('db_username')
    ->setDbPassword('db_password')
    ->includeOnly(['carts', 'houses', 'categories'])
    ->then()->storeAfterExportTo('backups')
    ->then()->getResponse();
```

#### (v1.0.1) Excluding specific tables only

[](#v101-excluding-specific-tables-only)

```
  SimpleBackup::start()
    ->setDbName('db_name')
    ->setDbUser('db_username')
    ->setDbPassword('db_password')
    ->excludeOnly(['users', 'posts'])
    ->then()->storeAfterExportTo('backups')
    ->then()->getResponse();
```

---

Exporting
---------

[](#exporting)

The export can be done in two ways.

1. Store in a directory
2. Download to your machine

#### 1-- Store in a directory

[](#1---store-in-a-directory)

To store the export in a directory, do this:

```
require 'vendor/autoload.php';

use Coderatio\SimpleBackup\SimpleBackup;

// Set the database to backup
$simpleBackup = SimpleBackup::setDatabase(['db_name', 'db_user', 'db_password', 'db_host'])
  ->storeAfterExportTo('pathtostore', 'file_name (optional)');
```

To get the stored file name, you can echo it out like this:

```
echo $simpleBackup->getExportedName();
```

You can also get the reponse by doing this:

```
/**
* @return object
**/
var_dump($simpleBackup->getResponse());
```

#### 2-- Download

[](#2---download)

To download the export to your machine, do this:

```
require 'vendor/autoload.php';

use Coderatio\SimpleBackup\SimpleBackup;

// Set the database to backup
$simpleBackup = SimpleBackup::setDatabase(['db_name', 'db_user', 'db_password', 'db_host'])
  ->downloadAfterExport($file_name (optional));
```

If $file\_name isn't provided, a random name will be generated for the download.

Adding where clauses to tables
------------------------------

[](#adding-where-clauses-to-tables)

To add where clauses as you would do on SQL, you can do this before exporting:

**Note:** `$tables` variable must be an associative array e.g

```
$tables = [
  'users' => 'is_active = true'
];
```

```
$simpleBackup->setTableConditions(array $tables);
```

Setting rows limit on tables
----------------------------

[](#setting-rows-limit-on-tables)

To limit how many rows to be included in your backup for a table, do this before exporting:

**Note:** Just like adding where clauses, the `$tables` variable here must be an associative array. e.g

```
$tables = [
  'users' => 50,
  'posts' => 50
]
```

```
$simpleBackup->setTableLimitsOn(array $tables);
```

Importing
---------

[](#importing)

This package makes importing or restoring your mysql database easy. To import your database, do this:

```
require 'vendor/autoload.php';

use Coderatio\SimpleBackup\SimpleBackup;

// Set the database to backup
$simpleBackup = SimpleBackup::setDatabase(['db_name', 'db_user', 'db_password', 'db_host (optional)']])
    ->importFrom('pathtosql_file or sql_contents');

/**
* You can then dump the response like this.
*
* @return object
**/
var_dump($simpleBackup->getResponse());
```

**Note:** You can provide sql statements as the parameter. You may also overwrite the database configuration by passing it as second parameter to the importFrom(). e.g `importFrom(pathtosql_file, array $db_config);`.

Todo
----

[](#todo)

1. Add a scheduler method to use with cron
2. Store backup in Dropbox, Google Drive.
3. Send backup to emails

Contribution
------------

[](#contribution)

To contribute to this project, send a pull request or find me on [Twitter](https://twitter.com/josiahoyahaya).

License
-------

[](#license)

This project is licenced with the MIT license.

###  Health Score

38

—

LowBetter than 84% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.6% 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 ~101 days

Total

5

Last Release

2189d ago

PHP version history (2 changes)v1.0.0PHP &gt;=5.6

v1.0.3PHP ^5.6|^7.0|^7.1|^7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/fea9ba733bfacc874e120052eba943294e7513b41597c2e51693b07e26942adc?d=identicon)[josiahoyahaya](/maintainers/josiahoyahaya)

---

Top Contributors

[![coderatio](https://avatars.githubusercontent.com/u/36877085?v=4)](https://github.com/coderatio "coderatio (29 commits)")[![atakanau](https://avatars.githubusercontent.com/u/2543993?v=4)](https://github.com/atakanau "atakanau (1 commits)")[![DarkVss](https://avatars.githubusercontent.com/u/13674664?v=4)](https://github.com/DarkVss "DarkVss (1 commits)")[![spyridonas](https://avatars.githubusercontent.com/u/4473825?v=4)](https://github.com/spyridonas "spyridonas (1 commits)")

---

Tags

backupmysql-databasetables-mentioned

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/coderatio-simple-backup/health.svg)

```
[![Health](https://phpackages.com/badges/coderatio-simple-backup/health.svg)](https://phpackages.com/packages/coderatio-simple-backup)
```

PHPackages © 2026

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