首页 热点资讯 义务教育 高等教育 出国留学 考研考公

ASP实现SQL数据库备份 还原!!!

发布网友 发布时间:2022-04-23 09:35

我来回答

1个回答

热心网友 时间:2022-04-27 17:41

<% '=========================数据库处理=============================================
IF Request.form("adminDatabase")<>"" Then
call CheckAdminLogin("数据库管理")
ZD_AdminDatabase=Request.form("adminDatabase")
select case ZD_AdminDatabase
case "Compact"
osMessage=CompactDatabase()
case "backup"
osMessage=BackupDatabase()
case "Restore"
osMessage=RestoreDatabase()
case else
osMessage=GetErrMessage()
End select
End IF
%>

<%
Function updateDatabase()
Dim resultMessage
'On Error Resume Next

updateDatabase = resultMessage

End Function
%>

<%

Function CompactDatabase()
Set Conn=Nothing
Dim FSO,Engine
Set FSO=Server.CreateObject("Scripting.FileSystemObject")
IF FSO.FileExists(Server.Mappath(ZD_DataName)) Then
' Response.Write "<div id=""Layer1"" style=""position:absolute; left:220px; top:153px; width:372px; height:95px; z-index:1"" class=""tdbg3""></div>"
' Response.Write "<div id=""Layer2"" style=""position:absolute; left:222px; top:155px; width:371px; height:93px; z-index:1; overflow: hidden;"" class=""tdbg1"">数据库压缩中....请等待....</div>"
Set Engine = CreateObject("JRO.JetEngine")
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath(ZD_DataName), "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath(ZD_DataName & ".temp")
FSO.CopyFile Server.Mappath(ZD_DataName & ".temp"),Server.Mappath(ZD_DataName)
FSO.DeleteFile(Server.Mappath(ZD_DataName & ".temp"))
Set FSO = Nothing
Set Engine = nothing
CompactDatabase = "<span class=""importantText"">压缩数据库成功!!</span>"
'call SaveLog(Session("member"),"成功操作",now(),"数据库压缩",getIP(),true)
End If
End Function

Function BackupDatabase()
Set Conn=Nothing
Set FSO=Server.CreateObject("Scripting.FileSystemObject")
FSO.CopyFile Server.Mappath(ZD_DataName),Server.Mappath(ZD_DataName & ".bak")
Set FSO = Nothing
BackupDatabase = "<span class=""importantText"">数据库备份成功!!</span>"
'call SaveLog(Session("member"),"操作成功",now(),"数据库备份",getIP(),true)
End Function

Function RestoreDatabase()
Application.Contents.Removeall()
Set Conn=Nothing
Set FSO=Server.CreateObject("Scripting.FileSystemObject")
IF FSO.FileExists(Server.Mappath(ZD_DataName & ".bak")) Then
FSO.CopyFile Server.Mappath(ZD_DataName & ".bak"),Server.Mappath(ZD_DataName)
Set FSO = Nothing
RestoreDatabase = "<span class=""importantText"">数据库恢复成功!!</span>"
'call SaveLog(Session("member"),"操作成功",now(),"数据库恢复",getIP(),true)
Else
Set FSO = Nothing
RestoreDatabase = "<span class=""importantText"">不存在有备份文件!</span>"
'call SaveLog(Session("member"),"操作失败",now(),"数据库恢复",getIP(),false)
End IF
End Function

%>

大体是这样您修改下吧。

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com