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
%>
<%
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
%>