当前位置:首页 » 参考文献 » asp备份数据库

asp备份数据库

发布时间: 2021-03-24 09:58:48

A. 急~~~ASP备份和恢复SQL数据库的操作方法

首先,你要这样来备份数据库:

SQL="backup database 数据库名 to disk='"&Server.MapPath("backup")&"\"&"backuptext.dat"&"' with INIT"

这样你的备份将覆盖原来的同名备份(如果有的话),否则备份将附加在原来的备份上,不仅文件越来越大,日后还原时还会发生各种问题。

其次,数据库在有用户连接时是不能恢复的。

所以你要备份的话,不能链接到你的数据库,要链接到master数据库,使用:

cnn.open "driver={SQL Server};Server=服务器名;uid=sa;pwd=;database=master"

再次,仅仅你不链接到数据库,但不能保证没有别人链接数据库,所以还要断开所有用户到数据库的连接,才能开始还原。可以使用下列语句来进行:

declare backup_cursor cursor global for select 'kill '+rtrim(spid) from master.dbo.sysprocesses where dbid=db_id('数据库名') exec sp_msforeach_worker '?'

所以,你的程序要改成这样:

1、备份
<%
SQL="backup database 数据库名 to disk='"&Server.MapPath("backup")&"\"&"backuptext.dat"&"' with INIT"
set cnn=Server.createobject("adodb.connection")
cnn.open "driver={SQL Server};Server=服务器名;uid=sa;pwd="
cnn.execute SQL
on error resume next
if err<>0 then
response.write "错误:"&err.Descripting
else
response.write "数据备份成功!"
end if
cnn.close
set cnn=nothing
%>

2、恢复
<%
aSQL="declare backup_cursor cursor global for select 'kill '+rtrim(spid) from master.dbo.sysprocesses where dbid=db_id('数据库名') exec sp_msforeach_worker '?'"

bSQL="Restore database 数据库名 from disk='"&Server.MapPath("backup")&"\"&"backuptext.dat"&"'"

set cnn=Server.createobject("adodb.connection")
cnn.open "driver={SQL Server};Server=服务器名;uid=sa;pwd=;database=master"
cnn.execute aSQL
cnn.execute bSQL
on error resume next
if err<>0 then
response.write "错误:"&err.Descripting
else
response.write "数据恢复成功!"
end if
cnn.close
set cnn=nothing
%>

B. ASP中怎么实现SQL数据库备份,恢复

1、备份
<%
SQL="backup database 数据库名 to disk='"&Server.MapPath("backup")&"\"&"backuptext.dat"&"'"
set cnn=Server.createobject("adodb.connection")
cnn.open "driver={SQL Server};Server=服务器名;uid=sa;pwd="
cnn.execute SQL
on error resume next
if err<>0 then
response.write "错误:"&err.Descripting
else
response.write "数据备份成功!"
end if
%>

2、恢复
<%
SQL="Restore database 数据库名 from disk='"&Server.MapPath("backup")&"\"&"backuptext.dat"&"'"
set cnn=Server.createobject("adodb.connection")
cnn.open "driver={SQL Server};Server=服务器名;uid=sa;pwd="
cnn.execute SQL
on error resume next
if err<>0 then
response.write "错误:"&err.Descripting
else
response.write "数据恢复成功!"
end if
%>

注:以上语句是把数据备份到磁盘的backup目录下,文件名为backuptext.dat。

C. 如何用asp代码实现数据备份和恢复

<form name="form1" method="post" action="?action=bf">
<table width="90%" border="0" align=center cellpadding="5" cellspacing="1" bgcolor="#336699" class="tableBorder">
<tr>
<th width="593" height=25 bgcolor="#FFFFFF" > <B>备份数据</B>( 需要FSO支持,FSO相关帮助请看微软网站 ) </th>
</tr>
<tr>
<td height=100 bgcolor="#FFFFFF" class="forumrow">
<span class="STYLE1">
<%
if request.QueryString("action")="bf" then
Dbpath=request.form("Dbpath")
backpath=request.form("backpath")&".mdb"
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.file Dbpath,Backpath
response.write "数据备份成功!"
else
response.write "数据库地址不存在,请检查CONN.ASP中的DB=这一项是否是绝对地址!"
end if
end if%>
</span> <div align="center">
<p>备份数据库路径(相对):
<input name=backpath type=text id="backpath" value="bak\jester_bak" size=30>
<br>
目标数据库路径(相对):
<input name=DBpath type=text id="DBpath" value="<%=db%>" size=30>
<BR>
<BR>

<input name="submit" type=submit value="备份数据">
</p>
<p>*必须是绝对的数据库地址<br>
</p>
</div></td>
</tr>
</table>
<p> </p>
</form>
<form name="form1" method="post" action="?action=hy">
<font color=red class="STYLE1">
<%
if request.QueryString("action")="hy" then
Dbpath=request.form("Dbpath")
backpath=request.form("backpath")
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.file Dbpath,Backpath
response.write "成功恢复数据!"
else
response.write "备份目录下并无您的备份文件!"
end if
end if%>
</font> <table width="80%" height="1" border="0" align=center cellpadding="5" cellspacing="1" bgcolor="#336699" class="tableBorder">
<tr>
<th width="593" height=25 bgcolor="#FFFFFF" > <B>恢复论坛数据</B>( 需要FSO支持,FSO相关帮助请看微软网站 ) </th>
</tr>
<tr>
<td height=100 bgcolor="#FFFFFF" class="forumrow"> 备份数据库路径(相对):
<input type=text size=30 name=DBpath value="bak\jester_bak.Mdb">
<BR>
目标数据库路径(相对):
<input name=backpath type=text id="backpath" value="<%=db%>" size=30>
<BR>
填写您当前使用的数据库路径,如不想覆盖当前文件,可自行命名(注意路径是否正确),然后修改conn.asp文件,如果目标文件名和当前使用数据库名一致的话,不需修改conn.asp文件<BR>

<input name="submit" type=submit value="恢复数据">
<br>
-----------------------------------------------------------------------------------------<br>
在上面填写本程序的数据库路径全名,本程序的默认备份数据库文件为,请按照您的备份文件自行修改。<br>
您可以用这个功能来备份您的法规数据,以保证您的数据安全!<br>
注意:所有路径都是相对与程序空间根目录的相对路径 </td>
</tr>
</table>
<p></p>
</form>
<span class="STYLE1">
<%
if request.QueryString("action")="ys" then
dim dbpath,boolIs97
if request("Dbpath")<>"" then Dbpath=request("Dbpath") end if
if request("Dbpath")="" then
if request("bkfolder")<>"" then bkfolder=request("bkfolder") else bkfolder="spubbsbak" end if
if request("bkdbname")<>"" then bkdbname=request("bkdbname") else bkdbname="spubbs" end if
bkdbname=bkdbname&"#.asp"
Dbpath=bkfolder&"\"&bkdbname
end if
'dbpath = request("dbpath")
if request("boolIs97")<>"" then boolIs97=request("boolIs97") else boolIs97=true end if
'boolIs97 = request("boolIs97")

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

'=====================压缩参数=========================
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 = "数据库名称或路径不正确. 请重试!" & vbCrLf
End If

End Function

end if%>
</span>
<form action="?action=ys" method="post">

<table width="80%" height="1" border="0" align=center cellpadding="5" cellspacing="1" bgcolor="#336699" class="tableBorder">
<tr>
<td width="581" height=25 bgcolor="#FFFFFF" class="forumrow"><b>注意:</b><br>
输入数据库所在相对路径,并且输入数据库名称(正在使用中数据库不能压缩,请选择备份数据库进行压缩操作) </td>
</tr>
<tr>
<td bgcolor="#FFFFFF" class="forumrow">压缩数据库:
<input type="text" name="dbpath" value=<%=db%>>

<input name="submit3" type="submit" value="开始压缩"></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" class="forumrow"><input type="checkbox" name="boolIs97" value="True">
如果使用 Access 97 数据库请选择 (默认为 Access 2000 数据库)<br>
<br></td>
</tr>
</table> </form>

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

<% '=========================数据库处理=============================================
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. 如何用asp做access数据库备份

用asp做access数据库备份
<% SQL="backup database 数据库名 to disk='"&
Server.MapPath("backup")&"\"&"backuptext.dat"&"'"

set cnn=Server.createobject("adodb.connection")

cnn.open "driver={SQL Server};Server=服务器名;uid=sa;pwd="

cnn.execute SQL

on error resume next

if err<>0 then

response.write "错误:"&err.Descripting

else

response.write "数据备份成功!"

end if %>

F. 怎样用ASP备份SQL2000数据库

ASP备份和恢复SQL数据库的操作方法:
1、备份
<%
SQL="backup database 数据库名 to disk='"&Server.MapPath("backup")&"\"&"backuptext.dat"&"'"
set cnn=Server.createobject("adodb.connection")
cnn.open "driver={SQL Server};Server=服务器名;uid=sa;pwd="
cnn.execute SQL
on error resume next
if err<>0 then
response.write "错误:"&err.Descripting
else
response.write "数据备份成功!"
end if
%>

2、恢复
<%
SQL="Restore database 数据库名 from disk='"&Server.MapPath("backup")&"\"&"backuptext.dat"&"'"
set cnn=Server.createobject("adodb.connection")
cnn.open "driver={SQL Server};Server=服务器名;uid=sa;pwd="
cnn.execute SQL
on error resume next
if err<>0 then
response.write "错误:"&err.Descripting
else
response.write "数据恢复成功!"
end if
%>

G. asp +access 怎样实现数据库备份

<% dim action dim admin_flag Function finddir(filepath) finddir="" for i=1 to len(filepath) if left(right(filepath,i),1)="/" or left(right(filepath,i),1)="\" then abc=i exit for end if next if abc <> 1 then finddir=left(filepath,len(filepath)-abc+1) end if end Function action=trim(request("action")) dim dbpath,bkfolder,bkdbname,fso,fso1 Dim uploadpath '备份数据 select case action 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 "请输入您要恢复成的数据库全名" else Dbpath=server.mappath(Dbpath) end if backpath=server.mappath(backpath) Set Fso=server.createobject("scripting.filesystemobject") if fso.fileexists(dbpath) then fso.file Dbpath,Backpath response.write "<br>" response.write "<br>" response.write "<br>" response.write "<center>成功恢复数据!" response.write "</center>" else response.write "备份目录下并无您的备份文件!" end if else call RestoreData() end if end select '====================备份数据库========================= sub BackupData() If IsSqlDataBase = 1 Then SQLUserReadme() Exit Sub End If %>

H. asp如何备份mdb数据库

Function CopyFiles(TempSource,TempEnd)
DimFSO
Set FSO =Server.CreateObject("Scripting.FileSystemObject")
IF FSO.FileExists(TempEnd) then
Response.Write "目标备份文件 <b>"& TempEnd &"</b> 已存在,请先删除!"
Set FSO=Nothing
Exit Function
End IF
IFFSO.FileExists(TempSource) Then
Else
Response.Write "要复制的源数据库文件<b>"&TempSource&"</b>不存在!"
Set FSO=Nothing
Exit Function
End If
FSO.CopyFileTempSource,TempEnd
Response.Write "已经成功复制文件<b>"&TempSource&"</b>到<b>"&TempEnd&"</b>"
Set FSO =Nothing
End Function

使用如下:

db="/Article/UploadFiles/200710/"&Title&""
TempSource= Server.MapPath(db)
db1="/Article/PicFile/"&Title&""
'db1=Replace(db1,"200708/","")
TempEnd=Server.MapPath(db1)
Call CopyFiles(TempSource,TempEnd)
Response.Write TempSource
Response.Write "<br>"
Response.Write TempEnd

I. 用asp实现数据库备份

用FileSystemObject将数据库复制一份

J. asp怎么进行数据库备份

主要看你是啥数据库了。
如果是ACCESS,可以直接复制到其他盘
如果是SQL
SEVER,要进入企业管理器,然后对数据库点右键--所有任务--数据库备份,选择指定的路径进行备份

热点内容
涂鸦论文 发布:2021-03-31 13:04:48 浏览:698
手机数据库应用 发布:2021-03-31 13:04:28 浏览:353
版面217 发布:2021-03-31 13:04:18 浏览:587
知网不查的资源 发布:2021-03-31 13:03:43 浏览:713
基金赎回参考 发布:2021-03-31 13:02:08 浏览:489
悬疑故事范文 发布:2021-03-31 13:02:07 浏览:87
做简单的自我介绍范文 发布:2021-03-31 13:01:48 浏览:537
战略地图参考 发布:2021-03-31 13:01:09 浏览:463
收支模板 发布:2021-03-31 13:00:43 浏览:17
电气学术会议 发布:2021-03-31 13:00:32 浏览:731