PHP code example of mccool / database-backup

1. Go to this page and download the library: Download mccool/database-backup library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mccool / database-backup example snippets


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

    'McCool\DatabaseBackup\ServiceProviders\LaravelServiceProvider',
    

     



mp 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();
SHELL
    php artisan config:publish mccool/database-backup
    
app/config/packages/mccool/database-backup/aws.php
SHELL
php artisan db:backup
SHELL
php artisan db:backup --local-path=backups
SHELL
php artisan db:backup --gzip
SHELL
php artisan db:backup --database=otherdatabaseconnection
SHELL
php artisan db:backup --filename=my_project_backup
SHELL
php artisan db:backup --s3-bucket=whatever --s3-path=/this/is/optional/
SHELL
php artisan db:backup --s3-bucket=whatever --s3-path=/this/is/optional/ --cleanup