PHP Classes
elePHPant
Icontem

MySQL DB Backup: Generate backup files of large MySQL databases

Recommend this page to a friend!
  Info   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2010-11-15 (5 years ago) RSS 2.0 feedStarStarStar 56%Total: 1,627 All time: 2,334 This week: 1,099Up
Version License PHP version Categories
mysql_db_backup 1.1.0GNU General Publi...5.0.0Databases, Systems administration
Description Author

The class can be used to create backup files of MySQL databases in the form of lists of SQL statements that can be executed to restore the database.

This is a new version of a class originally written by Vagharshak Tozalakyan to use much less memory.

It can store the backup data in compressed or uncompressed files directly, instead of concatenating the whole data in a text string, thus avoiding to use too much memory when taking backups of large databases.

It can also return the backup data as a single uncompressed string, but this way it may exceed the PHP memory limit.

Picture of Luis Arturo Aguilar Mendoza
Name: Luis Arturo Aguilar ... <contact>
Classes: 1 package by
Country: Mexico Mexico

Details
MySQL DB export class, version 1.1.1

WHAT'S NEW?
- The class now is PHP5 compatible

version 1.0.1

WHAT'S NEW?
- The class now can make backups from big databases (+16M in SQL code) when 
it creates a backup file or saves the backup file in users computer.
- Added the task MSX_APPEND

HOW TO USE

1. Create the instance of MySQL_Export class.
2. Define necessary properties.
3. Call Execute() method to create backup.

require_once 'mysql_export.class.php';
$backup_obj = new MySQL_DB_Backup();
$backup_obj->server = 'localhost';
$backup_obj->username = 'username';
$backup_obj->password = 'password';
$backup_obj->database = 'dbname';
$backup_obj->tables = array();
$backup_obj->create_tables = true;
$backup_obj->drop_tables = true;
$backup_obj->struct_only = false;
$backup_obj->locks = true;
$backup_obj->comments = true;
$backup_obj->fname_format = 'd_m_y__H_i_s';
$backup_obj->null_values = array( '0000-00-00', '00:00:00', '0000-00-00 00:00:00');
if (!$backup_obj->Execute(MSX_DOWNLOAD, '', true))
{
  die($backup_obj->error);
}


PUBLIC PROPERTIES

var $server = 'localhost';
The name of MySQL server.

var $port = 3306;
The port of MySQl server.

var $username = 'root';
Database username.

var $password = '';
Database password.

var $database = '';
Name of the database.

var $link_id = -1;
MySQL link identifier of the current connection. You can set this if you
want to connect the MySQL server by your own.

var $connected = false;
Set true if the connection is already established before calling Execute().

var $tables = array();
Tables you want to backup. All tables in the database will be backed up if
this array is empty.

var $create_tables = true;
Backup the structure of tables if true.

var $drop_tables = true;
Add DROP TABLE IF EXISTS queries before CREATE TABLE in backup file.

var $struct_only = false;
Only structure of the tables will be backed up if true.

var $locks = true;
Add LOCK TABLES and UNLOCK TABLES queries before and after each INSERT queries
block.

var $comments = true;
Include comments in backup file if true.

var $backup_dir = '';
Directory on the server where the backup file will be placed. Used if task
parameter equals to MSX_SAVE or MSX_DOWNLOAD in Execute() method.

var $fname_format = 'd_m_y__H_i_s';
Default file name format.

var $error = '';
Error message.

var $null_values = array( '0000-00-00', '00:00:00', '0000-00-00 00:00:00');
Values which must be interpreted as NULL


PUBLIC METHODS

function Execute($task = MSX_STRING, $fname = '', $compress = false)
$task - operation to perform: MSX_STRING - return SQL commands as a string;
  MSX_SAVE - create the backup file on the server; MSX_DOWNLOAD - save backup
  file in the user's computer; MSX_APPEND - append backup in the file on the
  server.
$fname - optional name of backup file.
$compress - use GZip compression?

  Files folder image Files  
File Role Description
Plain text file mysql_db_backup.class.php Class Mysql DB Backup class source
Accessible without login Plain text file execute_db_backup.php Example Example
Accessible without login Plain text file readme.txt Doc. Readme

 Version Control Unique User Downloads Download Rankings  
 0%
Total:1,627
This week:0
All time:2,334
This week:1,099Up
 User Ratings  
 
 All time
Utility:75%StarStarStarStar
Consistency:83%StarStarStarStarStar
Documentation:50%StarStarStar
Examples:58%StarStarStar
Tests:-
Videos:-
Overall:56%StarStarStar
Rank:1467