josmiguel92 / phpBackupMySQL

Backup a MySQL database only with PHP (without mysqldump)

Home Page:http://proinf.net/permalink/backup_a_mysql_database_only_with_php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

php BackupMySQL

Backup a MySQL database only with PHP (without mysqldump)

Examples

Example 1

Download a SQL backup file

require_once "BackupMySQL.php";
$backup = new BackupMySQL([
	'host'=> "localhost",
	'database'=> "acme",
	'user'=> "root",
	'password'=> "",
]);
$backup->download();

Example 2

Download a ZIP backup file

require_once "BackupMySQL.php";
$connection = [
	'host'=> "localhost",
	'database'=> "acme",
	'user'=> "root",
	'password'=> "",
];
$tables = [
	"wp_*",
	"mytable1",
];
$show = [
	'TABLES',
	'DATA'
];
$backup = new BackupMySQL($connection, $tables, $show);
$backup->zip();
$backup->download();

Example 3

Stores a SQL backup file to a writable folder

require_once "BackupMySQL.php";
$setup = [
	'connection'=> [
		'host'=> "localhost",
		'database'=> "acme",
		'user'=> "root",
		'password'=> "",
	],
	'tables'=> "wp_*,mytable1",
	'show'=> "TABLES,DATA",
	'folder'=> "../backups",
];
$backup = new BackupMySQL();
$backup->setConnection ($setup['connection']);
$backup->setTables ($setup['tables']);
$backup->setShow ($setup['show'])
$backup->setFolder ($setup['folder']);
$backup->run();

Example 4

Download zip of all tables except table1 and table2

require_once "BackupMySQL.php";
$backup = new BackupMySQL();
$backup->setConnection(array('database'=>"acme", 'user'=>"root", 'password'=>""));
$backup->setName("ACME_BACKUP");
$backup->setFolder("backups");
$backup->setTables(array("*", "table1", "table2"));
$backup->setShow(array("VIEWS", "PROGRAMS", "TRIGGERS", "DATA"));
$backup->run();
$backup->zip();
$backup->download();

Changes

TODO:

  • Avoid timeout with database too large

DONE:

  • Extract the FOREIGN KEY of CREATE TABLE sentence.
  • Compress SQL file to ZIP file (without shell)
  • Method to download the SQL or ZIP file (using header)
  • Detect a temporary writable folder to store SQL & ZIP files
  • Delete file after download
  • Publish in GitHub

About

Backup a MySQL database only with PHP (without mysqldump)

http://proinf.net/permalink/backup_a_mysql_database_only_with_php

License:GNU General Public License v3.0


Languages

Language:PHP 100.0%