ASP备份Sql Server数据库

原创 2005年04月30日 21:51:00

<% http://www.acnow.net/ xxcoA1lfx
Dim objSQLServer http://www.acnow.net/ xxcoA1lfx
Dim objBackup http://www.acnow.net/ xxcoA1lfx
Set objSQLServer = Server.CreateObject("SQLDMO.SQLServer") http://www.acnow.net/ xxcoA1lfx
objSQLServer.Connect "Localhost", "sa", "sa" http://www.acnow.net/ xxcoA1lfx
Set objBackup = Server.CreateObject("SQLDMO.Backup") http://www.acnow.net/ xxcoA1lfx
objBackup.Database = "vehicle" http://www.acnow.net/ xxcoA1lfx
objBackup.Files="d:/vehicle.bak" http://www.acnow.net/ xxcoA1lfx
objBackup.MediaDescription = "Back of vehicle" http://www.acnow.net/ xxcoA1lfx
On Error Resume Next http://www.acnow.net/ xxcoA1lfx
objBackup.SQLBackup(objSQLServer) http://www.acnow.net/ xxcoA1lfx
if Err<>0 then http://www.acnow.net/ xxcoA1lfx
strErr = Err.Description http://www.acnow.net/ xxcoA1lfx
response.write strErr http://www.acnow.net/ xxcoA1lfx
else http://www.acnow.net/ xxcoA1lfx
response.write "&Ecirc;&yacute;&frac34;&Yacute;&sup3;&Eacute;&sup1;&brvbar;±&cedil;·&Yacute;!" http://www.acnow.net/ xxcoA1lfx
end if http://www.acnow.net/ xxcoA1lfx
%>

http://www.acnow.net/ B7W6bI

2. http://www.acnow.net/ xxcoA1lfx
文件1:BackupDB.asp

<%@ Language=VBscript %> http://www.acnow.net/ xxcoA1lfx
<HTML> http://www.acnow.net/ xxcoA1lfx
<HEAD> http://www.acnow.net/ xxcoA1lfx
<meta name=VI60_defaultClientscript content=VBscript> http://www.acnow.net/ xxcoA1lfx
<meta NAME="GENERATOR" Content="Microsoft FrontPage 4.0"> http://www.acnow.net/ xxcoA1lfx
<script ID=clientEventHandlersVBS LANGUAGE=vbscript> http://www.acnow.net/ xxcoA1lfx
<!--btnbak_onclick http://www.acnow.net/ xxcoA1lfx
if frmbak.txtsvr.value="" then http://www.acnow.net/ xxcoA1lfx
window.alert("'Server Name' is empty!") http://www.acnow.net/ xxcoA1lfx
frmbak.txtsvr.focus http://www.acnow.net/ xxcoA1lfx
exit sub http://www.acnow.net/ xxcoA1lfx
end if http://www.acnow.net/ xxcoA1lfx
if frmbak.txtuid.value="" then http://www.acnow.net/ xxcoA1lfx
window.alert("'Administrators' is empty!") http://www.acnow.net/ xxcoA1lfx
frmbak.txtuid.focus http://www.acnow.net/ xxcoA1lfx
exit sub http://www.acnow.net/ xxcoA1lfx
end if http://www.acnow.net/ xxcoA1lfx
if frmbak.txtdb.value="" then http://www.acnow.net/ xxcoA1lfx
window.alert("'Database' is empty!") http://www.acnow.net/ xxcoA1lfx
frmbak.txtdb.focus http://www.acnow.net/ xxcoA1lfx
exit sub http://www.acnow.net/ xxcoA1lfx
end if http://www.acnow.net/ xxcoA1lfx
if frmbak.txtto.value="" then http://www.acnow.net/ xxcoA1lfx
window.alert("'Backup To' is empty!") http://www.acnow.net/ xxcoA1lfx
frmbak.txtto.focus http://www.acnow.net/ xxcoA1lfx
exit sub http://www.acnow.net/ xxcoA1lfx
end if http://www.acnow.net/ xxcoA1lfx
frmbak.submit http://www.acnow.net/ xxcoA1lfx
End Sub--> http://www.acnow.net/ xxcoA1lfx
</script> http://www.acnow.net/ xxcoA1lfx
<link rel="stylesheet" href="../../sheets/B2BStyle.css"> http://www.acnow.net/ xxcoA1lfx
</HEAD> http://www.acnow.net/ xxcoA1lfx
<form action="backupdbsave.asp" method="post" id=frmbak name=frmbak> http://www.acnow.net/ xxcoA1lfx
<body class="bg_frame_up"> http://www.acnow.net/ xxcoA1lfx
<p class=heading> Database --> Backup</p> http://www.acnow.net/ xxcoA1lfx
<P align=center> http://www.acnow.net/ xxcoA1lfx
<div align="center"> http://www.acnow.net/ xxcoA1lfx
<center> http://www.acnow.net/ xxcoA1lfx
<table width="60%" cellpadding=1 cellspacing=1 border=0 align=center> http://www.acnow.net/ xxcoA1lfx
<tr> http://www.acnow.net/ xxcoA1lfx
<td class=TD_Mand_FN align="center" height="35" width="40%">Server Name:</td> http://www.acnow.net/ xxcoA1lfx
<td class=TD_Mand_F height="35" width="59%"> http://www.acnow.net/ xxcoA1lfx
<INPUT id=txtsvr name=txtsvr size="20" style="font-family: Arial; font-size: 9pt"></td> http://www.acnow.net/ xxcoA1lfx
</tr> http://www.acnow.net/ xxcoA1lfx
<tr> http://www.acnow.net/ xxcoA1lfx
<td class=TD_Mand_FN align="center" height="35" width="40%">Administrators:</td> http://www.acnow.net/ xxcoA1lfx
<td class=TD_Mand_F height="35" width="59%"> http://www.acnow.net/ xxcoA1lfx
<INPUT id=txtuid name=txtuid size="20" style="font-family: Arial; font-size: 9pt"></td> http://www.acnow.net/ xxcoA1lfx
</tr> http://www.acnow.net/ xxcoA1lfx
<tr> http://www.acnow.net/ xxcoA1lfx
<td class=TD_Mand_FN align="center" height="35" width="40%">Password:</td> http://www.acnow.net/ xxcoA1lfx
<td class=TD_Mand_F height="35" width="59%"> http://www.acnow.net/ xxcoA1lfx
<INPUT id=txtpwd name=txtpwd type=password style="font-family: Arial; font-size: 9pt"></td> http://www.acnow.net/ xxcoA1lfx
</tr> http://www.acnow.net/ xxcoA1lfx
<tr> http://www.acnow.net/ xxcoA1lfx
<td class=TD_Mand_FN align="center" height="35" width="40%">Database:</td> http://www.acnow.net/ xxcoA1lfx
<td class=TD_Mand_F height="35" width="59%"> http://www.acnow.net/ xxcoA1lfx
<p align="left"> http://www.acnow.net/ xxcoA1lfx
<INPUT id=txtdb name=txtdb size="20" style="font-family: Arial; font-size: 9pt"></p> http://www.acnow.net/ xxcoA1lfx
</td> http://www.acnow.net/ xxcoA1lfx
</tr>http://www.acnow.net/ xxcoA1lfx

<td class=TD_Mand_FN align="center" height="35" width="40%">Backup T<br/> http://www.acnow.net/ xxcoA1lfx
<u>(Server Path)</u></td> http://www.acnow.net/ xxcoA1lfx
<td class=TD_Mand_F height="35" width="59%"> http://www.acnow.net/ xxcoA1lfx
<input id=txtto name=txtto style="font-family: Arial; font-size: 9pt"></td> http://www.acnow.net/ xxcoA1lfx
</tr> http://www.acnow.net/ xxcoA1lfx
</table> http://www.acnow.net/ xxcoA1lfx
</center> </div> http://www.acnow.net/ xxcoA1lfx
<p align=center><input id=btnbak name=btnbak type=button value="Start Backup" style="font-family: Arial; font-size: 9pt"></p> http://www.acnow.net/ xxcoA1lfx
</body> http://www.acnow.net/ xxcoA1lfx
</form> http://www.acnow.net/ xxcoA1lfx
</HTML>

http://www.acnow.net/ xxcoA1lfx

http://www.acnow.net/ xxcoA1lfx
文件2:BackupDBSave.asp

http://www.acnow.net/ xxcoA1lfx

<%@ Language=VBscript %> http://www.acnow.net/ xxcoA1lfx
<% http://www.acnow.net/ xxcoA1lfx
dim msvr,muid,mpwd,mdb,mto http://www.acnow.net/ xxcoA1lfx
msvr=Request.Form("txtsvr") http://www.acnow.net/ xxcoA1lfx
muid=Request.Form("txtuid") http://www.acnow.net/ xxcoA1lfx
mpwd=Request.Form("txtpwd") http://www.acnow.net/ xxcoA1lfx
mdb=Request.Form("txtdb") http://www.acnow.net/ xxcoA1lfx
mto=Request.Form("txtto") http://www.acnow.net/ xxcoA1lfx
if mpwd="" then mpwd="''"

http://www.acnow.net/ xxcoA1lfx

on error resume next http://www.acnow.net/ xxcoA1lfx
set dmosvr=server.CreateObject("SQLDMO.SQLServer") http://www.acnow.net/ xxcoA1lfx
dmosvr.connect msvr,muid,mpwd

http://www.acnow.net/ xxcoA1lfx

if err.number>0 then Response.Redirect("http:backuperr.asp?err="&err.number)

http://www.acnow.net/ xxcoA1lfx

mdevname="Backup_"&muid&"_"&mdb http://www.acnow.net/ xxcoA1lfx
set dmodev=server.CreateObject("SQLDMO.BackupDevice") http://www.acnow.net/ xxcoA1lfx
dmodev.name=mdevname http://www.acnow.net/ xxcoA1lfx
dmodev.type=2 http://www.acnow.net/ xxcoA1lfx
dmodev.PhysicalLocation=mto http://www.acnow.net/ xxcoA1lfx
dmosvr.BackupDevices.Add dmodev

http://www.acnow.net/ xxcoA1lfx

if err.number>0 then Response.Redirect("http:backuperr.asp?err="&err.number)

http://www.acnow.net/ xxcoA1lfx

set dmobak=server.CreateObject("SQLDMO.Backup") http://www.acnow.net/ xxcoA1lfx
dmobak.database=mdb http://www.acnow.net/ xxcoA1lfx
dmobak.devices=mdevname http://www.acnow.net/ xxcoA1lfx
%> http://www.acnow.net/ xxcoA1lfx
<HTML> http://www.acnow.net/ xxcoA1lfx
<HEAD> http://www.acnow.net/ xxcoA1lfx
<meta NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> http://www.acnow.net/ xxcoA1lfx
</HEAD> http://www.acnow.net/ xxcoA1lfx
<body background="../../Images/dot.gif">

http://www.acnow.net/ xxcoA1lfx

<p><strong>Backuping, wait please...</strong></p> http://www.acnow.net/ xxcoA1lfx
<% http://www.acnow.net/ xxcoA1lfx
dmobak.sqlbackup dmosvr http://www.acnow.net/ xxcoA1lfx
if err.number>0 then Response.Redirect("http:backuperr.asp?err="&err.number)

http://www.acnow.net/ xxcoA1lfx

dmosvr.backupdevices(mdevname).remove http://www.acnow.net/ xxcoA1lfx
set dmobak=nothing http://www.acnow.net/ xxcoA1lfx
set dmodev=nothing http://www.acnow.net/ xxcoA1lfx
dmosvr.disconnect http://www.acnow.net/ xxcoA1lfx
set dmosvr=nothing http://www.acnow.net/ xxcoA1lfx
%> http://www.acnow.net/ xxcoA1lfx
<p><strong>Database '<%=mdb%>' backup successed!</strong></p> http://www.acnow.net/ xxcoA1lfx
</BODY> http://www.acnow.net/ xxcoA1lfx
</HTML>

http://www.acnow.net/ xxcoA1lfx

http://www.acnow.net/ xxcoA1lfx
文件3:BackupErr.asp

http://www.acnow.net/ xxcoA1lfx

<%@ Language=VBscript %> http://www.acnow.net/ xxcoA1lfx
<% http://www.acnow.net/ xxcoA1lfx
dim errno,errstr http://www.acnow.net/ xxcoA1lfx
errno=Request.QueryString("err") http://www.acnow.net/ xxcoA1lfx
errstr="" http://www.acnow.net/ xxcoA1lfx
select case cstr(errno) http://www.acnow.net/ xxcoA1lfx
case "18456" http://www.acnow.net/ xxcoA1lfx
errstr="administrators or password error!" http://www.acnow.net/ xxcoA1lfx
case "20482" http://www.acnow.net/ xxcoA1lfx
errstr="server name error or server cannot connect!" http://www.acnow.net/ xxcoA1lfx
case "911" http://www.acnow.net/ xxcoA1lfx
errstr="database not found!" http://www.acnow.net/ xxcoA1lfx
case "15026" http://www.acnow.net/ xxcoA1lfx
errstr="server path not found!" http://www.acnow.net/ xxcoA1lfx
case "3201" http://www.acnow.net/ xxcoA1lfx
errstr="server path not found!" http://www.acnow.net/ xxcoA1lfx
case "3254" http://www.acnow.net/ xxcoA1lfx
errstr="restore from file lawlessness!" http://www.acnow.net/ xxcoA1lfx
case else http://www.acnow.net/ xxcoA1lfx
errstr="unknown error! retry later please!" http://www.acnow.net/ xxcoA1lfx
end select http://www.acnow.net/ xxcoA1lfx
%> http://www.acnow.net/ xxcoA1lfx
<HTML> http://www.acnow.net/ xxcoA1lfx
<HEAD> http://www.acnow.net/ xxcoA1lfx
<meta name=VI60_defaultClientscript content=VBscript> http://www.acnow.net/ xxcoA1lfx
<meta NAME="GENERATOR" Content="Microsoft FrontPage 4.0"> http://www.acnow.net/ xxcoA1lfx
<script ID=clientEventHandlersVBS LANGUAGE=vbscript> http://www.acnow.net/ xxcoA1lfx
<!--

btnret_onclick http://www.acnow.net/ xxcoA1lfx
history.back http://www.acnow.net/ xxcoA1lfx
End Sub

--> http://www.acnow.net/ xxcoA1lfx
</script> http://www.acnow.net/ xxcoA1lfx
<title></title> http://www.acnow.net/ xxcoA1lfx
</HEAD> http://www.acnow.net/ xxcoA1lfx
<body class="bg_frame_up"> http://www.acnow.net/ xxcoA1lfx
<p align=center><font color=#006666><%=errstr%></font></p> http://www.acnow.net/ xxcoA1lfx
<p align=center><input id=btnret name=btnret type=button value=Return style="font-family: Arial; font-size: 9pt"></p> http://www.acnow.net/ xxcoA1lfx
</BODY> http://www.acnow.net/ xxcoA1lfx
</HTML>

利用ASP备份SQL SERVER数据库

 if session("user_name")="" then   response.write "alert(对不起,请你先登陆!);window.location.href=index.asp;...
  • fenglibing
  • fenglibing
  • 2006年06月05日 09:53
  • 7169

ASP中怎么实现SQL数据库备份、恢复! 选择自 hanghwp 的 Blog

1、ASP中怎么实现SQL数据库备份、恢复!答:asp在线备份sql server数据库:1、备份SQL="backup database 数据库名 to disk="&Server.MapPath(...
  • doublel
  • doublel
  • 2005年07月21日 09:13
  • 687

SQL SERVER 2008 R2 远程备份数据库

题记因为之前出现服务器硬盘挂掉,数据库数据差点就木有了,这个问题很严重,因此就想这在局域网中其他机器也备份一下数据库。 使用方法: (1) 使用python,ssh2连接(通过密钥或账号/密码登陆);...
  • cdd801
  • cdd801
  • 2015年07月30日 10:25
  • 1843

ASP连接SQL Server数据库总结

Microsoft SQL Server7.0是一种大型、分布式数据库系统,也可被认为是一种大型、分布式数据仓库。SQL Server是一个十分注重安全性的数据库,特别是在7.0版本发布以后,可以将数...
  • denlee
  • denlee
  • 2007年04月29日 15:00
  • 14898

SQL Server2014数据库的备份和还原

在系统开发的过程中,把DB备份,并还原到其他的服务器上,或者在本机上在还原出一个数据库的操作很常见。 大概步骤是: 1.以sa账号登录,在需要备份的DB上选择右键->任务->备份 2. ...
  • zpf0901
  • zpf0901
  • 2017年04月25日 17:09
  • 2704

SQL备份所有数据库脚本

技巧要点:使用游标循环读取所有数据库名,然后定义存放路径,最后备份所有数据库到指定存在的本地文件夹中脚本如下:declare @fileName varchar(255) --定义备份文件名变量dec...
  • xqf222
  • xqf222
  • 2014年03月28日 19:09
  • 1287

SQL server 2008定期的备份数据库--差异+完整

在SQL Server中出于数据安全的考虑,所以需要定期的备份数据库。而备份数据库一般又是在凌晨时间基本没有数据库操作的时候进行,所以我们不可能要求管理员 每天守到晚上1点去备份数据库。要实现数据库的...
  • zcyy1211
  • zcyy1211
  • 2017年02月13日 20:12
  • 2353

SQL SERVER数据库自动备份与删除命令

使用备份命令 一、备份数据的第一个步骤–“建立备份” 使用用户自定义的备份命令时,只需要在配置定时作业时增加备份命令,即可实现自动备份。具体的操作方法如下: 1.       使用S...
  • YABIGNSHI
  • YABIGNSHI
  • 2015年12月28日 05:08
  • 1448

SQL server 2008R2 数据库备份和还原

先说点题外话  第一篇博客有点小激动 。由于时间关系决定先写一个比较简单的数据库备份和还原。当初还是菜鸟的时候被实验室老师学长扔在一边,全靠自己琢磨,当时强大的网民群体真心帮了不少忙。所以临近毕业,也...
  • cherish_CX
  • cherish_CX
  • 2016年10月09日 22:49
  • 4002

SQL Server 2008数据库创建,备份,还原图解及注意点

一、新建数据库 步骤1:点击“新建数据库”。 步骤2:输入数据库名称,设置数据库文件保存位置(注意点:最好自己设置数据库文件保存位置,不要采用安装时默认的文件保存位置!),点击“确认”即可完成...
  • tiana0
  • tiana0
  • 2013年10月12日 16:32
  • 11804
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:ASP备份Sql Server数据库
举报原因:
原因补充:

(最多只允许输入30个字)