2017 © Pedro Peláez
 

library danpu

Zero-dependency MySQL dump library for easily exporting and importing databases

image

rah/danpu

Zero-dependency MySQL dump library for easily exporting and importing databases

  • Monday, April 28, 2014
  • by rah
  • Repository
  • 5 Watchers
  • 39 Stars
  • 14,347 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 9 Forks
  • 18 Open issues
  • 24 Versions
  • 11 % Grown

The README.md

Danpu - MySQL dump tool for PHP

Build Status Coverage Status Packagist, (*1)

Danpu is a dependency-free, cross-platform, portable PHP library for backing up MySQL databases. It has no hard dependencies, and is fit for restricted environments where security is key and access is limited. Danpu requires nothing more than access to your database, PDO and a directory it can write the backup to. The script is optimized and has low memory-footprint, allowing it to handle even larger databases., (*2)

Danpu supports backing up table structures, the data itself, views and triggers. Created dump files can optionally be compressed to save space, and generated SQL output is optimized for compatibility., (*3)

Requirements

Minimum:, (*4)

  • PHP 5.3.0 or newer
  • MySQL 4.1.0 or newer
  • PDO

Recommended, but optional:, (*5)

  • PHP 5.4.0 or newer
  • MySQL 5.0.11 or newer
  • zlib

Backing up views and triggers requires MySQL 5.0.11 or newer., (*6)

Install

Using Composer:, (*7)

$ composer require rah/danpu

Usage

To create a new backup or import one, configure a new Dump instance and pass it to one of the worker classes. To begin, first make sure you have included Composer's autoloader file in your project:, (*8)

require './vendor/autoload.php';

If you are already using other Composer packages, or a modern Composer-managed framework, this should be taken care of already. If not, merely add the autoloader to your base bootstrap includes. See Composer's documentation for more information., (*9)

Take a backup

Backups can be created with the Export class. The class exports the database to a SQL file, or throws exceptions on errors. The file is compressed if the target filename ends to a .gz extension., (*10)

use Rah\Danpu\Dump;
use Rah\Danpu\Export;

try {
    $dump = new Dump;
    $dump
        ->file('/path/to/target/dump/file.sql')
        ->dsn('mysql:dbname=database;host=localhost')
        ->user('username')
        ->pass('password')
        ->tmp('/tmp');

    new Export($dump);
} catch (\Exception $e) {
    echo 'Export failed with message: ' . $e->getMessage();
}

The database is dumped in chunks, one row at the time without buffering huge amount of data to the memory. This makes the script very memory efficient, and can allow Danpu to handle databases of any size, given the system limitations of course. You physically won't be able backup rows that take more memory than can be allocated to PHP, nor write backups if there isn't enough space for the files., (*11)

Import a backup

Danpu can also import its own backups using the Import class. While the importer works with backups it has made, it doesn't accept freely formatted SQL. The importer is pretty strict about formatting, and expects exactly the same format as generated by Danpu. It expects that values in statements are escaped properly, including newlines, queries have to end to a semicolon and statements preferably should not wrap to multiple lines., (*12)

To import a backup, create a new instance of the Import class. It uncompresses any .gz files before importing., (*13)

use Rah\Danpu\Dump;
use Rah\Danpu\Import;

try {
    $dump = new Dump;
    $dump
        ->file('/path/to/imported/file.sql')
        ->dsn('mysql:dbname=database;host=localhost')
        ->user('username')
        ->pass('password')
        ->tmp('/tmp');

    new Import($dump);
} catch (\Exception $e) {
    echo 'Import failed with message: ' . $e->getMessage();
}

Options

In addition to the mandatory connection and file location, Danpu accepts various optional configuration options. These include filtering tables and views by prefix, ignoring tables and creating dumps without row data. See the src/Rah/Danpu/Config.php for full list of options. The source file contains detailed documentation blocks, outlining each option., (*14)

Troubleshooting

Running out of memory, backup taking too long

As with any PHP script, Danpu is restricted by the safe limits you have set for PHP. When dealing with larger databases, taking a backup will take longer and require more memory. If you find yourself hitting the maximum execution time or running out of memory, its time to increase the limits enough to let the script to work., (*15)

PHP lets you to change these limits with its configuration options, which can be modified temporarily during script execution, or in global configuration files. The configuration options you will be the most interested in, are memory_limit and max_execution_time, and possibly ignore_user_abort. You can change these values in your script before running a backup with Danpu:, (*16)

ini_set('memory_limit', '256M');
set_time_limit(0);
ignore_user_abort(true);

This of course requires that you have access to these values and you actually have more memory to give. Keep in mind that PHP may be affected by other limitations, such as your web server., (*17)

The Versions

28/04 2014

dev-master

9999999-dev https://github.com/gocom/danpu

Zero-dependency MySQL dump library for easily exporting and importing databases

  Sources   Download

MIT

The Requires

  • ext-pdo *
  • php >=5.3.0

 

The Development Requires

database sql library export mysql db backup dump import mysqldump restore

22/12 2013

2.6.2

2.6.2.0 https://github.com/gocom/danpu

Zero-dependency MySQL dump library for easily exporting and importing databases

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-pdo *

 

The Development Requires

database sql library export mysql db backup dump import mysqldump restore

18/12 2013

2.6.1

2.6.1.0 https://github.com/gocom/danpu

Zero-dependency MySQL dump library for easily exporting and importing databases

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-pdo *

 

The Development Requires

database sql library export mysql db backup dump import mysqldump restore

16/12 2013

2.6.0

2.6.0.0 https://github.com/gocom/danpu

Zero-dependency MySQL dump library for easily exporting and importing databases

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-pdo *

 

The Development Requires

database sql library export mysql db backup dump import mysqldump restore

22/05 2013

2.5.0

2.5.0.0 https://github.com/gocom/danpu

MySQL database dump and restoration tool implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-pdo *

 

The Development Requires

sql export mysql backup dump import restore

22/05 2013

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/gocom/danpu

MySQL database dump tool implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.2.0
  • ext-pdo *

 

The Development Requires

sql export mysql backup dump import mysqldump

22/05 2013

1.5.0

1.5.0.0 https://github.com/gocom/danpu

MySQL database dump tool implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.2.0
  • ext-pdo *

 

The Development Requires

sql export mysql backup dump import mysqldump

16/05 2013

2.4.0

2.4.0.0 https://github.com/gocom/danpu

MySQL database dump and restoration tool implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-pdo *

 

The Development Requires

sql export mysql backup dump import restore

16/05 2013

1.4.0

1.4.0.0 https://github.com/gocom/danpu

MySQL database dump tool implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.2.0
  • ext-pdo *

 

The Development Requires

sql export mysql backup dump import mysqldump

15/05 2013

2.3.3

2.3.3.0 https://github.com/gocom/danpu

MySQL database dump and restoration tool implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-pdo *

 

The Development Requires

sql export mysql backup dump import restore

15/05 2013

1.3.3

1.3.3.0 https://github.com/gocom/danpu

MySQL database dump tool implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.2.0
  • ext-pdo *

 

The Development Requires

sql export mysql backup dump import mysqldump

14/05 2013

2.3.2

2.3.2.0 https://github.com/gocom/danpu

MySQL database dump and restoration tool implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-pdo *
  • ext-zlib *

 

The Development Requires

sql export mysql backup dump import restore

14/05 2013

1.3.2

1.3.2.0 https://github.com/gocom/danpu

MySQL database dump tool implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.2.0
  • ext-pdo *
  • ext-zlib *

 

The Development Requires

sql export mysql backup dump import mysqldump

14/05 2013

2.3.1

2.3.1.0 https://github.com/gocom/danpu

MySQL database dump and restoration tool implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-pdo *
  • ext-zlib *

 

The Development Requires

sql export mysql backup dump import restore

13/05 2013

1.3.1

1.3.1.0 https://github.com/gocom/danpu

MySQL database dump tool implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.2.0
  • ext-pdo *
  • ext-zlib *

 

The Development Requires

sql export mysql backup dump import mysqldump

13/05 2013

2.3.0

2.3.0.0 https://github.com/gocom/danpu

MySQL database dump and restoration tool implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-pdo *
  • ext-zlib *

 

The Development Requires

sql export mysql backup dump import restore

13/05 2013

1.3.0

1.3.0.0 https://github.com/gocom/danpu

MySQL database dump tool implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.2.0
  • ext-pdo *
  • ext-zlib *

 

The Development Requires

sql export mysql backup dump import mysqldump

13/05 2013

2.2.0

2.2.0.0 https://github.com/gocom/danpu

MySQL database dump and restoration tool implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-pdo *
  • ext-zlib *

 

sql export mysql backup dump import restore

13/05 2013

1.2.0

1.2.0.0 https://github.com/gocom/danpu

MySQL database dump tool implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.2.0
  • ext-pdo *
  • ext-zlib *

 

sql export mysql backup dump import mysqldump

13/05 2013

2.1.1

2.1.1.0 https://github.com/gocom/danpu

MySQL database dump and restoration tool implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-pdo *
  • ext-zlib *

 

sql export mysql backup dump import restore

13/05 2013

2.1.0

2.1.0.0 https://github.com/gocom/danpu

MySQL database dump and restoration tool implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-pdo *
  • ext-zlib *

 

sql export mysql backup dump import restore

13/05 2013

1.1.0

1.1.0.0 https://github.com/gocom/danpu

MySQL database dump tool implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.2.0
  • ext-pdo *
  • ext-zlib *

 

sql export mysql backup dump import mysqldump

12/05 2013

2.0.1

2.0.1.0 https://github.com/gocom/danpu

MySQL database dump and restoration tool implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-pdo *
  • ext-zlib *

 

sql export mysql backup dump import restore

11/05 2013

1.0.0

1.0.0.0 https://github.com/gocom/danpu

MySQL database dump tool implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=5.2.0
  • ext-pdo *
  • ext-zlib *

 

sql export mysql backup dump import mysqldump