$message_bool = true; } else { $message = '无法还原系统,可能是该备份文件损坏了!'; $message_bool = false; } //开启平台 $oaconfig->save('WEB_ON', '1'); } /** * 删除备份 * @since 1 */ if (isset($_GET['del']) == true) { $backup_filename = $backup_dir . DS . (int) substr($_GET['del'], 0, -4) . '.zip'; if (corefile::is_file($backup_filename) == true) { if (corefile::delete_file($backup_filename) == true) { $message = '删除成功!'; $message_bool = true; } } if (!$message) { $message = '无法删除该备份文件!'; $message_bool = false; } } /** * 获取备份文件列表 * @since 1 */ $table_list = corefile::list_dir($backup_dir, '*.zip'); /**
$message_bool = false; } } /** * 删除文件 * @since 1 */ if (isset($_GET['del']) == true) { $del_view = $oapost->view($_GET['del']); if ($del_view) { $del_view_list = $oapost->view_list_row(null, null, null, null, $post_type, $del_view['post_parent']); if ($del_view_list < 2) { $del_parent = $oapost->view($del_view['post_parent']); if ($del_parent) { if ($oapost->del($del_parent['id']) == true) { if (!corefile::delete_file($del_parent['post_url'])) { $message = '无法删除该文件。'; $message_bool = false; } } else { $message = '无法删除该文件。'; $message_bool = false; } } } //删除引用ID if ($oapost->del($_GET['del']) == true && $message == '') { $message = '删除成功。'; $message_bool = true; } else { $message = '无法删除该文件。';
/** * 生成新的备份文件 * @since 2 * @param coredb $db 数据库操作句柄 * @param string $backup_dir 备份到目录 * @param string $content_dir 文件数据目录 * @return string 备份文件路径 */ function plugbackup(&$db, $backup_dir, $content_dir) { $return = ''; $bool = false; $file_type = 'zip'; $ls_dir = $backup_dir . DS . substr(sha1(rand(1, 99999)), 0, 8); if (!corefile::is_dir($ls_dir)) { $ls_sql_dir = $ls_dir . DS . 'sql'; //创建临时目录 $bool = corefile::new_dir($ls_dir); //创建临时SQL目录 if ($bool == true) { $bool = corefile::new_dir($ls_sql_dir); } //拷贝文件数据 if ($bool == true) { $bool = corefile::copy_dir($content_dir . DS . 'files', $ls_dir . DS . 'content' . DS . 'files'); } if ($bool == true) { $bool = corefile::copy_dir($content_dir . DS . 'logs', $ls_dir . DS . 'content' . DS . 'logs'); } //依次遍历所有数据并拷贝到文件内 foreach ($db->tables as $k => $v) { //创建表目录 $v_table_dir = $ls_sql_dir . DS . $v; if ($bool == true) { $bool = corefile::new_dir($v_table_dir); } else { break; } //计算表内所有字段数据平均长度,得出最终步长 $max = 50; if ($bool == true) { $sql = 'SELECT AVG( LENGTH(`' . implode('`))+AVG(LENGTH(`', $db->fields[$k]) . '`)) as al FROM `' . $v . '`'; $sth = $db->prepare($sql); if ($sth->execute() == true) { $res = (int) $sth->fetchColumn(); if ($res > 500) { $max = 20; } elseif ($res > 1000) { $max = 10; } elseif ($res > 5000) { $max = 1; } } else { $bool = false; break; } } else { break; } //遍历数据写入文件 $p = 0; $p_bool = true; while ($p_bool) { $sql = 'SELECT * FROM `' . $v . '` ORDER BY ' . $db->fields[$k][0] . ' ASC LIMIT ' . $p * $max . ',' . $max; $sth = $db->prepare($sql); if ($sth->execute() == true) { $res = $sth->fetchAll(PDO::FETCH_ASSOC); if ($res) { $file_content = 'INSERT INTO `' . $v . '`(`' . implode('`,`', array_keys($res[0])) . '`) VALUES'; foreach ($res as $v_res) { $file_content .= '('; foreach ($v_res as $v_res_v) { if ($v_res_v == null) { $file_content .= 'NULL,'; } elseif (is_int($v_res_v) == true) { $file_content .= $v_res_v . ','; } else { $file_content .= '\'' . $v_res_v . '\','; } } $file_content = substr($file_content, 0, -1); $file_content .= '),'; } $file_content = substr($file_content, 0, -1) . ';'; $file_table_row = $v_table_dir . DS . $v . '_' . $p . '.sql'; $p_bool = corefile::edit_file($file_table_row, $file_content); $bool = $p_bool; $file_content = null; } else { $p_bool = false; $bool = true; } } else { $p_bool = false; $bool = false; } $p += 1; } } } //将临时文件压缩为压缩包 $backup_file = $backup_dir . DS . time() . '.' . $file_type; if (corefile::is_file($backup_file)) { $bool = corefile::delete_file($backup_file); } if ($bool == true) { $bool = corefile::create_zip($backup_file, $ls_dir); } if ($bool == true) { $return = $backup_file; } else { //失败删除所有临时文件 corefile::delete_file($backup_file); } //删除临时文件 corefile::delete_dir($ls_dir); return $return; }