📄 data.asp
字号:
<%if session("china_admin")="" then
response.redirect "login.asp"
end if
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" type="text/css" href="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="98%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#799AE1">
<tr>
<td height="20" bgcolor="#799AE1" align="center">
<table width="98%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center"><font color="#FFFFFF" 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"> 当前数据库路径(相对路径):
<input type=text size=20 name=DBpath value="../data/#data.asp">
<BR>
备份数据库目录(相对路径):
<input type=text size=20 name=bkfolder value="../databak">
如目录不存在,程序将自动创建<BR>
备份数据库名称(填写名称):
<input type=text size=20 name=bkDBname value="bak.mdb">
如备份目录有该文件,将覆盖,如没有,将自动创建<BR>
<input type=submit value="备份数据">
<%
if request("action")="BackupData" then
call updata()
end if %>
</td>
</tr>
<tr>
<td bgcolor="#FFFFFF" class="forumrow"> 在上面填写本程序的数据库路径全名,本程序的默认数据库文件为Data\#data.asp<font color="#FF0000">(请一定不能用默认名称命名备份数据库)</font><br>
您可以用这个功能来备份您的数据,以保证您的数据安全!<br>
注意:所有路径都是相对与程序空间根目录的相对路径 </td>
</tr>
</form>
</table>
<br>
</td>
</tr>
</table>
<br>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#799AE1">
<tr>
<td height="20" bgcolor="#799AE1" align="center">
<table width="98%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center"><font color="#FFFFFF" 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">
<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="98%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#799AE1">
<tr>
<td height="20" bgcolor="#799AE1" align="center">
<table width="98%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center"><font color="#FFFFFF" 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"> 备份数据库路径(相对):
<input name=DBpatha type=text id="DBpatha2" value="../databak/bak.mdb" size=30>
<BR>
目标数据库路径(相对):
<input name=backpatha type=text id="backpatha2" value="../data/#data.asp" size=30>
<BR>
填写您当前使用的数据库路径,如不想覆盖当前文件,可自行命名(注意路径是否正确),然后修改conn.asp文件,如果目标文件名和当前使用数据库名一致的话,不需修改conn.asp文件<BR>
<input name="submit" type=submit value="恢复数据">
<%if request("action")="huifu" then
call huifua()
end if%>
</td>
</tr>
<tr>
<td bgcolor="#FFFFFF" class="forumrow"> 在上面填写本程序的数据库路径全名,本程序的默认备份数据库文件为Databak/bak.mdb,请按照您的备份文件自行修改。<br>
您可以用这个功能来备份您的法规数据,以保证您的数据安全!<br>
注意:所有路径都是相对与程序空间根目录的相对路径 </td>
</tr>
</form>
</table>
<br> </td>
</tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -