示例#1
0
 protected function getMainBodyTable()
 {
     $ret = $this->getTopTableHeader();
     $dirname = $GLOBALS['PRJ_DIR'] . '/admin/backup/';
     //var_dump($dirname);
     $dir = @opendir($dirname);
     $files = array();
     while ($file = @readdir($dir)) {
         $fullname = $dirname . $file;
         if ($file == "." || $file == ".." || @is_dir($fullname)) {
             continue;
         } else {
             if (@file_exists($fullname)) {
                 $files[] = array('name' => $fullname, 'name2' => $file, 'type' => 0, 'ext' => substr($file, strrpos($file, ".")), 'stat' => stat($fullname));
             }
         }
     }
     @closedir($dir);
     foreach ($files as $current) {
         //var_dump($current['ext']);
         if ($current['ext'] == '.gz') {
             $ret .= '<tr>';
             $tmp_ret = '';
             $link = str_replace($GLOBALS['PRJ_DIR'], '', $current['name']);
             $ret .= '<td>' . $current['name2'] . '</td>';
             $ret .= '<td>' . str_replace($_SERVER['DOCUMENT_ROOT'], '', $current['name']) . '</td>';
             $ret .= '<td>' . CUtils::getSize($current['stat'][7]) . '</td>';
             $ret .= '<td>' . date('d.m.Y H:i:s', $current['stat'][9]) . '</td>';
             $ret .= $this->getUpdateDelete($link) . '</tr>' . "\n";
         }
     }
     $ret .= $this->getTopTableFooter();
     return $ret;
 }
示例#2
0
 public static function getFileSize($ref, $precision = 2)
 {
     $ret = '';
     if (@file_exists($GLOBALS['PRJ_DIR'] . $ref)) {
         $ret = CUtils::getSize(max(filesize($GLOBALS['PRJ_DIR'] . $ref), 0), $precision);
     }
     return $ret;
 }
示例#3
0
function makeArchive($fD)
{
    $my_time = time();
    $my_key = CUtils::genKey(8);
    $objResponse = new xajaxResponse();
    $objResponse->assign("archive_info", 'innerHTML', '');
    $filename = 'admin/backup/' . date('YmdHi', $my_time) . '_' . $my_key . '.tar.gz';
    $filename_sql = 'admin/backup/' . date('YmdHi', $my_time) . '_' . $my_key . '.sql';
    $filename_sql2 = 'admin/backup/' . date('YmdHi', $my_time) . '_' . $my_key . '_after_connect.sql';
    $f = fopen($GLOBALS['PRJ_DIR'] . '/' . $filename_sql2, "a");
    fwrite($f, "/*!41000 SET NAMES 'cp1251' */;");
    fclose($f);
    set_time_limit(0);
    $GLOBALS['db']->backupDB($filename_sql);
    inc_lib('tools/CArchive.php');
    $test = new gzip_file($filename);
    $test->set_options(array('basedir' => $GLOBALS['PRJ_DIR'] . '/', 'overwrite' => 1, 'level' => 5));
    $test->add_files(array("*.*"));
    //$test->exclude_files(array("admin/lib/templates_c/*.php", "*.gz"));
    $cfiles = 0;
    $sfiles = 0;
    foreach ($test->files as $key => $current) {
        if (stristr($current['name'], '.tar.gz')) {
            unset($test->files[$key]);
        } else {
            $sfiles += $current['stat'][7];
            $cfiles++;
        }
    }
    $test->create_archive();
    $text = '';
    $text .= 'Количество файлов: ' . $cfiles;
    $text .= '<br>';
    $text .= 'Размер неупакованых файлов: ' . CUtils::getSize($sfiles, 2);
    $text .= '<br>';
    $text .= 'Размер архива: ' . CUtils::getFileSize('/' . $filename, 2);
    //$text = 'test';
    @unlink($GLOBALS['PRJ_DIR'] . '/' . $filename_sql);
    @unlink($GLOBALS['PRJ_DIR'] . '/' . $filename_sql2);
    $objResponse->assign("archive_info", 'innerHTML', $text);
    $objResponse->script("hideDiv('waiting');window.location.reload()");
    return $objResponse;
}