bsp; }
}
if (!$fp = fopen($filename, 'ab'))
{
return $this->error('无法写入数据,请设置当前文件夹属性为可写,UNIX主机设置为777.Unable to write to backup file. Please CHMod the current directory so it is writable');
}
fwrite($fp,$dump);
fclose($fp);
if ($timedout)
{
$data = base64_encode(serialize($data));
$url = 'back.php?act=do_backup&file='.urlencode($filename).'&data='.$data;
$this->meta = '<meta http-equiv="refresh" content="1; url='.$url.'" />';
$this->output = <<<HTML
<table align="center" class="tablewrap" cellpadding="0" cellspacing="3" width="350">
<tr>
<td align="center" class="title">备份中...</td>
</tr>
<tr>
<td>
<table class="table1" align="center" width="100%">
<tr>
<td class="tdrow2">
<div align="center">数据正在备份<br /><br /><a href="$url">如果你想终止备份请点这里</a></div>
</td>
</tr>
</table>
</td>
</tr>
</table>
HTML;
}
else
{
$this->output = <<<HTML
<table align="center" class="tablewrap" cellpadding="0" cellspacing="3" width="350">
<tr>
<td align="center" class="title">备份完成</td>
</tr>
<tr>
<td>
<table class="table1" align="center" width="100%">
<tr>
<td class="tdrow2">
数据备份已经完成,文件保存为:"$filename".<br /><br />
<a href="$filename">点击这里下载备份文件</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
HTML;
}
}
function backup_table($table,$start) {
$dump = '';
if (!$start)
{
$result = mysql_query('SHOW CREATE TABLE '.$table);
$row = mysql_fetch_assoc($result);
$dump .= "nn--n";
$dump .= "-- Table structure for table '$table'n";
$dump .= "--nn";
$dump .= str_replace( "`", "", $row['Create Table'] );
$dump .= ";nn";
$dump .= "nn--n";
$dump .= "-- Dumping data for table '$table'n";
$dump .= "--nn";
}
//
// Records
//
$done = $start;
$result = mysql_query('SELECT * FROM '.$table.' LIMIT '.$start.',-1');
while ($row = mysql_fetch_row($result))
{
if ($this->timeout())
{
return array($dump,$done);
}
$done++;
foreach ($row as $id => $value)
{
$value = str_replace('"','\"',$value);
$row[$id] = '"'.$value.'"';
}
$dump .= 'INSERT INTO ' . $table . ' VALUES (' . implode(',',$row) . ");n";
}
return $dump;
}
function main() {
if (!$this->link)
{
if (!$this->read_db_details())
{
return $this->set_database();
}
if ($error_text = $this->connect(1))
{
return $this->set_database($error_text);
}
}
$tables_to_backup = '';
if ($this->db['prefix'])
{
$tables_to_backup .= '<input type="radio" name="tables" value="prefix" checked="checked" />IPB Tables Only <br />';
$tables_to_backup .= '<input type="radio" name="tables" value="all" />All<br />';
}
else
{
$tables_to_backup .= '<input type="radio" name="tables" value="all" checked="checked" />全部数据 / All<br />';
}
$tables = mysql_list_tables($this->db['name']);
$options = '';
while (list($table_name) = mysql_fetch_array($tables))
{
$options .= '<option value="'.$table_name.'">'.$table_name.'</option>';
}
$tables_to_backup .= <<<HTML
<input type="radio" name="tables" value="selected" />选择数据表 / Selected tables:<br />
<div style="margin-left: 40px">
<select name="table_select[]" class="textbox" size="5" style="width: 250px" multiple="multiple">
$options
</select>
</div>
HTML;
$options = '';
if ($dir = @opendir('./'))
{
while ($file = readdir($dir))
{
$temp = strtolower($file);
if ($file != '.' && $file != '..' && strpos($temp, '.sql'))
{
$options .= '<option value="'.$file.'">'.$file.'</option>';
}
}
closedir($dir);
}
$restore_files = '<select name="filename" class="textbox">'.$options.'</select>';
$restore_files .= '<br><br>或地址:<input type="text" name="relfilename" class="textbox" />';
$this->output = <<<HTML
<form method="post" action="back.php?act=login">
<table align="center" class="tablewrap" cellpadding="0" cellspacing="3" width="450">
<tr>
<td align="center" class="title">目前连接数据库信息</td>
</tr>
<tr>
<td>
<table class="table1" align="center" width="100%">
<tr>
<td width="150" class="tdrow1"><strong>主机 / 端口:</strong></td>
<td width="300" class="tdrow2">{$this->db['host']}:{$this->db['port']}</td>
</tr>
<tr>
<td class="tdrow1"><strong>数据库名:</strong></td>
<td class="tdrow2">{$this->db['name']}</td>
</tr>
<tr>
<td class="tdrow1"><strong>用户名:</strong></td>
<td class="tdrow2">{$this->db['user']}</td>
</tr>
<tr>
<td class="tdrow2" colspan="2"><div align="center">[ <a href="back.php?act=change_db">变更当前连接的数据库</a> ]</div></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<br>
<form method="post" action="back.php?act=backup">
<table align="center" class="tablewrap" cellpadding="0" cellspacing="3" width="450">
<tr>
<td align="center" class="title">备份设置/Backup Options</td>
</tr>
<tr>
<td>
<table class="table1" align="center" width="100%">
<tr>
<td width="150" class="tdrow1" valign="top"><strong>数据备份:<br>Tables to backup:</strong></td>
<td width="300" class="tdrow2">$tables_to_backup</td>