diff --git a/module/backup/config.php b/module/backup/config.php index 5c4f0d8e57..4cec28e064 100644 --- a/module/backup/config.php +++ b/module/backup/config.php @@ -1,3 +1,4 @@ backup = new stdclass(); $config->backup->holdDays = 14; +$config->backup->setting = ''; diff --git a/module/backup/control.php b/module/backup/control.php index 2b8b21f4bc..a37a85f4d1 100644 --- a/module/backup/control.php +++ b/module/backup/control.php @@ -60,6 +60,14 @@ class backup extends control { $backupFile->files[$this->backupPath . $backupFile->name . '.code.zip.php'] = abs(filesize($this->backupPath . $backupFile->name . '.code.zip.php')); } + if(file_exists($this->backupPath . $backupFile->name . '.file')) + { + $backupFile->files[$this->backupPath . $backupFile->name . '.file'] = $this->backup->getDirSize($this->backupPath . $backupFile->name . '.file'); + } + if(file_exists($this->backupPath . $backupFile->name . '.code')) + { + $backupFile->files[$this->backupPath . $backupFile->name . '.code'] = $this->backup->getDirSize($this->backupPath . $backupFile->name . '.code'); + } $backups[$backupFile->name] = $backupFile; } @@ -98,9 +106,14 @@ class backup extends control } $this->backup->addFileHeader($this->backupPath . $fileName . '.sql.php'); - if(extension_loaded('zlib')) + if((extension_loaded('zlib') or strpos($this->config->backup->setting, 'nozip') !== false) and strpos($this->config->backup->setting, 'nofile') === false) { - $result = $this->backup->backFile($this->backupPath . $fileName . '.file.zip.php'); + $nozip = strpos($this->config->backup->setting, 'nozip') !== false; + + $backFileName = $this->backupPath . $fileName . '.file'; + if(!$nozip) $backFileName .= '.zip.php'; + + $result = $this->backup->backFile($backFileName); if(!$result->result) { if($reload == 'yes') @@ -113,9 +126,11 @@ class backup extends control printf($this->lang->backup->error->backupFile, $result->error); } } - $this->backup->addFileHeader($this->backupPath . $fileName . '.file.zip.php'); + if(!$nozip) $this->backup->addFileHeader($backFileName); - $result = $this->backup->backCode($this->backupPath . $fileName . '.code.zip.php'); + $backFileName = $this->backupPath . $fileName . '.code'; + if(!$nozip) $backFileName .= '.zip.php'; + $result = $this->backup->backCode($backFileName); if(!$result->result) { if($reload == 'yes') @@ -128,7 +143,7 @@ class backup extends control printf($this->lang->backup->error->backupCode, $result->error); } } - $this->backup->addFileHeader($this->backupPath . $fileName . '.code.zip.php'); + if(!$nozip) $this->backup->addFileHeader($backFileName); } /* Delete expired backup. */ @@ -182,6 +197,12 @@ class backup extends control if(!$result->result) $this->send(array('result' => 'fail', 'message' => sprintf($this->lang->backup->error->resotreFile, $result->error))); } + if(file_exists($this->backupPath . $fileName . '.file')) + { + $result = $this->backup->restoreFile($this->backupPath . $fileName . '.file'); + if(!$result->result) $this->send(array('result' => 'fail', 'message' => sprintf($this->lang->backup->error->resotreFile, $result->error))); + } + $this->send(array('result' => 'success', 'message' => $this->lang->backup->success->restore)); } @@ -215,6 +236,20 @@ class backup extends control die(js::alert(sprintf($this->lang->backup->error->noDelete, $this->backupPath . $fileName . '.code.zip.php'))); } + /* Delete attatchments dir. */ + if(file_exists($this->backupPath . $fileName . '.file')) + { + $zfile = $this->app->loadClass('zfile'); + $zfile->removeDir($this->backupPath . $fileName . '.file'); + } + + /* Delete code dir. */ + if(file_exists($this->backupPath . $fileName . '.code')) + { + $zfile = $this->app->loadClass('zfile'); + $zfile->removeDir($this->backupPath . $fileName . '.code'); + } + die(js::reload('parent')); } @@ -235,4 +270,24 @@ class backup extends control $this->display(); } + + /** + * Setting backup + * + * @access public + * @return void + */ + public function setting() + { + if(strtolower($this->server->request_method) == "post") + { + $data = fixer::input('post')->join('setting', ',')->get(); + $setting = ''; + if(isset($data->setting)) $setting = $data->setting; + $this->loadModel('setting')->setItem('system.backup.setting', $setting); + + die(js::reload('parent.parent')); + } + $this->display(); + } } diff --git a/module/backup/js/setting.js b/module/backup/js/setting.js new file mode 100644 index 0000000000..bb7f87c334 --- /dev/null +++ b/module/backup/js/setting.js @@ -0,0 +1,15 @@ +$(function() +{ + $('#settingnofile').change(function() + { + if($(this).prop('checked')) + { + $('#settingnozip').closest('.checkbox-primary').hide(); + } + else + { + $('#settingnozip').closest('.checkbox-primary').show(); + } + }) + $('#settingnofile').change(); +}); diff --git a/module/backup/lang/en.php b/module/backup/lang/en.php index 0ffabaf795..efac67a838 100644 --- a/module/backup/lang/en.php +++ b/module/backup/lang/en.php @@ -12,6 +12,10 @@ $lang->backup->time = 'Date'; $lang->backup->files = 'Files'; $lang->backup->size = 'Size'; +$lang->backup->setting = 'Setting'; +$lang->backup->settingList['nofile'] = 'Not backup file and code.'; +$lang->backup->settingList['nozip'] = 'Only copy file'; + $lang->backup->waitting = ' In Progress. Please wait...'; $lang->backup->confirmDelete = 'Do you want to delete the backup?'; $lang->backup->confirmRestore = 'Do you want to restore the backup?'; diff --git a/module/backup/lang/zh-cn.php b/module/backup/lang/zh-cn.php index 425e8c6654..587c6073d7 100644 --- a/module/backup/lang/zh-cn.php +++ b/module/backup/lang/zh-cn.php @@ -12,6 +12,10 @@ $lang->backup->time = '备份时间'; $lang->backup->files = '备份文件'; $lang->backup->size = '大小'; +$lang->backup->setting = '设置'; +$lang->backup->settingList['nofile'] = '不备份附件和代码'; +$lang->backup->settingList['nozip'] = '只拷贝文件'; + $lang->backup->waitting = '正在进行中,请稍候...'; $lang->backup->confirmDelete = '是否删除备份?'; $lang->backup->confirmRestore = '是否还原该备份?'; diff --git a/module/backup/model.php b/module/backup/model.php index 2606d10d67..23b109a7de 100644 --- a/module/backup/model.php +++ b/module/backup/model.php @@ -37,13 +37,23 @@ class backupModel extends model $return->result = true; $return->error = ''; - $this->app->loadClass('pclzip', true); - $zip = new pclzip($backupFile); - $zip->create($this->app->getAppRoot() . 'www/data/', PCLZIP_OPT_REMOVE_PATH, $this->app->getAppRoot() . 'www/data/'); - if($zip->errorCode() != 0) + $nozip = strpos($this->config->backup->setting, 'nozip') !== false; + if(!$nozip) { - $return->result = false; - $return->error = $zip->errorInfo(); + $this->app->loadClass('pclzip', true); + $zip = new pclzip($backupFile); + $zip->create($this->app->getAppRoot() . 'www/data/', PCLZIP_OPT_REMOVE_PATH, $this->app->getAppRoot() . 'www/data/'); + if($zip->errorCode() != 0) + { + $return->result = false; + $return->error = $zip->errorInfo(); + } + } + else + { + if(!is_dir($backupFile)) mkdir($backupFile, 0777, true); + $zfile = $this->app->loadClass('zfile'); + $zfile->copyDir($this->app->getAppRoot() . 'www/data/', $backupFile); } return $return; @@ -75,13 +85,37 @@ class backupModel extends model $fileList = array_merge($fileList, $wwwFileList); - $this->app->loadClass('pclzip', true); - $zip = new pclzip($backupFile); - $zip->create($fileList, PCLZIP_OPT_REMOVE_PATH, $appRoot); - if($zip->errorCode() != 0) + $nozip = strpos($this->config->backup->setting, 'nozip') !== false; + if(!$nozip) { - $return->result = false; - $return->error = $zip->errorInfo(); + $this->app->loadClass('pclzip', true); + $zip = new pclzip($backupFile); + $zip->create($fileList, PCLZIP_OPT_REMOVE_PATH, $appRoot); + if($zip->errorCode() != 0) + { + $return->result = false; + $return->error = $zip->errorInfo(); + } + } + else + { + if(!is_dir($backupFile)) mkdir($backupFile, 0777, true); + $zfile = $this->app->loadClass('zfile'); + foreach($fileList as $codeFile) + { + $file = trim(str_replace($appRoot, '', $codeFile), DS); + if(is_dir($codeFile)) + { + if(!is_dir($backupFile . DS . $flle)) mkdir($backupFile . DS . $flle, 0777, true); + $zfile->copyDir($codeFile, $backupFile . DS . $file); + } + else + { + $dirName = dirname($file); + if(!is_dir($backupFile . DS . $dirName)) mkdir($backupFile . DS . $dirName, 0777, true); + $zfile->copyFile($codeFile, $backupFile . DS . $file); + } + } } return $return; @@ -113,12 +147,21 @@ class backupModel extends model $return->result = true; $return->error = ''; - $this->app->loadClass('pclzip', true); - $zip = new pclzip($backupFile); - if($zip->extract(PCLZIP_OPT_PATH, $this->app->getAppRoot() . 'www/data/') == 0) + $nozip = strpos($this->config->backup->setting, 'nozip') !== false; + if(!$nozip) { - $return->result = false; - $return->error = $zip->errorInfo(); + $this->app->loadClass('pclzip', true); + $zip = new pclzip($backupFile); + if($zip->extract(PCLZIP_OPT_PATH, $this->app->getAppRoot() . 'www/data/') == 0) + { + $return->result = false; + $return->error = $zip->errorInfo(); + } + } + else + { + $zfile = $this->app->loadClass('zfile'); + $zfile->copyDir($backupFile, $this->app->getAppRoot() . 'www/data/'); } return $return; @@ -208,4 +251,28 @@ class backupModel extends model fclose($fh); return true; } + + /** + * Get dir size. + * + * @param string $dir + * @access public + * @return int + */ + public function getDirSize($dir) + { + $size = 0; + foreach(glob("$dir/*") as $file) + { + if(is_dir($file)) + { + $size += $this->getDirSize($file); + } + else + { + $size += abs(filesize($file)); + } + } + return $size; + } } diff --git a/module/backup/view/index.html.php b/module/backup/view/index.html.php index aad455a88d..10db3a0ba1 100644 --- a/module/backup/view/index.html.php +++ b/module/backup/view/index.html.php @@ -21,7 +21,10 @@
backup->common;?>
-
+
+ + +
diff --git a/module/backup/view/setting.html.php b/module/backup/view/setting.html.php new file mode 100644 index 0000000000..5fb46d6095 --- /dev/null +++ b/module/backup/view/setting.html.php @@ -0,0 +1,32 @@ + + * @package backup + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +
+
+

backup->setting;?>

+
+
+ + + + + +
+
+ backup->settingList, isset($config->backup->setting) ? $config->backup->setting : '');?> +
+
+
+
+ +