ZipIt now backs up every 30 mins and dels >7 days

Now backs up every 30 mins instead of 10 mins
New var defining no of days to keep
Location & filename now seperate params
keepLastDays var passed through as well now
This is used when scanning backups dir
Any files older than this no of days removed
All zip files created are perm 777 now so you can manually delete
This commit is contained in:
Matt Pass
2012-07-23 08:06:15 +01:00
parent 88cd0996ec
commit d9baa76804
2 changed files with 17 additions and 3 deletions

View File

@@ -18,7 +18,7 @@ $ICEcoder = array(
"plugins" => array(
array("Database Admin","images/database.png","margin-top: 3px","plugins/adminer/adminer-3.3.3-mysql-en.php","_blank",""),
array("Batch Image Processor","images/images.png","margin-top: 5px","http://birme.net","_blank",""),
array("Zip It!","images/zip-it.png","margin-top: 3px","plugins/zip-it/?zip=|&exclude=.doc,.gif,.jpg,.jpeg,.pdf,.png,.swf,.xml,.zip","fileControl:<b>Zipping Files</b>","10")
array("Zip It!","images/zip-it.png","margin-top: 3px","plugins/zip-it/?zip=|&exclude=.doc,.gif,.jpg,.jpeg,.pdf,.png,.swf,.xml,.zip","fileControl:<b>Zipping Files</b>","30")
),
"theme" => "default",
"tabWidth" => 4,

View File

@@ -15,10 +15,12 @@ include("../../lib/settings.php");
$zipItSaveLocation = '../../backups/';
if ($_GET['zip']=="|") {$zipItFileName = "root";} else {$zipItFileName = str_replace("|","_",strClean($_GET['zip']));};
$zipItFileName .= '-'.time().'.zip';
$keepLastDays = 7;
if (!is_dir($zipItSaveLocation)) {mkdir($zipItSaveLocation, 0777);}
Class zipIt {
public function zipFilesUp($zipName='') {
public function zipFilesUp($zipDir,$zipFile,$keepLastDays) {
$zipName = $zipDir.$zipFile;
$zipFiles = array();
$_GET['zip']=="|" ? $zipTgt = "" : $zipTgt = str_replace("|","/",strClean($_GET['zip']));
if (strpos($_GET['zip'],"/")!==0) {$zipTgt = "/".$zipTgt;};
@@ -39,6 +41,17 @@ Class zipIt {
} else {
if(file_exists($addItem)) {$zipFiles[] = $addItem;}
}
if ($backupsDir = opendir($zipDir)) {
$keepTime = $keepLastDays*60*60*24;
while (false !== ($backup = readdir($backupsDir))) {
if ($backup != "." && $backup != "..") {
if ((time()-filemtime($zipDir.$backup)) > $keepTime) {
unlink($zipDir.$entry) or DIE("couldn't delete $zipDir$backup<br>");
}
}
}
closedir($backupsDir);
}
if(count($zipFiles)) {
$zip = new ZipArchive();
if($zip->open($zipName,ZIPARCHIVE::CREATE)!== true) {return false;}
@@ -53,6 +66,7 @@ Class zipIt {
}
}
$zip->close();
chmod($zipName, 0777);
return file_exists($zipName);
} else {
return false;
@@ -62,7 +76,7 @@ Class zipIt {
if($_SESSION['userLevel']==10) {
$zipItDoZip = new zipIt();
echo '<script>top.ICEcoder.serverMessage("<b>Zipping Files</b>");</script>';
$zipItAddToZip = $zipItDoZip->zipFilesUp($zipItSaveLocation.$zipItFileName);
$zipItAddToZip = $zipItDoZip->zipFilesUp($zipItSaveLocation,$zipItFileName,$keepLastDays);
if (!$zipItAddToZip) {
echo '<script>top.ICEcoder.message("Could not zip files up!");</script>';
} else {