📄 backup.class.php
字号:
$to = ($pagesize*($page+1)-$pagesize);
} else {
$from = $pagesize * ($page-1);
$to = ($pagesize*($page+1)-$page *$pagesize);
}
$res = "
<script language=\"JavaScript\" type=\"text/javascript\">
<!--
function IECColor1(el) {
IEC_obj2.IECColor(el);
IEC_obj1.IECColor(el);
}
function IECColor2(el){
IEC_obj1.IECColor(el);
IEC_obj2.IECColor(el);
if(ConfirmDelete()){
return true;
} else {
document.getElementById(el).style.background = IEC_obj1.BG2;
document.forms[\"bform\"].reset();
return false;
}
}
function IECColorClass(BG1, BG2){
this.gvar = 10000;
this.BG1 = BG1;
this.BG2 = BG2;
this.IECColor=IECColor;
}
function IECColor(el) {
document.getElementById(el).style.background = this.BG1;
if(this.gvar < 9000 && this.gvar != el)
document.getElementById(this.gvar).style.background = this.BG2;
this.gvar = el;
}
IEC_obj1 = new IECColorClass('khaki','#F6F6F6');
IEC_obj2 = new IECColorClass('#CF2B5A','#F6F6F6');
//-->
</script>
<form method=get action=\"?\" name=bform><b>".$GONX["selectbackupfile"]." :</b><br/><br/>\n";
if (!is_dir($this->backupdir)) {
@mkdir($this->backupdir,octdec($this->file_mod));
}
$d = dir($this->backupdir);
$i = $BackupSize = 0;
while (false !== ($entry = $d->read())) {
if ($entry!="." and $entry!=".." and (ereg(".bz2$",$entry) or ereg(".gz$",$entry) or ereg(".sql$",$entry))) {
$mtime = date ("Y-m-d(H:i:s)", filemtime($this->backupdir."/".$entry));
$time = filemtime($this->backupdir."/".$entry);
$size = filesize($this->backupdir."/".$entry);
$fsize = round($size/1024);
$GonxBackups[$i]["fname"] = $entry;
$GonxBackups[$i]["mtime"] = $mtime;
$GonxBackups[$i]["time"] = $time;
$GonxBackups[$i]["fsize"] = $fsize;
$GonxBackups[$i]["size"] = $size;
$BackupSize += $fsize;
$i++;
}
}
if ($i==0) {
$res .= "<ul><li>".$GONX["nobckupfile"]."</li></ul>";
} else {
/**
* Pagination
*/
$allpages = round(sizeof($GonxBackups)/$pagesize);
$all_rest = $allpages - $allpages*$pagesize;
if ($all_rest > 0) {$allpages++; }
if ($page<$allpages)
{
$next = "<a href=\"?option=databaseAdmin&go=list&page=".($page+1)."&orderby=$orderby\" class=tab-s>".$GONX["next"]."</a>";
} else $next="";
if ($page>1)
{
$prev = "<a href=\"?option=databaseAdmin&go=list&page=".($page-1)."&orderby=$orderby\" class=tab-s>".$GONX["prev"]."</a>";
} else $prev ="";
$links = "";
for ($i=0; $i<$allpages; $i++)
{
if (($i+1) == $page)
{
$links .= "<span class=tab-s> ".($i+1)." </span>";
} else {
$links .= "<a href=\"?option=databaseAdmin&go=list&page=".($i+1)."&orderby=$orderby\" class=tab-g> ".($i+1)." </a>";
}
}
/**
* Order by
*/
$OrderMenu = "<select class=button OnChange=\"location.href='?option=databaseAdmin&go=list&page=$page&orderby='+ChgOrder.options[selectedIndex].value\" name=\"ChgOrder\" style=\"color: #0000FF; font-family: Arial; font-size: 8pt; background-color: #FFFFCC\">\n";
foreach($GonxOrder as $v){
if ($v==$orderby) {
$sel = " selected";
} else $sel ="";
$OrderMenu .= "<option$sel value=\"$v\">$v</option>\n";
}
$OrderMenu .= "</select>\n";
switch($orderby){
case "Date_Descending":
usort($GonxBackups, array("backup","DateSortDesc"));
break;
case "Date_Ascending":
usort($GonxBackups, array("backup","DateSortAsc"));
break;
case "Name_Descending":
usort($GonxBackups, array("backup","NameSortDesc"));
break;
case "Name_Ascending":
usort($GonxBackups, array("backup","NameSortAsc"));
break;
case "Size_Descending":
usort($GonxBackups, array("backup","SizeSortDesc"));
break;
case "Size_Ascending":
usort($GonxBackups, array("backup","SizeSortAsc"));
break;
default:
usort($GonxBackups, array("backup","DateSortDesc"));
break;
} // switch
if (is_array($GonxBackups)) {
$GonxBackups = array_slice($GonxBackups, $from,$to);
}
$color3 = $this->color3;
$color2 = $this->color2;
$color1 = $this->color1;
$res .= "\n\n<br>
<table width=500 cellpadding=4 style=\"border-collapse: collapse; border: 1px solid #666699; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1\">
\t<tr bgcolor=\"$color1\">
<th></th>
<th align=left width=170><font face=arial size=2>Backed Up Database</font></th>
<th width=70><font face=arial size=2>Date</font></th>
<th><font face=arial size=2>Size</font></th>
<th><font face=arial size=2>Delete</font><th>
</tr>\n";
$bgcolor=$color2;
foreach($GonxBackups as $k=>$v){
$db = explode("-",$v['fname'] );
$db = $db[0];
$res .= "\t<tr id=$k bgcolor=\"$bgcolor\">
<td><input type=\"radio\" name=\"bfile\" value=\"".$v['fname']."\"></td>
<td><font face=Verdana size=1 color=blue><b>".$v['fname']."</b></font></td>
<td align=center><font face=Verdana size=1 color=#006600>".$v['mtime']."</font></td>
<td align=center><font face=Verdana size=1 color=#006600>".$v['fsize']." KB</font></td>
<td align=center><a href=\"?option=databaseAdmin&go=delete&fname=".$v['fname']."\" title=\"".$GONX["delete"]." ".$v['fname']."\" onclick=\"return IECColor2($k);\"><u>Delete</u></a><td>
</tr>\n\n";
if ($bgcolor==$color3) {
$bgcolor = $color2;
} else $bgcolor = $color3;
}
$BackupSize = number_format(($BackupSize/1024),3 );
$res .= "</table><br><br>\n<font face=arial size=2> Sorted by: $OrderMenu
</font><br><br><input type=hidden name=go value=import>
<p align=right>";
if($this->mysqldump)
$res .="<p align=left> <input type=submit name=import value=\"Restore DB\"></p></form><br><br><br><br><br><br>";
}
$d->close();
return $res;
}
/**
* backup::NameSortAsc()
*
* @param $a
* @param $b
* @return
**/
function NameSortAsc($a, $b) {
return strcmp($a["fname"], $b["fname"]);
}
/**
* backup::NameSortDesc()
*
* @param $a
* @param $b
* @return
**/
function NameSortDesc($a, $b) {
return !strcmp($a["fname"], $b["fname"]);
}
/**
* backup::SizeSortAsc()
*
* @param $a
* @param $b
* @return
**/
function SizeSortAsc($a, $b) {
return ($a["size"]>$b["size"])?1:-1;
}
/**
* backup::SizeSortDesc()
*
* @param $a
* @param $b
* @return
**/
function SizeSortDesc($a, $b) {
return ($a["size"]<$b["size"])?1:-1;
}
/**
* backup::DateSortAsc()
*
* @param $a
* @param $b
* @return
**/
function DateSortAsc($a, $b) {
return ($a["time"]>$b["time"])?1:-1;
}
/**
* backup::DateSortDesc()
*
* @param $a
* @param $b
* @return
**/
function DateSortDesc($a, $b) {
return ($a["time"]<$b["time"])?1:-1;
}
/**
* backup::delete() delete a backup file based on its name
*
* @param $_fname
* @return
**/
function delete($_fname){
if (is_file($this->backupdir."/".$_fname)) {
unlink($this->backupdir."/".$_fname);
return "<font color=red> Backup file $_fname is correctly removed </font>";
} else return "<font color=red> Error while removing backup file $_fname</font>";
}
/**
* backup::keep() Keep backup files for a limited period of days and remove all others
*
* @param integer $days
* @return
**/
function keep($days = 4){
if (is_dir($this->backupdir)) {
$d = dir($this->backupdir);
while (false !== ($entry = $d->read())) {
if ($entry!="." and $entry!=".." and (ereg(".bz2$",$entry) or ereg(".gz$",$entry) or ereg(".sql$",$entry))) {
if ((filemtime($this->backupdir."/".$entry)) < (strtotime('-'.$days.' days'))) {
$this->delete($entry);
}
}
}
}
}
/**
* backup::monitor() Return tables status
*
* @return
**/
function monitor(){
$color3 = $this->color3;
$color2 = $this->color2;
$color1 = $this->color1;
$res = "<font face=\"arial\" size=2 color=#000099> This is the area to backup/restore Login Manager V3.0 Database.<br><br>";
$res .= "<b>Backup existing database:</b><br>Click the link \"Create a Backup\", choose either \"backup whole database\" or \"backup selected tables\", click the button \"Backup DB\" to save the result.<br><br>";
$res .= "<b>Restore backed up database:</b><br>Click the link \"List/Import backup\", choose the backed up file you want to restore, then click the button \"Restore DB\".<br><br></font>";
$res .= "<font face=\"arial\" size=2 color=#000099><b>Table Status:</b></font><br><br>";
$res .= "<table cellpadding=4 style=\"border-collapse: collapse; border: 1px solid #666699; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1\">";
$result=mysql_query("SHOW TABLE STATUS");
$i = 0; $bgcolor = $color2; $l1 = $l2 = "";
while ($line=mysql_fetch_array($result,MYSQL_ASSOC)) {
$field=array($line['Name'],$line['Row_format'],$line['Rows'],$line['Data_length'],$line['Create_time'],$line['Update_time']);
$l1 .= "<th><font face=\"arial\" size=2><u>Name</u></font></th><th width=80><font face=\"arial\" size=2><u>Row Format</u></font></th><th><font face=\"arial\" size=2><u>Rows</u></font></th><th width=80><font face=\"arial\" size=2><u>Data Length</u></font></th><th width=80><font face=\"arial\" size=2><u>Create Time</u></font></th><th width=90><font face=\"arial\" size=2><u>Update Time</u></font></th>\n";
$l2 .= "<td align=left><font face=\"Verdana\" size=1 color=#006600> <b>".strtoupper($line['Name'])."</b></font></td><td align=center><font face=\"Verdana\" size=1 color=#006600>".$line['Row_format']."</font></td><td align=center><font face=\"Verdana\" size=1 color=#006600>".$line['Rows']."</font></td><td align=center><font face=\"Verdana\" size=1 color=#006600>".$line['Data_length']."</font></td><td align=center><font face=\"Verdana\" size=1 color=#006600>".$line['Create_time']."</font></td><td align=center><font face=\"Verdana\" size=1 color=#006600>".$line['Update_time']."</font></td>\n";
if ($i==0) {
$res .= "<tr bgcolor=\"$color1\">\n$l1</tr>\n";
}
$res .= "<tr bgcolor=\"$bgcolor\">\n$l2</tr>\n";
if ($bgcolor==$color3) {
$bgcolor = $color2;
} else $bgcolor = $color3;
$l1 = $l2 = "";
$i++;
}
$res .= "</table><br><br><br><br>";
return $res;
}
/**
* backup::getbackup()
*
* @return
**/
function getbackup($bfile){
if (is_file($this->backupdir."/".$bfile) and !ereg("../",$bfile)) {
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".basename($this->backupdir."/".$file));
header("Content-Description: File Transfer");
@readfile($this->backupdir."/".$file);
exit;
}
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -