<!--#include file="conn.asp"-->
<!--#include file=cookies.asp-->
<!--#include file=cookies1.asp-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" type="text/css" href="inc_style.css">
<title>备份数据库</title>
</head>

<body>
<% 
sub updata()
  On Error Resume Next
  Dim FileConnStr,Fileconn
  Dbpath=request.Form("Dbpath")
  Dbpath=server.mappath(Dbpath)
  bkfolder=request.Form("bkfolder")
  bkdbname=request.Form("bkdbname")

  FileConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Dbpath
  Set Fileconn = Server.CreateObject("ADODB.Connection")
  Fileconn.open FileConnStr
  If Err Then
   Response.Write Err.Description
   Err.Clear
   Set Fileconn = Nothing
   Response.Write "<font color=#FF0000><b>备份的文件并非合法的数据库。</b></font>"
   Exit Sub
  Else
   Set Fileconn = Nothing
  End If
  Set Fso=server.createobject("scripting.filesystemobject")
  If Fso.fileexists(dbpath) then
   If CheckDir(bkfolder) = True Then
    Fso.copyfile dbpath,bkfolder& "\"& bkdbname
   else
    MakeNewsDir bkfolder
    Fso.copyfile dbpath,bkfolder& "\"& bkdbname
   end if
   response.write "<font color=#FF0000><b>备份数据库成功，您备份的数据库路径为</b></font>" &bkfolder& "\"& bkdbname
  Else
   response.write "<font color=#FF0000><b>找不到您所需要备份的文件。</b></font>"
  End if
end sub
'------------------检查某一目录是否存在-------------------
Function CheckDir(FolderPath)
 folderpath=Server.MapPath(".")&"\"&folderpath
    Set fso1 = CreateObject("Scripting.FileSystemObject")
    If fso1.FolderExists(FolderPath) then
       '存在
       CheckDir = True
    Else
       '不存在
       CheckDir = False
    End if
    Set fso1 = nothing
End Function
'-------------根据指定名称生成目录-----------------------
Function MakeNewsDir(foldername)
 dim f
    Set fso1 = CreateObject("Scripting.FileSystemObject")
        Set f = fso1.CreateFolder(foldername)
        MakeNewsDir = True
    Set fso1 = nothing
End Function
 %>
 <%
'====================压缩数据库 =========================
sub CompressData()
dim dbpath,boolIs97
dbpath = request("dbpath")
boolIs97 = request("boolIs97")

 If dbpath <> "" Then
 dbpath = server.mappath(dbpath)
  response.write(CompactDB(dbpath,boolIs97))
 End If

end sub

'=====================压缩参数=========================
Function CompactDB(dbPath, boolIs97)
Dim fso, Engine, strDBPath,JET_3X
strDBPath = left(dbPath,instrrev(DBPath,"\"))
Set fso = CreateObject("Scripting.FileSystemObject")

If fso.FileExists(dbPath) Then
 fso.CopyFile dbpath,strDBPath & "temp.mdb"
 Set Engine = CreateObject("JRO.JetEngine")

 If boolIs97 = "True" Then
  Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb", _
  "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp1.mdb;" _
  & "Jet OLEDB:Engine Type=" & JET_3X
 Else
  Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb", _
  "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp1.mdb"
 End If

fso.CopyFile strDBPath & "temp1.mdb",dbpath
fso.DeleteFile(strDBPath & "temp.mdb")
fso.DeleteFile(strDBPath & "temp1.mdb")
Set fso = nothing
Set Engine = nothing

 CompactDB = "<font color=#FF0000><b>你的数据库, " & dbpath & ", 已经压缩成功!</b></font>" & vbCrLf

Else
 CompactDB = "<font color=#FF0000><b>数据库名称或路径不正确. 请重试!</b></font>" & vbCrLf
End If

End Function%>
<% '====================恢复数据库=========================
sub huifua()
   Dbpatha=request.form("Dbpatha")
   backpatha=request.form("backpatha")
   if Dbpatha="" then
   response.write "<font color=#FF0000><b>请输入您要恢复成的数据库全名</b></font>" 
   else
   Dbpatha=server.mappath(Dbpatha)
   end if
   backpatha=server.mappath(backpatha)
   
   Set TestConn = Server.CreateObject("ADODB.Connection")
   On Error Resume Next
   TestConn.open "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Dbpatha
   If Err Then
    Response.Write Err.Description
    Err.Clear
    Set TestConn = Nothing
    Response.Write "<font color=#FF0000><b>备份的文件并非合法的数据库。</b></font>"
    Response.End 
   Else
    Set TestConn = Nothing
   End If
   Set Fso=server.createobject("scripting.filesystemobject")
   if fso.fileexists(Dbpatha) then       
   fso.copyfile Dbpatha,Backpatha
   response.write "<font color=#FF0000><b>成功恢复数据！</b></font>"
   else
   response.write "<font color=#FF0000><b>备份目录下并无您的备份文件！</b></font>" 
End If

end sub %>
<table width="93%" border="1" align="center" cellpadding="3" cellspacing="0" bordercolorlight="#c5cfe0" bordercolordark="#FFFFFF" bgcolor="#C5D5E4"  style="font-size:12px; letter-spacing:1px;">
        <tr align="center" bgcolor="#FFFFFF" height="20"> 
<td align="center" height="29" bgcolor="#C5D5E4">
      <table width="98%"  border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td align="center"><font color="#333333" style="font-size:14px">备 份 数 据 库( 需要FSO支持，FSO相关帮助请看微软网站 )  </font></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF"> <br>
        <table width="98%" border="0" align=center cellpadding="5"  cellspacing="1" bgcolor="#D6DFF7" class="tableBorder">
  <form method="post" action="?action=BackupData">
    <tr>
      <td bgcolor="#FFFFFF" class="forumrow">&nbsp;&nbsp; 当前数据库路径(相对路径)：
          <input type=text size=20 name=DBpath value="../data/data.mdb">
          <BR>
  &nbsp;&nbsp; 备份数据库目录(相对路径)：
          <input type=text size=20 name=bkfolder value="../databak">
  &nbsp;如目录不存在，程序将自动创建<BR>
  &nbsp;&nbsp; 备份数据库名称(填写名称)：
          <input type=text size=20 name=bkDBname value="bak.mdb">
  &nbsp;如备份目录有该文件，将覆盖，如没有，将自动创建<BR>
&nbsp;&nbsp;
        <input type=submit value="备份数据">
<% 
if request("action")="BackupData" then 
 call updata()
end if %>
</td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF" class="forumrow">
		&nbsp;&nbsp;在上面填写本程序的数据库路径全名，本程序的默认数据库文件为Data\data.mdb<font color="#FF0000">（请一定不能用默认名称命名备份数据库）</font><br>
&nbsp;&nbsp;您可以用这个功能来备份您的数据，以保证您的数据安全！<br>
&nbsp;&nbsp;注意：所有路径都是相对与程序空间根目录的相对路径 </td>
    </tr>
  </form>
</table>
        <br>
    </td>
  </tr>
</table>

<br>
<table width="93%" border="1" align="center" cellpadding="3" cellspacing="0" bordercolorlight="#c5cfe0" bordercolordark="#FFFFFF" bgcolor="#C5D5E4"  style="font-size:12px; letter-spacing:1px;">
        <tr align="center" bgcolor="#FFFFFF" height="20"> 
<td align="center" height="29" bgcolor="#C5D5E4">
      <table width="98%"  border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td align="center"><font color="#333333" style="font-size:14px">压 缩 数 据 库( 需要FSO支持，FSO相关帮助请看微软网站 ) </font></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF"> <br>
        <table width="98%" border="0" align=center cellpadding="5"  cellspacing="1" bgcolor="#D6DFF7" class="tableBorder">
<form action="?action=yasuoshuju" method="post">
<tr>
<td bgcolor="#FFFFFF" class="forumrow">压缩数据库：
  <input type="text" name="dbpath" value="../databak/bak.mdb">
&nbsp;
<input type="submit" value="开始压缩">
<%if request("action")="yasuoshuju" then 
 call CompressData()
end if%> 
</td>
</tr>
<tr>
<td bgcolor="#FFFFFF" class="forumrow"><input type="checkbox" name="boolIs97" value="True">如果使用 Access 97 数据库请选择
(默认为 Access 2000 数据库)<br>
<b>注意：</b>输入数据库所在相对路径,并且输入数据库名称<font color="#FF0000">（正在使用中数据库不能压缩，请选择备份数据库进行压缩操作）</font><br></td>
</tr>
</form>
</table>
        <br>
    </td>
  </tr>
</table>
<br>
<table width="93%" border="1" align="center" cellpadding="3" cellspacing="0" bordercolorlight="#c5cfe0" bordercolordark="#FFFFFF" bgcolor="#C5D5E4"  style="font-size:12px; letter-spacing:1px;">
  <tr align="center" bgcolor="#FFFFFF" height="20"> 
<td align="center" height="29" bgcolor="#C5D5E4">
      <table width="98%"  border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td align="center"><font color="#333333" style="font-size:14px">恢 复 数 据 库( 需要FSO支持，FSO相关帮助请看微软网站 ) </font></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td align="center" bgcolor="#FFFFFF"> <br>
        <table width="98%" border="0" align=center cellpadding="5"  cellspacing="1" bgcolor="#D6DFF7" class="tableBorder"  >
          <form method="post" action="?action=huifu">
            <tr>
              <td bgcolor="#FFFFFF" class="forumrow"> &nbsp;&nbsp;备份数据库路径(相对)：
                  <input name=DBpatha type=text id="DBpatha2" value="../databak/bak.mdb" size=30>
&nbsp;&nbsp;<BR>
&nbsp;&nbsp;目标数据库路径(相对)：
        <input name=backpatha type=text id="backpatha2" value="../data/data.mdb" size=30>
        <BR>
&nbsp;&nbsp;填写您当前使用的数据库路径，如不想覆盖当前文件，可自行命名（注意路径是否正确），然后修改conn.asp文件，如果目标文件名和当前使用数据库名一致的话，不需修改conn.asp文件<BR>
&nbsp;&nbsp;
        <input name="submit" type=submit value="恢复数据">
		<%if request("action")="huifu" then 
 call huifua()
end if%>
        </td>
            </tr>
            <tr>
              <td bgcolor="#FFFFFF" class="forumrow">&nbsp;&nbsp;在上面填写本程序的数据库路径全名，本程序的默认备份数据库文件为Databak/bak.mdb，请按照您的备份文件自行修改。<br>
&nbsp;&nbsp;您可以用这个功能来备份您的法规数据，以保证您的数据安全！<br>
&nbsp;&nbsp;注意：所有路径都是相对与程序空间根目录的相对路径 </td>
            </tr>
          </form>
      </table>
    <br>    </td>
  </tr>
</table>
<%
if request("delbak")="ok" then
dim objFSO,bkdbname
bkdbname=trim(request("bkdbname"))
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
if objFSO.fileExists(Server.MapPath("..\databak\"&bkdbname)) then
objFSO.DeleteFile(Server.MapPath("..\databak\"&bkdbname))
end if
response.write"<SCRIPT language=JavaScript>alert('删除备份数据库成功！');</SCRIPT>"
response.write "<meta http-equiv=refresh content=""1;URL=admin_data_backup.asp"">"
response.end
else
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
on error resume next
Set uploadFolder=objFSO.GetFolder(Server.MapPath("..\databak\"))
Set uploadFiles=uploadFolder.Files
filenum=uploadfiles.count
%>

<div align="center">
 
<table width="93%" border="1" align="center" cellpadding="3" cellspacing="0" bordercolorlight="#c5cfe0" bordercolordark="#FFFFFF" bgcolor="#C5D5E4"  style="font-size:12px; letter-spacing:1px;">
        <tr align="center" bgcolor="#FFFFFF" height="20"> 
<td align="center" height="29" bgcolor="#C5D5E4" colspan="5">
<a name="delbakdata"></a><b>删除备份数据库</b></td>
</tr>
<tr>
<td height="25" width="176" bgcolor="#FEEEBC" class="tdbar" bordercolor="#A7D0F5">
<p align="left"><span style="font-weight: 400"><b>&nbsp;文件名称</b></span></td>
<td height="25" width="85" bgcolor="#FEEEBC" class="tdbar" bordercolor="#A7D0F5">
<p align="center">
<span style="font-weight: 400"><b>类型</b></span></td>
<td align=center height="25" width="73" bgcolor="#FEEEBC" class="tdbar" bordercolor="#A7D0F5"> 
<p><span style="font-weight: 400"><b>大小</b></span></td>
<td align=center height="25" width="127" bgcolor="#FEEEBC" class="tdbar" bordercolor="#A7D0F5">
<p align="left"><span style="font-weight: 400"><b>&nbsp;备份时间</b></span></td>
<td align=center height="25" width="31" bgcolor="#FEEEBC" class="tdbar" bordercolor="#A7D0F5">
<p align="left"></td>
</tr>
<%
For Each Upname In uploadFiles
%>
<tr>
<td width="176" height="25" bgcolor="#DBECFB">&nbsp;<%=upname.name%></td>
<td width="85" height="25" bgcolor="#DBECFB"><%if right(upname.name,4)<>".mdb" then%><p align="center"><font color="#FF0000">未知</font><%else%><p align="center">
数据库备份<%end if%></td>
<td width="73" height="25" align=center bgcolor="#DBECFB">
<p><%if upname.size>1024000 then%><%=left(upname.size/(1024*1024),5)%> MB<%else%><%=left(upname.size/1024,5)%>
<font color="#FF0000">KB</font><%end if%></td>
<td width="127" height="25" align=center bgcolor="#DBECFB">
<p align="left">&nbsp;<%=upname.datecreated%></td>
<td width="31" height="25" align=center bgcolor="#DBECFB"><a href="admin_data_backup.asp?bkdbname=<%=upname.name%>&delbak=ok">删除</a></td>
</tr>
<%next%>
</table>
<br>
</div>
<%
set uploadFolder=nothing
set uploadFiles=nothing
end if
%>
</body>
</html>
