asp 在线备份与恢复sql server数据库的代码
发布时间:2010-07-31 18:52:00
asp 在线备份 恢复 sql server 数据库,对于远程没有提供sql server远程连接或打包下载的朋友是个临时解决方法,对于大数据来说可能效果不好。
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、恢复sql server
<%
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
%>


猜你喜欢
- 内连接(inner join)。 外连接: 全连接(full join)、左连接(left join)、右连接(right join)。 交
- 1. join()join(’参数‘)把数组的元素以传入的参数为分割符,转换成字符串。let arr
- 本文实例讲述了JS实现json数组排序操作。分享给大家供大家参考,具体如下:有时需要根据json对象的某个属性排序json数组,javasc
- 游戏规则用pygame动画实现神庙逃亡类似的小游戏,当玩家移动的时候躲避 * ,如果 * 命中玩家或者名字龙都会减速,玩家躲避 * 使更多的 * 打
- 简介: 我们在这世上,选择什么就成为什么,人生的丰富多彩,得靠自己成就。你此刻的付出,决定了你未来成为什么样的人,当你改变不了世界
- 如下所示:import osimport cv2import sysimport numpy as nppath = "F:\\I
- 实例代码如下def demo(): print("开始执行...") while 1: &nbs
- 本文以Centos7.6系统与Oracle11g为例:一.先找到数据库的环境变量如果是在root账户下,须先登录到数据库所在账户su ora
- 页签的流行自从Yahoo!的首页引进页签(tab, 见下图)之后,这种可用性极佳的方式越来越受欢迎,用户也逐步习惯和喜欢上它,因为它可以在原
- 先看一个例子:<?phpclass A{ public $b; public $c; public function A() { &n
- import numpy as npimport pandas as pdfrom pandas_datareader import dat
- 先给大家展示实现后效果:为直观期间,先贴出来我做的效果列表展示和地图展示以及联动显示信息实现思路:1、列表与地图的互动鼠标经过列表时,修改列
- element-ui el-table组件自定义合计(summary-method)坑项目需要用到表格,带有合计功能的,照搬的element
- 本文实例讲述了Python 面向对象之类class和对象基本用法。分享给大家供大家参考,具体如下:类(class):定义一件事物的抽象特点,
- 下面为您介绍sql下用了判断各种资源是否存在的代码,需要的朋友可以参考下,希望对您学习sql的函数及数据库能够有所帮助。-- 库是否存在if
- 我们最常用的 DBD::mysql 模块,我发现是难住很多人的地方.因为安装老是失败,下面我介绍一下解决方法,比如我使用 cpanm 安装,
- 字节串bytes字节串也叫字节序列,是不可变的序列,存储以字节为单位的数据字节串表示方法:b"ABCD"b"\
- 先来说eval的用法,内容比较简单,熟悉的可以跳过eval函数接收一个参数s,如果s不是字符串,则直接返回s。否则执行s语句。如果s语句执行
- 刚刚在学习些测试报告的时候,出现一个路径的问题,找了很久的原因,竟然是少了一个反斜杠引起的,在此顺便记录一下正反斜杠的作用。在Python中
- MySQL 数据(字段)类型在创建表的时候,要明确定义字段对应的数据类型。MySQL 主要的数据类型分为数值类型、字符串(文本)类型、时间日