PHP Classes

File: execute_db_backup.php

Recommend this page to a friend!
  Classes of Luis Arturo Aguilar Mendoza  >  MySQL DB Backup  >  execute_db_backup.php  >  Download  
File: execute_db_backup.php
Role: Example script
Content type: text/plain
Description: Example
Class: MySQL DB Backup
Generate backup files of large MySQL databases
Author: By
Last change: Example for new class version (1.1.0)
Date: 11 years ago
Size: 3,822 bytes
 

Contents

Class file image Download
<?
   
/*
        |-----------------------------------------------------------------------|
        | Example MySQL DB Backup for PHP5 1.1.0 File |
        | |
        | Written by: Luis Arturo Aguilar Mendoza <minibikec@prodigy.net.mx> |
        | Released under GNU Public license. |
        | |
        | Only use with MySQL DB Bakup class for PHP5. |
        |-----------------------------------------------------------------------|
    */
   
   
require_once 'mysql_db_backup.class.php';
   
$backup_obj = new MySQL_DB_Backup();
   
   
//----------------------- EDIT - REQUIRED SETUP VARIABLES -----------------------
           
           
$backup_obj->server = 'localhost';
           
$backup_obj->port = 3306;
           
$backup_obj->username = 'root';
           
$backup_obj->password = '';
           
$backup_obj->database = 'mdbbk';
           
           
//Tables you wish to backup. All tables in the database will be backed up if this array is null.
           
$backup_obj->tables = array();

   
//------------------------ END - REQUIRED SETUP VARIABLES -----------------------
   
    //-------------------- OPTIONAL PREFERENCE VARIABLES ---------------------
           
            //Add DROP TABLE IF EXISTS queries before CREATE TABLE in backup file.
           
$backup_obj->drop_tables = true;
           
           
//No table structure will be backed up if false
           
$backup_obj->create_tables = true;

           
//Only structure of the tables will be backed up if true.
           
$backup_obj->struct_only = false;

           
//Add LOCK TABLES before data backup and UNLOCK TABLES after
           
$backup_obj->locks = true;

           
//Include comments in backup file if true.
           
$backup_obj->comments = true;
           
           
//Directory on the server where the backup file will be placed. Used only if task parameter equals MSX_SAVE.
           
$backup_obj->backup_dir = './';
           
           
//Default file name format.
           
$backup_obj->fname_format = 'm_d_Y';
           
           
//Values you want to be intrerpreted as NULL
           
$backup_obj->null_values = array( '0000-00-00', '00:00:00', '0000-00-00 00:00:00');
   
//--------------------- END - OPTIONAL PREFERENCE VARIABLES ---------------------
           
    //---------------------- EDIT - REQUIRED EXECUTE VARIABLES ----------------------
               
            /*
                Task:
                    MSX_STRING - Return SQL commands as a single output string.
                    MSX_SAVE - Create the backup file on the server.
                    MSX_DOWNLOAD - Download backup file to the user's computer.
                    MSX_APPEND - Append the backup to the file on the server.
                   
            */
           
$task = MSX_DOWNLOAD;
           
           
//Optional name of backup file if using 'MSX_APPEND', 'MSX_SAVE' or 'MSX_DOWNLOAD'. If nothing is passed, the default file name format will be used.
           
$filename = '';
           
           
//Use GZip compression if using 'MSX_APPEND', 'MSX_SAVE' or 'MSX_DOWNLOAD'?
           
$use_gzip = true;

   
//--------------------- END - REQUIRED EXECUTE VARIABLES ----------------------
   
    //-------------------- NO NEED TO ANYTHING BELOW THIS LINE --------------------
   
   
$result_bk = $backup_obj->Execute($task, $filename, $use_gzip);
    if (!
$result_bk)
    {
        
$output = $backup_obj->error;
    }
    else
    {
       
$output = 'Operation Completed Successfully At: <b>' . date('g:i:s A') . '</b><i> ( Local Server Time )</i>';
        if (
$task == MSX_STRING)
        {
           
$output.= '\n' . $result_bk;
        }
    }
    if (
$task != MSX_DOWNLOAD)
    {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>MySQL Backup</title>
</head>
<body>
<?
   
echo $output;
?>
</body>
</html>
<?
   
}
?>

For more information send a message to info at phpclasses dot org.