<HTML>
<HEAD>
<TITLE> Database Operations _ Web Design Home </TITLE>
<meta http-equiv= "Content-type" content= "text/html"; charset=gb2312 ">
</HEAD>
<BODY>
<form method= "POST" name=myform>
<%if action= "restore" then%><input type= "hidden" name= "action" value= "restore" > Ready to restore the database ...
<%elseif action= "Backup" Then%><input type= "hidden" name= "action" value= "Backup" > Prepare to back up the database ... <%else%>
Select operation:
<input type= "Radio" name= "Action" id= "Act_backup" value= "Backup" ><label for=act_backup> backup </label >
<input type= "Radio" name= "Action" id= "Act_restore" value= "restore" ><label for=act_restore> restore </label ><%end if%>
<br> database name: <input type= "text" name= "DatabaseName" value= "50forum" >
<br> file path: <input type= "text" name= "Bak_file" value= "50forum.bak" > (file path for backup or recovery) <br>
<input type= "Submit" value= "OK" >
</form>
<%
' SQL Server database backup and restore!
' http://www.dwww.cn
Dim Sqlserver,sqlname,sqlpassword,sqllogintimeout,databasename,bak_file,act
SQL Server = "localhost" \
sqlname = "sa" User name
sqlpassword = "sa" password
sqllogintimeout = 15 ' Login Timeout
DatabaseName = Trim (Request ("DatabaseName"))
Bak_file = Trim (Request ("Bak_file"))
bak_file = Server.MapPath ("backup/" &bak_file)
act = LCase (Request ("action"))
if databasename = "" Then
Response.Write "Input database name"
Else
If act = "Backup" then
Set srv = Server.CreateObject ("SQLDMO.") SQL Server ")
srv. LoginTimeout = Sqllogintimeout
srv. Connect Sqlserver,sqlname, SQLPassword
Set bak = Server.CreateObject ("SQLDMO.") Backup ")
Bak. Database = DatabaseName
Bak. Devices = Files
Bak. Files = Bak_file
Bak. Action = 0
Bak. Initialize = 1
' Bak. ReplaceDatabase = True
Bak. SQLBackup SRV
if Err.number>0 then
Response.Write err.number& "<font color=red><br>"
Response.Write err.description& "</font>"
End If
Response.Write "<font color=green> backup succeeded!</font>"
Srv.disconnect
Set srv = Nothing
Set bak = Nothing
ElseIf act = "Restore" then
' restore when not using the database!
Set srv=server.createobject ("SQLDMO. SQL Server ")
srv. LoginTimeout = Sqllogintimeout
srv. Connect Sqlserver,sqlname, SQLPassword
Set rest = Server.CreateObject ("SQLDMO.") Restore ")
Rest. Action = 0 ' Full db restore
rest. Database = DatabaseName
rest. Devices = Files
rest. Files = Bak_file
rest. ReplaceDatabase = True ' Force restore over existing database
if Err.number>0 then
Response.Write err.number& "<font color=red><br>"
Response.Write err.description& "</font>"
End If
rest. SQLRestore SRV
Response.Write "<font color=green> Restore Success!</font>"
Srv.disconnect
Set srv = Nothing
Set rest = Nothing
Else
Response.Write "<font color=red> did not select operation </font>"
End If
End If
%>
</BODY>
</HTML>