<formmethod="post"name="myform"action="?action=backupdatabase">
选择操作:
<inputtype="radio"name="act"id="act_backup"value="backup">
<labelfor=act_backup>备份</label>
<inputtype="radio"name="act"id="act_restore"value="restore">
<labelfor=act_restore>恢复</label>
<br>
数据库名:
<inputtype="text"name="databasename"value="<%=request("databasename")%>">
<br>
文件路径:
<inputtype="text"name="bak_file"value="c:$1.bak">
(备份或恢复的文件路径)<br>
<inputtype="submit"value="确定"id=submit1name=submit1>
</form>
<%
'sqlserver数据库的备份与恢复!
ifrequest("action")="backupdatabase"then
dimsqlserver,sqlname,sqlpassword,sqllogintimeout,databasename,bak_file,act
'**************************************************************************
sqlserver="127.0.0.1"
sqlname="sa"
sqlpassword="111"
sqllogintimeout=15
databasename=trim(request("databasename"))
bak_file=trim(request("bak_file"))
bak_file=replace(bak_file,"$1",databasename)
act=lcase(request("act"))
'**************************************************************************
ifdatabasename=""then
response.write"inputdatabasename"
else
ifact="backup"then
setsrv=server.createobject("sqldmo.sqlserver")
srv.logintimeout=sqllogintimeout
srv.connectsqlserver,sqlname,sqlpassword
setbak=server.createobject("sqldmo.backup")
bak.database=databasename
bak.devices=files
bak.action=0
bak.initialize=1
'bak.replace=true
bak.files=bak_file
bak.sqlbackupsrv
iferr.number>0then
response.writeerr.number&"<fontcolor=red><br>"
response.writeerr.description&"</font>"
endif
response.write"<fontcolor=green>备份成功!</font>"
endif
ifact="restore"then
'恢复时要在没有使用数据库时进行!
setsrv=server.createobject("sqldmo.sqlserver")
srv.logintimeout=sqllogintimeout
srv.connectsqlserver,sqlname,sqlpassword
setrest=server.createobject("sqldmo.restore")
rest.action=0'fulldbrestore
rest.database=databasename
rest.devices=files
rest.files=bak_file
rest.replacedatabase=true'forcerestoreoverexistingdatabase
iferr.number>0then
response.writeerr.number&"<fontcolor=red><br>"
response.writeerr.description&"</font>"
endif
rest.sqlrestoresrv
response.write"<fontcolor=green>恢复成功!</font>"
else
response.write"<fontcolor=red>没有选择操作</font>"
endif
endif
endif
%>