redirect($_SERVER['HTTP_REFERER'], $sysmsg); } $random = random(8); cache_write('backup_temp_tables.php', $tables); } else { if (!($tables = cache_read('backup_temp_tables.php'))) { $sysmsg[] = __('cannot_write_backup_database_list'); redirect($_SERVER['HTTP_REFERER'], $sysmsg); } } $sql_data = ''; $tableid = $tableid ? $tableid - 1 : 0; $startfrom = $startfrom ? $startfrom : 0; $tablenumber = count($tables); for ($i = $tableid; $i < $tablenumber && strlen($sql_data) < $sizelimit * 1000; $i++) { $sql_data .= sql_dumptable($tables[$i], $startfrom, strlen($sql_data)); $startfrom = 0; } if (!$error) { if (trim($sql_data)) { $sqldump = "# Database backup file, auto-generated by PHPDISK. " . LF; $sqldump .= "# -------------------------------------------" . LF . LF . $sql_data; $tableid = $i; $filename = $configs['dbname'] . '_' . date('Ymd') . '_' . $random . '_' . $fileid . '.sql'; $fileid++; $bakfile = $bak_dir . $filename; if (!is_writable($bak_dir)) { $sysmsg[] = __('sql_cannot_write'); redirect($_SERVER['HTTP_REFERER'], $sysmsg); } file_put_contents($bakfile, $sqldump);
$db->query("SET NAMES '" . $sqlcharset . "';\n\n"); } if ($sqlcompat == 'MYSQL40') { $db->query("SET SQL_MODE='MYSQL40'"); } else { if ($sqlcompat == 'MYSQL41') { $db->query("SET SQL_MODE=''"); } } } $sqldump = ''; $tableid = isset($tableid) ? $tableid - 1 : 0; $startfrom = isset($startfrom) ? intval($startfrom) : 0; $tablenumber = count($tables); for ($i = $tableid; $i < $tablenumber && strlen($sqldump) < $sizelimit * 1000; $i++) { $sqldump .= sql_dumptable($tables[$i], $startfrom, strlen($sqldump)); $startfrom = 0; } if (trim($sqldump)) { $sqldump = "# Destoon V" . DT_VERSION . " R" . DT_RELEASE . " http://www.destoon.com\n# " . timetodate($DT_TIME, 6) . "\n# --------------------------------------------------------\n\n\n" . $sqldump; $tableid = $i; $filename = $random . '/' . $fileid . '.sql'; file_put($D . $filename, $sqldump); $fid = $fileid; msg('分卷 <strong>#' . $fileid++ . '</strong> 备份成功.. 程序将自动继续...' . progress(0, $fid, $tid), '?file=' . $file . '&sizelimit=' . $sizelimit . '&sqlcompat=' . $sqlcompat . '&sqlcharset=' . $sqlcharset . '&tableid=' . $tableid . '&fileid=' . $fileid . '&fileid=' . $fileid . '&tid=' . $tid . '&startfrom=' . $startrow . '&random=' . $random . '&backup=1'); } else { cache_delete($_username . '_backup.php'); $db->query("DELETE FROM {$DT_PRE}setting WHERE item='destoon' AND item_key='backtime'"); $db->query("INSERT INTO {$DT_PRE}setting (item,item_key,item_value) VALUES('destoon','backtime','{$DT_TIME}')"); msg('数据库备份成功', '?file=' . $file . '&action=import'); }