File: /home/bkpall.php
<?
set_time_limit(2500);
ini_set("memory_limit","512M");
//Backup Gestion
$dbhost = "127.0.0.1"; // usually localhost
$dbuser = "root";
$dbpass = "beto23casela";
$files_to_zip = array(
'bkp/afiliadesuteorg_sistema'.date("Y-m-d").'.sql'
);
//mysqldump --create-options -h 127.0.0.1 -u root -pbeto23casela gestyon_gpstotal > gpstotal.zip
foreach($files_to_zip as $file) {
$backupfile = $file;
$labase = str_replace("bkp/","",str_replace(date("Y-m-d").".sql","",$file));
system("mysqldump --create-options -h $dbhost -u $dbuser -p$dbpass ".$labase." --ignore-table=".$labase.".logpausadas > $backupfile");
}
$result = create_zip($files_to_zip,'bkp/bkp'.date("Y-m-d").'.zip');
foreach($files_to_zip as $file) {
unlink($file);
}
/* creates a compressed zip file */
function create_zip($files = array(),$destination = '',$overwrite = false) {
//if the zip file already exists and overwrite is false, return false
if(file_exists($destination) && !$overwrite) { return false; }
//vars
$valid_files = array();
//if files were passed in...
if(is_array($files)) {
//cycle through each file
foreach($files as $file) {
//make sure the file exists
if(file_exists($file)) {
$valid_files[] = $file;
}
}
}
//if we have good files...
if(count($valid_files)) {
//create the archive
$zip = new ZipArchive();
if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
return false;
}
//add the files
foreach($valid_files as $file) {
$zip->addFile($file,$file);
}
//debug
//echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
//close the zip -- done!
$zip->close();
//check to make sure the file exists
return file_exists($destination);
}
else
{
return false;
}
}
?>