数据库备份系统
数据库备份系统
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>数据库管理</title>
</head>
<body>
<div align=center>数据库管理系统</div>
<br>
<br>
<p align="center">
<%
Dim ZC_DATABASE_PATH
'数据库的路径
ZC_DATABASE_PATH="database/data.mdb"
data_array= Split(ZC_DATABASE_PATH,"/")
Dim action
action=trim(request("action"))
Dim dbpath,bkfolder,bkdbname,fso,fso1
Select Case action
Case ""
Call chushihua()
Case "CompressData" '压缩数据
Dim tmprs
dim allarticle
dim Maxid
dim topic,username,dateandtime,body
call CompressData()
case "BackupData" '备份数据
if request("act")="Backup" Then
call updata()
else
call BackupData()
end If
case "RestoreData" '恢复数据
dim backpath
if request("act")="Restore" Then
Dbpath=request.form("Dbpath")
backpath=request.form("backpath")
if dbpath="" Then
response.write "Please input your database whole Name"
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 "数据库被成功还原!<br>"
else
response.write "没找到您所需要的数据库!"
end If
else
call RestoreData()
end If
Case "SpaceSize" '系统空间占用
call SpaceSize()
Case "deletebackup"
Dim dbname
dbpath=Request.QueryString("dbpath")
dbname=Request.QueryString("dbname")
dbpath=Server.MapPath(dbpath)
dbpath=dbpath &"\"&dbname
set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(dbPath) Then
fso.DeleteFile(DBPath)
Set fso = nothing
response.write "<br>您备份的数据库已经" & dbpath &"被成功删除!<br><br><a href=""data_s.asp"">返回..</a>"
Else
response.write dbpath
response.write "<br>输入的路径错误,请确认后重新输入!<br><br><a href=""data_s.asp"">返回..</a>"
End If
Case Else
End Select
%>
</div>
<%
response.write"</body></html>"
Sub chushihua()
%>
<div align=center>
<form id="edit">
<a href="?action=CompressData">[压缩数据库]</a>
<a href="?action=BackupData">[备份数据库]</a>
<a href="?action=RestoreData">[还原数据库]</a>
<a href="?action=SpaceSize">[系统空间占用]</a>
</form>
</div>
<%end sub%>
<%
'====================系统空间占用=======================
Sub SpaceSize()
On Error Resume Next
%>
<div align=center>
<div align=center>
系统空间查看
<form id="edit">
<br>
数据库:<%showSpaceinfo("../"&data_array(1)&"")%><br><br>
备份数据库:<%showSpaceinfo("databackup")%><br><br>
系统总共:<%showSpaceinfo("/")%>
<br><br>
</form>
</div>
<br >
<br >
<br >
<a href="data_s.asp">返回...</a>
</div>
<%
End Sub
%>
<% Sub ShowSpaceInfo(drvpath)
dim fso,d,size,showsize
set fso=server.CreateObject("scripting.filesystemobject")
drvpath=server.mappath(drvpath)
set d=fso.getfolder(drvpath)
size=d.size
showsize=size & " Byte"
if size>1024 Then
size=(Size/1024)
showsize=size & " KB"
end If
if size>1024 Then
size=(size/1024)
showsize=formatnumber(size,2) & " MB"
end If
if size>1024 Then
size=(size/1024)
showsize=formatnumber(size,2) & " GB"
end If
response.write "<font face=verdana>" & showsize & "</font>"
End Sub
%>
<%
Sub RestoreData()
%>
<div align=center>
<div align=center>
还原数据库:
<form id="edit" method="post" action="data_s.asp?action=RestoreData&act=Restore">
还原的路径(相对路径):<input type=text size=30 name=DBpath value="DataBackup\<%=Date()%>_Bak.mdb"><BR>
还原后的路径(相对路径):<input type=text size=30 name=backpath value="<%=ZC_DATABASE_PATH%>"><BR><BR>
<input type=submit value="开始还原">
</form>
</div>
<br>
<br>
<a href="data_s.asp">返回...</a>
</div>
<%
End Sub
Sub updata()
Dbpath=request.form("Dbpath")
Dbpath=server.mappath(Dbpath)
bkfolder=request.form("bkfolder")
bkdbname=request.form("bkdbname")
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 "<br>已经成功备份,你的数据库的路径:" &bkfolder& "\"& bkdbname
response.write "<br><br>点击此处将数据库下载下来:<a href="""& ZC_BLOG_HOST & request.form("bkfolder") & "/" & bkdbname &""">" & ZC_BLOG_HOST & request.form("bkfolder") & "/" & bkdbname &"<br><br>"
response.write "<br><br><a href=""data_s.asp?action=deletebackup&dbpath="&request.form("bkfolder") &"&dbname=" & bkdbname &""">当您下载完毕后,点击此处将删除备份的数据库!</a><br><br><br><a href=""Data_s.asp"">返回...</a>"
Else
response.write "Error ,,找不到文件!<br>"
End If
Set fso = nothing
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 BackupData()
%>
<div align=center>
备份数据库
<form id="edit" method="post" action="data_s.asp?action=BackupData&act=Backup">
当前数据库的路径(相对路径):<input type=text size=15 name=DBpath value="<%=ZC_DATABASE_PATH%>">
备份数据库的路径(相对路径):<input type=text size=15 name=bkfolder value="Databackup">
如果该目录不存在,系统将自动建立
备份后数据库的名称:<input type=text size=20 name=bkDBname value="<%=Date()%>_bak.mdb"> 按日期自动命名
如果备份文件不存在将建立,如果存在,将自动覆盖!
<input type=submit value="开始备份"><br>
</form>
<br><br>
<a href="data_s.asp">返回..</a>
</div>
<%
End Sub
Sub CompressData()
%>
<div align=center>
压缩数据库:
<form id="edit" action="data_s.asp?action=CompressData" method="post">
输入数据库的所在路径
压缩数据库的路径:<input type="text" name="dbpath" value="<%=ZC_DATABASE_PATH%>">
<input type="submit" value="开始压缩">
<input type="checkbox" name="boolIs97" value="True">如果是ac97,请将钩打上.(默认是Access 2000)<br><br>
</form>
<br><br>
<a href="data_s.asp">返回..</a>
</div>
<%
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 = "您的数据库" & dbpath & "已经被成功压缩!" & vbCrLf
Else
CompactDB = "<br>您输入的路径错误,请确认后重新输入!" & vbCrLf
End If
End Function
'////////////////////end////////////////////////
%>
</p>
</body>
</html>
补充:asp教程,安全加密