MySQL Forums
Forum List  »  Backup

Re: create a backup script of my DB
Posted by: tech
Date: March 03, 2006 03:15AM

<?php
/
* MySQLDump Class<br />
* Backs up a database, creating a file for each day of the week,
* using the mysqldump utility.<br />
* Can compress backup file with gzip of bzip2<br />
* Intended for command line execution in conjunction with cron<br />
* Requires the user executing the script has permissions to execute
* <code>
* $mysqlDump = new MySQLDump('harryf','secret','sitepoint','/backups');
* $mysqlDump->backup();
* </code>
* mysqldump.
* @access public
* @package SPLIB
*/
class MySQLDump {
/**
* The backup command to execute
* @private
* @var string
*/
var $cmd;

/**
* MySQLDump constructor
* @param string dbUser (MySQL User Name)
* @param string dbPass (MySQL User Password)
* @param string dbName (Database to select)
* @param string dest (Full destination directory path for backup file)
* @param string zip (Zip type; gz - gzip [default], bz2 - bzip)
* @access public
*/
function MySQLDump ($dbUser,$dbPass,$dbName,$dest,$zip='gz') {
$zip_util=array('gz'=>'gzip','bz2'=>'bzip2');
if (array_key_exists($zip,$zip_util)) {
$fname = $dbName.'.'.date("w").'.sql.'.$zip;
$this->cmd='mysqldump -u'.$dbUser.' -p'.$dbPass.' '.$dbName.
'| '.$zip_util[$zip].' >'.$dest.'/'.$fname;
} else {
$fname = $dbName.'.'.date("w").'.sql';
$this->cmd='mysqldump -u'.$dbUser.' -p'.$dbPass.' '.$dbName.
' >'.$dest.'/'.$fname;
}
}

/**
* Runs the constructed command
* @access public
* @return void
*/
function backup () {
system ($this->cmd, $error);
if($error)
trigger_error ('Backup failed: '.$error);
}
}
?>

Options: ReplyQuote


Subject
Views
Written By
Posted
5360
February 27, 2005 08:16AM
3301
August 28, 2005 11:46PM
3326
August 28, 2005 11:56PM
3301
August 29, 2005 09:37AM
3077
October 06, 2005 08:27PM
3129
October 09, 2005 07:25PM
2922
December 30, 2005 06:39AM
Re: create a backup script of my DB
3836
March 03, 2006 03:15AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.