Hi, this script is suppose to back up most if not all directories, all files within each directory then compressed those files and directories in a zip file and save it to a directory.
A typical web server can be in the hundreds of megs, the script works except it is missing alot of directores and or alot of the files within those directories which results in a server back up that is very short of it's actual size. I was hoping someone could help get this script working I would appreciate it.
<?php
// ZIP Everything into one zip file
// Create a new directory called "mybackup".
// It's important to use that name because you don't want the
// backup script to backup previous backups. It will ignore
// the directory where your backup zipped files are located.
// Call this script something like "backup123.php" and put it into your main website directory.
// Make this script name something that nobody can easily figure out. Don't call it "backup.php"
$file="backup".time().".zip";
if(Zip('./', './mybackup/'.$file)===TRUE){
echo "Zip Complete";
}
else{
echo "Did not zip";
}
function Zip($source, $destination){
if (!extension_loaded('zip') || !file_exists($source)) {
return false;
}
$zip = new ZipArchive();
if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
return false;
}
$source = str_replace('\\', '/', realpath($source));
if (is_dir($source) === true){
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file){
$file = str_replace('\\', '/', $file);
// Ignore "." and ".." folders
if( in_array(substr($file, strrpos($file, '/')+1), array('.', '..','mybackup')) )
continue;
$file = realpath($file);
if (is_dir($file) === true){
$zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
}
else if (is_file($file) === true){
$zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
}
}
}
else if (is_file($source) === true){
$zip->addFromString(basename($source), file_get_contents($source));
}
return $zip->close();
}
?>