asp 在线备份与恢复sqlserver数据库的代码
来源:asp之家 发布时间:2011-03-06 11:14:00
asp在线备份sql server数据库:
1、备份sqlserver
代码如下:
<%
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、恢复sqlserver
代码如下:
<%
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
%>
ACCESS原理一样
代码如下:
<%
'*****************************************
function CopyTo(ByVal cFile,ByVal toFile)
cFile=Server.MapPath(cFile) ‘所要备份的文件
toFile=Server.MapPath(toFile) ‘备份文件
Dim cFso,cf
set cFso=Server.CreateObject("Scripting.FileSystemObject")
cFso.fileexists(cFile)
cFso.Copyfile cFile,toFile
end function
'*********************************************
' ASP实现备份及恢复ACCESS数据库操作
'本页面为 databackup.asp
dim dbpath,bkfolder,bkdbname,fso,fso1
call main()
call main2()
conn.close
set conn=nothing
sub main()
if request("action")="Backup" then
call backupdata()
else
%>
<table cellspacing=1 cellpadding=1 align=center width="90%">
<tr>
<th height=25 >
<B>数据库备份</B>
</th>
</tr>
<form method="post" action="databackup.asp?action=Backup">
<tr>
<td height=100 style="line-height:150%">
当前数据库路径(相对路径):
<input type=text size=15 name=DBpath value="../mdb/database.mdb"><BR>
备份数据库目录(相对路径):
<input type=text size=15 name=bkfolder value=../Databackup> 如目录不存在,程序将自动创建<BR>
备份数据库名称(填写名称):
<input type=text size=15 name=bkDBname value=database.mdb> 如备份目录有该
文件,将覆盖,如没有,将自动创建<BR>
<input type=submIT value="备份数据"><hr align="center" width="90%" color="#999999"></td>
</tr>
</form>
</table>
<%
end if
end sub
sub main2()
if request("action")="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)
Response.wrITe Backpath
Set Fso=server.createobject("scripting.filesystemobject")
if fso.fileexists(dbpath) then
fso.copyfile Dbpath,Backpath
response.wrITe "<font color=red>成功恢复数据!</font>"
else
response.wrITe "<font color=red>备份目录下并无您的备份文件!</font>"
end if
else
%>
<table align=center cellspacing=1 cellpadding=1 width="90%">
<tr>
<th height=25 >
<B>恢复数据库</B>
</th>
</tr>
<form method="post" action="databackup.asp?action=Restore">
<tr>
<td height=100 >
备份数据库路径(相对):
<input type=text size=30 name=DBpath value="../Databackup/database.mdb"> <BR>
当前数据库路径(相对):
<input type=text size=30 name=backpath value="../mdb/database.mdb"><BR>
<input type=submIT value="恢复数据"> <hr width="90%" align="center" color="#999999">
<font color="#666666">·注意:所有路径都是相对路径 </font></td>
</tr>
</form>
</table>
<%
end if
end sub
sub backupdata()
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 "<font color=red>备份数据库成功,您备份的数据库路径为" &bkfolder& "\\"& bkdbname+"</font>"
Else
response.wrITe "<font color=red>找不到您所需要备份的文件。</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
%>
猜你喜欢
- 1、设置数据库模式为简单模式:打开SQL企业管理器,在控制台根目录中依次点开Microsoft SQL Server-->SQL Se
- (5)SELECT (5-2) DISTINCT(5-3)TOP(<top_specification>)(5-1) <s
- 但Insus.NET想到的是,从下面的SQL语句,就可以查询到数据库大小。因此分享于此。 代码如下:SELECT DB_NAME
- 继续Mootools的扩展,适用于Mootools 1.1及1.2,这次在Element扩展了两个非常简单的方法,一个用来获取
- 最近随着狂风计划的席卷,我也终于开始橱窗产品位列表展示的编码工作,这只是一个改进项目,因此有原代码可供参考。但是当我打开原代码模板的时候便愣
- GetRepeatTimes(TheChar,TheString) 得到一个字符串在另一个字符串当中出现几次的函数(新)如:response
- 依次前移,实现聊友们的发言的更迭:function form1_onsubmit()if document.form1.
- 有朋友使用DIV居中,但是却发现DIV居中失灵了,是怎么回事呢?下面给大家解决一下问题,呵呵!1、一般情况下DIV居中失效是因为没写DTD语
- 本文讨论 MySQL 的备份和恢复机制,以及如何维护数据表,包括最主要的两种表类型:MyISAM 和 Innodb,文中设计的 MySQL
- 如何用JMail同时给多人发信?在ASP中,为什么我在Jmail收件人处指定多个收件人时,像这样:JMail.AddRecipient&nb
- (1)、back_log:要求 MySQL 能有的连接数量。当主要MySQL线程在一个很短时间内得到非常多的连接请求,这就起作用,然后主线程
- CSS代码更清晰高效的一些经验是许多网页制作者与开发者都关心的问题。但是大概没有什么魔法,可以保证一下就把你的样式表缩小到百分之多少,合理的
- 曾经为看别人写的杂乱代码而头痛吗?曾经为看BWindow代码而烦恼吗?曾经为减小JS体积和JS的可读性之间的矛盾而左右徘徊吗?最好的办法是有
- 如何干预执行计划 - - 使用hints提示基于代价的优化器是很聪明的,在绝大多数情况下它会选择正确的优化器,减轻了DBA的负担。但有时它也
- 这里使用FSO对象来删除指定文件夹 代码和说明如下:<% set fs=createobject(&qu
- asp之家注:防止表单重复提交的方法,在客户端其实很容易实现,只要使用js让用户第一次点击提交按钮后,把提交按钮设置为disabled,这样
- PHP原型模式Prototype Pattern是什么原型模式是一种创建型模式,它可以通过复制现有对象来创建新的对象,而无需知道具体的创建过
- 1,exists和in的理解exists:如果子查询中包括某一行,那么就为TRUE in:如果操作数为TRUE等于表达式列表中的一个,那么就
- 字符串的IndexOf()方法搜索在该字符串上是否出现了作为参数传递的字符串,如果找到字符串,则返回字符的起始位置 (0表示第一个字符,1表
- 如果你只使用一个更新日志,你只须清空日志文件,然后移走旧的更新日志文件到一个备份中,然后启用新的更新日志。用下列方法可以强制服务器启用新的更