2017 © Pedro Peláez
 

library database-backup

A framework-agnostic driver-based database backup package with a Laravel add-on.

image

mccool/database-backup

A framework-agnostic driver-based database backup package with a Laravel add-on.

  • Tuesday, June 16, 2015
  • by ShawnMcCool
  • Repository
  • 9 Watchers
  • 103 Stars
  • 18,157 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 10 Forks
  • 4 Open issues
  • 5 Versions
  • 1 % Grown

The README.md

This package is abandoned. This Backup Manager has fully replaced it., (*1)

Database Backup

A framework-agnostic database backup package., (*2)

Drivers: At this moment the package supports MySQL, gzip, and Amazon S3. However, it's modular and could be extended to support much more., (*3)

Frameworks: This package doesn't require a framework, but a Laravel service provider and Artisan command are made available for convenience., (*4)

Note: be aware that this package uses mysqldump for MySQL backups., (*5)

Example

Laravel users can run the following command if they'd like to backup the db, gzip it, upload it to s3, and remove the local backup file:, (*6)

php artisan db:backup --s3-bucket=whatever --s3-path=/this/is/optional/ --cleanup --gzip

Non-Laravel users can look at the Usage section below., (*7)

Requirements

  • 5.4 (would openly accept pull requests to lower to 5.3)

Installation

Laravel

  1. add to composer.json, (*8)

    "mccool/database-backup": "1.0.1"
    
  2. install dependency, (*9)

    composer update
    
  3. install configuration file, (*10)

    php artisan config:publish mccool/database-backup
    
  4. add service provider to config/app.php, (*11)

    'McCool\DatabaseBackup\ServiceProviders\LaravelServiceProvider',
    
  5. add key / secret to the config file in app/config/packages/mccool/database-backup/aws.php

Native PHP

  1. add to composer.json, (*12)

    "mccool/database-backup": "dev-master"
    
  2. install dependency, (*13)

    composer update
    
  3. make sure that your app requires the composer autoloader, (*14)

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

Usage

Laravel

Dump the database to app/storage/dumps/databasename_timestamp.sql, (*15)

php artisan db:backup

Store the database to backups/databasename_timestamp.sql, (*16)

php artisan db:backup --local-path=backups

Gzip the database., (*17)

php artisan db:backup --gzip

Choose a database to dump other than the default (names are configured in Laravel's config/database.php)., (*18)

php artisan db:backup --database=otherdatabaseconnection

Choose a specific filename other than the default (default is 'Y-m-d_H-i-s' ). Note, do not include the file extension .sql, we will do that for you, (*19)

php artisan db:backup --filename=my_project_backup

Upload the backup to S3, (*20)

php artisan db:backup --s3-bucket=whatever --s3-path=/this/is/optional/

Cleanup file when we're done, (*21)

php artisan db:backup --s3-bucket=whatever --s3-path=/this/is/optional/ --cleanup

Native PHP

<?php

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

// dump the database to backup/test.sql
$shellProcessor = new McCool\DatabaseBackup\Processors\ShellProcessor(new Symfony\Component\Process\Process(''));
$dumper = new McCool\DatabaseBackup\Dumpers\MysqlDumper($shellProcessor, 'localhost', 3306, 'username', 'password', 'test_db', 'backup/test.sql');

$backup = new McCool\DatabaseBackup\BackupProcedure($dumper);
$backup->backup();

// dump the database to backup/test.sql and gzip it
$shellProcessor = new McCool\DatabaseBackup\Processors\ShellProcessor(new Symfony\Component\Process\Process(''));
$dumper   = new McCool\DatabaseBackup\Dumpers\MysqlDumper($shellProcessor, 'localhost', 3306, 'username', 'password', 'test_db', 'backup/test.sql');
$archiver = new McCool\DatabaseBackup\Archivers\GzipArchiver($shellProcessor);

$backup = new McCool\DatabaseBackup\BackupProcedure($dumper);
$backup->setArchiver($archiver);

$backup->backup();

// dump the database to backup/test.sql, gzip it, upload it to S3, and clean up after ourselves
$shellProcessor = new McCool\DatabaseBackup\Processors\ShellProcessor(new Symfony\Component\Process\Process(''));
$dumper   = new McCool\DatabaseBackup\Dumpers\MysqlDumper($shellProcessor, 'localhost', 3306, 'username', 'password', 'test_db', 'backup/test.sql');
$archiver = new McCool\DatabaseBackup\Archivers\GzipArchiver($shellProcessor);
$storer   = new McCool\DatabaseBackup\Storers\S3Storer($awsKey, $awsSecret, 'us-east-1', $bucket, $s3Path);

$backup = new McCool\DatabaseBackup\BackupProcedure($dumper);
$backup->setArchiver($archiver);
$backup->setStorer($storer);

$backup->backup();
$backup->cleanup();

License

MIT, (*22)

The Versions

16/06 2015

dev-master

9999999-dev

A framework-agnostic driver-based database backup package with a Laravel add-on.

  Sources   Download

MIT

The Requires

 

The Development Requires

03/11 2014

1.0.2

1.0.2.0

A framework-agnostic driver-based database backup package with a Laravel add-on.

  Sources   Download

MIT

The Requires

 

The Development Requires

16/06 2014

1.0.1

1.0.1.0

A framework-agnostic driver-based database backup package with a Laravel add-on.

  Sources   Download

MIT

The Requires

 

The Development Requires

02/04 2014

2.0.x-dev

2.0.9999999.9999999-dev

A framework-agnostic driver-based database backup package with a Laravel add-on.

  Sources   Download

MIT

The Requires

 

The Development Requires

18/12 2013

1.0.0

1.0.0.0

A framework-agnostic driver-based database backup package with a Laravel add-on.

  Sources   Download

MIT

The Requires

 

The Development Requires