Copy Code code as follows:
<form method= "POST" name= "MyForm" action= "Action=backupdatabase" >
Select actions: <input type= "Radio" name= "act" id= "act_backup" value= "Backup" ><label for=act_backup> backup </label >
<input type= "Radio" name= "act" id= "Act_restore" value= "restore" ><label for=act_restore> recovery </label>
<br> database name: <input type= "text" name= "DatabaseName" value= "<%=request (" DatabaseName ")%>" >
<br> file path: <input type= "text" name= "Bak_file" value= "C:\$1.bak" > (file path for backup or recovery) <br>
<input type= "Submit" value= "OK" id=submit1 name=submit1>
</form>
<%
' Backup and restore of SQL Server database!
If Request ("action") = "BackupDatabase" Then
Dim sqlserver,sqlname,sqlpassword,sqllogintimeout,databasename,bak_file,act
SQL Server = "localhost"
Sqlname = "sa"
SQLPassword = "Password"
Sqllogintimeout = 15
DatabaseName = Trim (Request ("DatabaseName"))
Bak_file = Trim (Request ("Bak_file"))
Bak_file = replace (Bak_file, "$", databasename)
act = LCase (Request ("act")
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. Action = 0
Bak. Initialize = 1
' Bak. Replace = True
Bak. Files=bak_file
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 Successful!</font>"
ElseIf act= "Restore" then
' Restore when you are 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>"
Else
Response.Write "<font color=red> did not select operation </font>"
End If
End If
End If
%>