use masterbackup database @name to disk=@path
2、数据库还原:
use masterrestore database @name from disk=@path With Replace
注:
Sql参数:@name 为数据库名称,@path 为备份文件路径;
以上两条语句可以分别封装为两个方法可方便调用。
1、备份<%
SQL="backup database 数据库名 to disk='"&Server.MapPath("backup")&"\"&"backuptext.dat"&"'"
set cnn=Server.createobject("adodb.connection")
cnn.open "driver={SQL Server}Server=服务器名uid=sapwd="
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=sapwd="
cnn.execute SQL
on error resume next
if err<>0 then
response.write "错误:"&err.Descripting
else
response.write "数据恢复成功!"
end if
%>
注:以上语句是把数据备份到磁盘的backup目录下,文件名为backuptext.dat。
<%sub backupdata()
Dbpath=db
Dbpath=server.mappath(Dbpath)
bkfolder=request.form("bkfolder")
bkdbname=request.form("bkdbname")&".mdb"
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 "<center>备份数据库成功!备份的数据库为 " &bkfolder &"\" &bkdbname &"</center>"
Else
response.write "找不到您所需要备份的文件。"
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)
Set fso1 = CreateObject("Scripting.FileSystemObject")
Set f = fso1.CreateFolder(foldername)
MakeNewsDir = True
Set fso1 = nothing
End Function
%>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)