예제 #1
0
파일: Fs.php 프로젝트: Konstnantin/zf-app
 public static function old_scandir($base = '', &$data = array())
 {
     if (substr($base, -1, 1) != DIRECTORY_SEPARATOR) {
         $base = $base . DIRECTORY_SEPARATOR;
     }
     $array = array_diff(scandir($base), array('.', '..', '.DS_Store'));
     foreach ($array as $value) {
         if (is_dir($base . $value)) {
             $data[] = $base . $value . DIRECTORY_SEPARATOR;
             $data = Z_Fs::rscandir($base . $value . DIRECTORY_SEPARATOR, $data);
         } elseif (is_file($base . $value)) {
             $data[] = $base . $value;
         }
     }
     return $data;
 }
예제 #2
0
 public function listAction()
 {
     $path = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'backups' . DIRECTORY_SEPARATOR;
     if (file_exists($path)) {
         $filesIn = Z_Fs::rscandir($path);
         $result = null;
         foreach ($filesIn as $fileIn) {
             $pi = pathinfo($fileIn);
             //backup_" . date("m-d-Y_H-i") . ".tar")
             if (isset($pi['extension']) && $pi['extension'] == 'tar' && isset($pi['basename'])) {
                 $pattern = "#backup\\_(\\d+\\-\\d+\\-\\d{2,4}\\_\\d+\\-\\d+)#";
                 $matches = array();
                 preg_match($pattern, $pi['basename'], $matches);
                 if (isset($matches[1])) {
                     $name = base64_encode($pi['basename']);
                     $date = new Zend_Date($matches[1], 'MM-dd-yyyy_h-m');
                     $result[] = array('name' => $name, 'date' => $date->get(Zend_Date::DATETIME_MEDIUM), 'size' => Z_Fs::getFormattedFileSize($fileIn));
                 }
             }
         }
         $this->view->backups = $result;
     }
 }
예제 #3
0
 public function init()
 {
     // create backup directory if not exists
     $errors = array();
     $this->setFileAmount(0);
     $backup_dir = $this->getBackupDir();
     // cleanup old backups
     if (is_file($backup_dir . "/backup-dump.sql")) {
         unlink($backup_dir . "/backup-dump.sql");
     }
     // get steps
     $steps = array();
     // get available tables
     $model = new Z_Model_Config();
     $db = $model->getAdapter();
     $tables = $db->fetchAll("SHOW FULL TABLES");
     $steps[] = array("mysql-tables", null);
     // tables
     foreach ($tables as $table) {
         $name = current($table);
         $type = next($table);
         if ($type != "VIEW") {
             $steps[] = array("mysql", array("name" => $name, "type" => $type));
         }
     }
     // views
     foreach ($tables as $table) {
         reset($table);
         $name = current($table);
         $type = next($table);
         if ($type == "VIEW") {
             $steps[] = array("mysql", array("name" => $name, "type" => $type));
         }
     }
     $steps[] = array("mysql-complete", null);
     // check files
     $currentFileCount = 0;
     $currentFileSize = 0;
     $currentStepFiles = array();
     // check permissions
     $filter_dir_end_name = array('session', 'captcha', 'cache', 'backups');
     $filesIn = Z_Fs::rscandir($this->PR_ROOT, $filter_dir_end_name);
     clearstatcache();
     $filesToBackup = null;
     foreach ($filesIn as $fileIn) {
         if (!is_readable($fileIn)) {
             $errors[] = $fileIn . " is not readable.";
         }
         if ($currentFileCount > 300 || $currentFileSize > 20000000) {
             $currentFileCount = 0;
             $currentFileSize = 0;
             if (!empty($currentStepFiles)) {
                 $filesToBackup[] = $currentStepFiles;
             }
             $currentStepFiles = array();
         }
         if (file_exists($fileIn)) {
             $currentFileSize += filesize($fileIn);
             $currentFileCount++;
             $currentStepFiles[] = $fileIn;
         }
     }
     if (!empty($currentStepFiles)) {
         $filesToBackup[] = $currentStepFiles;
     }
     if (count($filesToBackup)) {
         $this->setFilesToBackup($filesToBackup);
         $fileSteps = count($filesToBackup);
         for ($i = 0; $i < $fileSteps; $i++) {
             $steps[] = array("files", array("step" => $i));
         }
         $steps[] = array("complete", null);
     }
     if (!empty($errors)) {
         $steps = null;
     }
     return array("steps" => $steps, "errors" => $errors);
 }