From d9baa76804728bba0386da89312e4fb3d23b7930 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Mon, 23 Jul 2012 08:06:15 +0100 Subject: [PATCH] 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 --- lib/config.php | 2 +- plugins/zip-it/index.php | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/config.php b/lib/config.php index 0350b2f..ce81f20 100644 --- a/lib/config.php +++ b/lib/config.php @@ -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:Zipping Files","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:Zipping Files","30") ), "theme" => "default", "tabWidth" => 4, diff --git a/plugins/zip-it/index.php b/plugins/zip-it/index.php index c4eecba..57f52ac 100644 --- a/plugins/zip-it/index.php +++ b/plugins/zip-it/index.php @@ -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
"); + } + } + } + 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 ''; - $zipItAddToZip = $zipItDoZip->zipFilesUp($zipItSaveLocation.$zipItFileName); + $zipItAddToZip = $zipItDoZip->zipFilesUp($zipItSaveLocation,$zipItFileName,$keepLastDays); if (!$zipItAddToZip) { echo ''; } else {