<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file = "tuzh_pri.asp"-->
<!--#include file ="../connadmin.asp"-->
<!--#include file ="../setup.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" type="text/css" href="../img/css.css">
<title><%=Site_Name%></title>
</head>

<body>
<table class="border" width="98%" border="0" align="center" cellpadding="1" cellspacing="0">
  <tr> 
    <td height="447" align="center" valign="top" class="bg_low"> <table width="100%" height="25" border="0" cellpadding="0" cellspacing="0">
        <tr> 
          <td align="center" valign="middle" class="bgtop"><font color="#FFFFFF"><b>数据库操作</b></font> 
          </td>
        </tr>
      </table>
      <table width="99%" border="1" align="center" cellpadding="6" cellspacing="1" bordercolor="#ABCEDD">
        <tr> 
          <td>数据库文件路径：<%=Request.ServerVariables("APPL_PHYSICAL_PATH")&defi_pathdata%></td>
        </tr>
        <tr> 
          <td>数据库文件空间占用：<%=GetTotalSize(Server.Mappath(mydata_path),"File")%></td>
        </tr>
        <tr> 
          <td> </td>
        </tr>
        <tr> 
          <td>数据库文件操作：<b>&nbsp;<a class="xiahua" href="admincp.asp?type=Compact">压缩</a></b>(压缩前最好备份一次)&nbsp;&nbsp;|&nbsp;&nbsp;<b><a class="xiahua" href="admincp.asp?type=Backup">备份</a></b>(强烈推荐每日备份一次)</td>
        </tr>
        <tr> 
          <td height="69" style="padding-left:18px;">&nbsp;</td>
        </tr>
        <tr> 
          <td style="padding-left:18px;"> 
<%
IF Request.QueryString("type")="Compact" Then
	Dim FSO,Engine
	Set FSO=Server.CreateObject("Scripting.FileSystemObject")
	IF Err<>0 Then
		Err.Clear
		Response.Write("服务器关闭FSO，无法压缩数据库")
	Else
		If FSO.FileExists(Server.Mappath(mydata_path)) Then
			Response.Write "压缩数据库开始，网站暂停一切用户的前台操作......<br>"
			Conn.Close
			Set Conn=Nothing
			Set Engine = CreateObject("JRO.JetEngine")
			Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(mydata_path), "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath(mydata_path&".temp")
			FSO.CopyFile Server.Mappath(mydata_path&".temp"),Server.Mappath(mydata_path)
			FSO.DeleteFile(Server.Mappath(mydata_path&".temp"))
			Set FSO = Nothing
			Set Engine = Nothing
			Response.write "压缩数据库完成..."
			Response.Write "<br>网站恢复正常访问..."
			Response.Write("<br><a class='xiahua' href=""admincp.asp"">请点击返回</a>")
		End IF
	End If
	Set FSO=Nothing
ElseIF Request.QueryString("type")="Backup" Then
	Response.Write "备份数据库开始，网站暂停一切用户的前台操作......<br>"
	Conn.Close
	Set Conn=Nothing
	CopyFiles Server.Mappath(mydata_path),Server.Mappath(mydata_path & "_" & DateToStr(Now(),"YmdHIS") &".BAK")
	Response.write "<br>备份完成..."
	Response.write "<br>网站恢复正常访问..."
	Response.Write("<br><a class='xiahua' href=""admincp.asp"">请点击返回</a>")
ElseIF Request.QueryString("type")="Restore" Then
			'Dbpath=request.form("Dbpath")
			backpath=mydata_path
			Dbpath=beifen_path & Get_path(request.QueryString("filename"))
			'if dbpath="" then
			'response.write "请输入您要恢复成的数据库全名"	
			'else
			Dbpath=server.mappath(Dbpath)
			'end if
			backpath=server.mappath(backpath)
		
			Set Fso=server.createobject("scripting.filesystemobject")
			if fso.fileexists(dbpath) then  					
			fso.copyfile Dbpath,Backpath
			response.write "成功恢复数据！"
			else
			response.write "备份目录下并无您的备份文件！"	
			end if
ElseIF Request.QueryString("type")="DeleFile" Then
	IF Request.QueryString("filename")=Empty Then
		Response.Write("<a class='xiahua' href=""admincp.asp?action=database"">要删除的文件名不能为空，请点击返回</a>")
	Else
		IF DeleteFiles(Server.MapPath(beifen_path&get_path(Request.QueryString("filename"))))=1 Then
			Response.Write("<a class='xiahua' href=""admincp.asp"">文件删除成功，请点击返回</a>")
		Else
			Response.Write("<a class='xiahua' href=""admincp.asp"">文件删除失败，请点击返回</a>")
		End IF
	End IF
Else
	Response.Write("<b>备份文件列表</b><br>")
	Dim DataFolder,DataFileList,DataFile,DataFileName
	Set FSO=Server.CreateObject("Scripting.FileSystemObject")
	IF Err<>0 Then
		Err.Clear
		Response.Write("服务器关闭FSO，无法查看备份文件列表")
	Else
		Set DataFolder=FSO.GetFolder(Server.MapPath(data_folder))
		Set DataFileList=DataFolder.Files
		For Each DataFile IN DataFileList
			IF Ubound(Split(DataFile,"."))>=2 and right(DataFile,3)="BAK" Then
				DataFileName=DataFile.Name
				Response.Write("<font color=""#FF0000"">"&DataFileName&"</font>&nbsp;&nbsp;|&nbsp;&nbsp;<b><a class='xiahua' href='"&beifen_path&DataFileName&"'>下载此文件</a></b>&nbsp;&nbsp;|&nbsp;&nbsp;<b><a class='xiahua' href=""admincp.asp?type=DeleFile&filename="&DataFileName&""">删除此文件</a></b>&nbsp;&nbsp;|&nbsp;&nbsp;<b><a class='xiahua' href=""admincp.asp?type=Restore&filename="&DataFileName&""">从此文件还原数据</a></b><br>")
			End IF
		Next
	End IF
	Set FSO=Nothing
End If

Function CopyFiles(TempSource,TempEnd)
    Dim FSO
    Set FSO = Server.CreateObject("Scripting.FileSystemObject")
	IF Err<>0 Then
		Err.Clear
		Response.Write("服务器关闭FSO，无法复制文件")
	Else
		If FSO.FileExists(TempEnd) then
		   Response.Write "目标备份文件 <b>" & TempEnd & "</b> 已存在，请先删除!"
		   Set FSO=Nothing
		   Exit Function
		End IF
		IF FSO.FileExists(TempSource) Then
		Else
		   Response.Write "要复制的源数据库文件 <b>"&TempSource&"</b> 不存在!"
		   Set FSO=Nothing
		   Exit Function
		End If
		FSO.CopyFile TempSource,TempEnd
		Response.Write "已经成功复制文件 <b>"&TempSource&"</b> 到 <b>"&TempEnd&"</b>"
	End If
    Set FSO = Nothing
End Function
Function GetTotalSize(GetLocal,GetType)
	Dim FSO
	Set FSO=Server.CreateObject("Scripting.FileSystemObject")
	IF Err<>0 Then
		Err.Clear
		GetTotalSize="服务器关闭FSO，查看占用空间失败"
	Else
		Dim SiteFolder
		IF GetType="Folder" Then
			Set SiteFolder=FSO.GetFolder(GetLocal) 
		Else
			Set SiteFolder=FSO.GetFile(GetLocal) 
		End IF
		GetTotalSize=SiteFolder.Size
		IF GetTotalSize>1024*1024 Then
		GetTotalSize=GetTotalSize/1024/1024
		IF inStr(GetTotalSize,".") Then GetTotalSize = Left(GetTotalSize,inStr(GetTotalSize,".")+2)
			GetTotalSize=GetTotalSize&" MB"
		Else
			GetTotalSize=Fix(GetTotalSize/1024)&" KB"
		End IF
		Set SiteFolder=Nothing
	End IF
	Set FSO=Nothing
End Function
Function DateToStr(DateTime,ShowType)  '日期转换函数
	Dim DateMonth,DateDay,DateHour,DateMinute
	DateMonth=Month(DateTime)
	DateDay=Day(DateTime)
	DateHour=Hour(DateTime)
	DateMinute=Minute(DateTime)
	If Len(DateMonth)<2 Then DateMonth="0"&DateMonth
	If Len(DateDay)<2 Then DateDay="0"&DateDay
	Select Case ShowType
	Case "Y-m-d"  
		DateToStr=Year(DateTime)&"-"&DateMonth&"-"&DateDay
	Case "Y-m-d H:I A"
		Dim DateAMPM
		If DateHour>12 Then 
			DateHour=DateHour-12
			DateAMPM="PM"
		Else
			DateHour=DateHour
			DateAMPM="AM"
		End If
		If Len(DateHour)<2 Then DateHour="0"&DateHour	
		If Len(DateMinute)<2 Then DateMinute="0"&DateMinute
		DateToStr=Year(DateTime)&"-"&DateMonth&"-"&DateDay&" "&DateHour&":"&DateMinute&" "&DateAMPM
	Case "Y-m-d H:I:S"
		Dim DateSecond
		DateSecond=Second(DateTime)
		If Len(DateHour)<2 Then DateHour="0"&DateHour	
		If Len(DateMinute)<2 Then DateMinute="0"&DateMinute
		If Len(DateSecond)<2 Then DateSecond="0"&DateSecond
		DateToStr=Year(DateTime)&"-"&DateMonth&"-"&DateDay&" "&DateHour&":"&DateMinute&":"&DateSecond
	Case "YmdHIS"
		DateSecond=Second(DateTime)
		If Len(DateHour)<2 Then DateHour="0"&DateHour	
		If Len(DateMinute)<2 Then DateMinute="0"&DateMinute
		If Len(DateSecond)<2 Then DateSecond="0"&DateSecond
		DateToStr=Year(DateTime)&DateMonth&DateDay&DateHour&DateMinute&DateSecond	
	Case "ym"
		DateToStr=Right(Year(DateTime),2)&DateMonth
	Case "d"
		DateToStr=DateDay
	Case Else
		If Len(DateHour)<2 Then DateHour="0"&DateHour
		If Len(DateMinute)<2 Then DateMinute="0"&DateMinute
		DateToStr=Year(DateTime)&"-"&DateMonth&"-"&DateDay&" "&DateHour&":"&DateMinute
	End Select
End Function
Function DeleteFiles(FilePath)
    Dim FSO
    Set FSO=Server.CreateObject("Scripting.FileSystemObject")
	IF Err<>0 Then
		Err.Clear
		Response.Write("服务器关闭FSO，无法删除文件")
	Else
		If FSO.FileExists(FilePath) Then
			FSO.DeleteFile FilePath,True
			DeleteFiles = 1
		Else
			DeleteFiles = 0
		End If
	End If
    Set FSO = Nothing
End Function
%>
          </td>
        </tr>
      </table> </td>
  </tr>
</table>
</body>
</html>
