Jump to content
Aerosol

Backup Script

Recommended Posts

Posted

<?php
ini_set('memory_limit', '64M');ignore_user_abort(true);set_time_limit(0);
Zip($_SERVER['DOCUMENT_ROOT'],$_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "backup-". time() .".zip");
echo "finish";
function Zip($source, $destination){
if (extension_loaded('zip') === true){
if (file_exists($source) === true){
$zip = new ZipArchive();
if ($zip->open($destination, ZIPARCHIVE::CREATE) === true){
$source = realpath($source);
if (is_dir($source) === true){
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file){
$file = realpath($file);
if (is_dir($file) === true){
$zip->addEmptyDir(str_replace($source . DIRECTORY_SEPARATOR, '', $file . DIRECTORY_SEPARATOR));
}else if (is_file($file) === true){
$zip->addFromString(str_replace($source . DIRECTORY_SEPARATOR, '', $file), file_get_contents($file));
}
}
}else if (is_file($source) === true){
$zip->addFromString(basename($source), file_get_contents($source));
}
}
return $zip->close();
}
}
return false;
}
?>

it backup all files in the ROOTDIR into a backup-%time%.zip

have fun with it. :D

Credits to : T3N38R15

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...