Project to make database backups based on MySQL. Inspired and based on mysqldump-php.
Call method create
. This method required a instance of Connection
. This class is a DTO with database required info (dsn, username and password):
new Connection(
'mysql:host=mysserver.com;dbname=myuser', 'myuser', 'password'
),
Complete example:
require_once './vendor/autoload.php';
use MyBackup\Backup;
use MyBackup\Connection;
Backup::create(
new Connection(
'mysql:host=myserver.com;dbname=mydb', 'myuser', 'password'
),
dirname(__FILE__) . '/storage/dump.sql'
);
Mapping with tableName and SQL condition.
$tableConditions = array(
'users' => 'date_registered > NOW() - INTERVAL 3 MONTH AND deleted=0',
'logs' => 'date_logged > NOW() - INTERVAL 1 DAY',
'posts' => 'isLive=1'
);
createWithConditions($connection, $storagePath, $tableConditions);
Mapping with tableName and row date limit.
$tableLimits = array(
'users' => 300,
'logs' => 50,
'posts' => 10
);
createWithRateLimits(Connection $connection, $storagePath, $tableLimits);
Create with table conditions and row date limits
createComplete(Connection $connection, $storagePath, $tableConditions, $tableLimits);
- Define afeter backup create:
Backup::log(
function($table) {
print_r(
"Tabla " . $table->name() . " con un total de " . $table->rows() . " filas. \n"
);
}
);