MySQL Backup Pro Class
Version: 1.5
Last update: 3 year ago
Platforms: MySQL, PHP, XML, SQL, CSV, WebDAV, FTP, MAIL, HTTP, ZIP
Example included: yes
Asq a question Purchase
description

MySQL Backup Pro Class allows you:

  • backup your MySQL database as SQL, CSV or XML;
  • upload backup to FTP server;
  • send backup as email attachment;
  • upload to Google Drive, Dropbox, Box, SkyDrive and other cloud using WebDAV;
  • send to server using PUTS HTTP;
  • support MySQL, MySQLi and PDO driver;
  • use CRON to automate backup your data;
  • easy installation on any server;
  • examples of both functions are included;
  • fully documented.
installation

Copy backup.php on your server and include in PHP script when you need it:

require_once('backup.php');
connect to database

Function DB::init($settings) can get parameters:

  • $settings['driver'] : MySQL Driver 'mysql', 'mysqli' or 'pdo' value. From PHP5.5 'mysql' not provided, please use 'mysqli';
  • $params['host'] : The MySQL server. It can also include a port number. e.g. "hostname:port" or a path to a local socket e.g. ":/path/to/socket" for the localhost;
  • $params['username'] : The username;
  • $params['password'] : The password;
  • $params['database'] : The name of the database that is to be selected.
  • $params['temp'] : Path to save files. By default script's folder
Example
$params = array( 'driver' => 'mysql', 'host' => 'localhost', 'username' => 'root', 'password' => 'pass123', 'database' => 'test' );
backup
SQL
Backup MySQL database as SQL file. Backup::init($params)->as_sql();
CSV
Backup MySQL database as CSV files. Parameters:
  • $delimeter - csv file delimeter (by default ";" ("," needed for MacOs csv)).
Backup::init($params)->as_csv($delimiter);
XML
 Backup MySQL database as XML file. Parameters (array):
  • root - root tag (after xml definition) (by default "mysql");
  • db_tag - database tag (by default "database");
  • db_prop - database property name (by default "name");
  • if exist db_prop in xml file write string ;
  • if not exist db_prop in xml file write string ;
  • if not exist db_prop and exist db_tag in xml file write string ;
  • if not exist db_prop and not exist db_tag this tag is skipped;
  • table_tag - table tag (by default "table");
  • table_prop - table property (by default "name");
  • row_tag - row tag (by default "row");
  • field_tag - field tag (by default "field");
  • field_prop - field property (by default "name").
Backup::init($params)->as_xml($xml_params);
save

Save backup on server. Parameters:

  • $path - path to save file
Backup::init($params)->as_sql()->save($path);

mail

Send backup as attachment on email. Parameters:

  • $email - email address receive backup files
  • $emailFrom - email address for parameter From. By default noreply@mailer.com
Backup::init($params)->as_sql()->mail('your_emal@mail.com');

ftp

Upload backup to FTP server. Parameters (array):

  • server - server name or ip;
  • user - username;
  • pass - password;
  • dest - folder when file is saving.
Backup::init($params)->as_sql()->ftp($ftp_params);

http

Upload backup to HTTP server using method PUTS. Parameters (array):

  • server - server name or ip;
  • user - username;
  • pass - password.
Backup::init($params)->as_sql()->http($http_params);

webdav

Upload backup to cloud using WebDAV. Support services:

  • Google Drive (https://dav-pocket.appspot.com);
  • Box.com;
  • Dropbox (http://dropdav.com);
  • SkyDrive;
  • Yandesk.Disk;
  • and other supported WebDAV.

Parameters (array):

  • server - server name;
  • user - username;
  • pass - password.
Backup::init($params)->as_sql()->webdav($webdav_params);

zip

Supported in PHP 5.2+

Example:

Backup::init($params)->as_sql()->zip()->http($http_params);
remove

Remove files after sending.

Example:

Backup::init($params)->as_sql()->zip()->http($http_params)->remove();
errors

Show Errors, collected in the class.

Example:

Backup::init($params)->as_sql()->zip()->showErrors();
Changelog
Version 1.5
  • Add remove function
  • Add temp path parameter
  • New error system
Version 1.3
  • Minor bug fixes
Version 1.2
  • Add ZIP method
Version 1.1
  • Add PDO driver
Version 1.0
  • Released
0