<?
//otherwise timeout
set_time_limit(300);
///////////////////////////////////////////////////////////
// INCLUDE FILES
///////////////////////////////////////////////////////////
//variables to be set
include_once("config.inc");
//collection with local functies
include_once("funkties_local.inc");
//SOAP functionality
include_once("nusoap.inc");
//zip package
include_once("pclzip-2-3/pclzip.lib.php");
///////////////////////////////////////////////////////////
//END INCLUDE FILES
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//BACKUP FILES
///////////////////////////////////////////////////////////
//new soapclient object: get content from remote directory
$client = new soapclient("http://##URL##/soap_GetDirContent.php");
$dirContent = $client->call("getDirContent",
array("root"=>"aangiftebiljet"));
$dirContent = unserialize($dirContent);
//get content from local directory
$localfilesArr = getDirContent($absRoot);
$tempDirName = time();
$archive = new PclZip($tempDirName.".zip");
$countadded = 0;
//all local files
foreach($localfilesArr as $value) {
$sizeLocal = $value['size'];
$sizeRemote = $dirContent[$value['relRoot']]['size'];
$lastmodLocal = strftime("%d.%m.%Y %H:%M", $value['lastmod']);
$lastmodRemote = strftime("%d.%m.%Y %H:%M", $dirContent[$value['relRoot']]['lastmod']);
//compare (size and last modified) local and remote files
if($sizeLocal!=$sizeRemote || $lastmodLocal!=$lastmodRemote) {
//if not the same, add to zip
$archive->add($value['path']."/".$value['name'], "", $absRoot);
$countadded++;
}
}
//aangifte table
//HIER FLIEGT ER MEISTENS RAUS (aber nicht immer)
if(file_exists($backupRoot."aangifte.csv")) {
chmod($backupRoot."aangifte.csv", 0755);
$testbla = $archive->add($backupRoot."aangifte.csv", "db", $backupRoot) or die("not added");
$countadded++;
echo(", 1 (".$testbla.") ");
$value_size = filesize($backupRoot."aangifte.csv");
//delete local csv-file
unlink($backupRoot."aangifte.csv");
}
///////////////////////////////////////////////////////////
//BACKUP DATABASE
///////////////////////////////////////////////////////////
//for all tables
$sql = "show tables";
$result = mysql_query($sql) or die(mysql_error());
while($data = mysql_fetch_row($result)) {
foreach($data as $key=>$value) {
if($value != "aangifte") {
//create Backupfile
...
//add backupfile to zip archive
$archive->add($backupRoot.$value.".csv", "db", $backupRoot);
$countadded++;
//delete local csv-file
unlink($backupRoot.$value.".csv");
}
}
}
}
chmod($backupRoot.$tempDirName.".zip", 0755);
echo("aantal bestanden (inkl. database backup): ".$countadded."<br>");
///////////////////////////////////////////////////////////
//END BACKUP DATABASE
///////////////////////////////////////////////////////////
//if anything added, zip file has to be sent to remote server
if($countadded>0) {
//send everything per ftp
...
//new soapclient object: unzip uploaded zip file
$client = new soapclient("http://##URL##/soap_Update.php");
$update = $client->call("update",
array("zipname"=>"$remote_file"));
$update = unserialize($update);
} else {
fwrite($fp, "nothing to update".chr(13).chr(10));
}
///////////////////////////////////////////////////////////
//END BACKUP FILES
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//UPDATE REMOTE DATABASE
///////////////////////////////////////////////////////////
//new soapclient object: delete and update tables
$client = new soapclient("http://##URL##/soap_UpdateDb.php");
$resUpdateDb = $client->call("updateDb", array());
///////////////////////////////////////////////////////////
//END UPDATE REMOTE DATABASE
///////////////////////////////////////////////////////////
?>