Have seen database backup and restore. Most of it is done using components. In fact, it can be done through sql statement.
Due to time constraints, the parameters were not verified and the interface beautified. The code is for reference only.
A total of 4 files: Download address: function rec(rs,sql)
set rs = server.CreateObject("ADODB.Recordset")
rs.Activeconnection = conn
rs.Source = sql
rs.CursorType = 0
rs.Cursorlocation = 3
rs.LockType = 1
rs.Open
if rs.eof and rs.bof then
rec=false
else
rec=true
end if
end function
function cmd(sql)
dim cmd1
set cmd1 = server.CreateObject("ADODB.Command")
cmd1.ActiveConnection = conn
cmd1.CommandText = sql
cmd1.CommandType = 1
cmd1.CommandTimeout = 0
cmd1.Prepared = true
cmd1.Execute()
end function
function cdb(rs)
rs.close()
set rs=nothing
end function
%>
dev.asp
<!--#include file="conn.asp"-->
<%
if request("AddDev") <> "" then
sql="select name,phyname from master..sysdevices where status=16 and name='"&request("devname")&"'"
rec chk,sql
if chk.eof and chk.bof then
sql = "sp_addumpdevice 'disk','"&request("devname")&"','"&request("phyname")&"'"
cmdsql
response.Write "<script language=javascript>window.location=reload;</script>"
else
response.Write "<script language=javascript>alert('The device already exists in the database"&request("devname")&"Device!');window.location='cmd.asp';</script>"
end if
end if
if request("deldev") <> "" then
sql = "sp_dropdevice '"&request("devname")&"'"
cmdsql
response.Write "<script language=javascript>window.location=reload;</script>"
end if
rec li,"select name,phyname from master..sysdevices where status=16"
if li.eof and li.bof then
response.Write "<font color=#ff0000>Please create a new backup device to back up and restore the database</font>"
else
%><style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
}
-->
</style>
<table width="60%" border="0" cellspacing="0">
<tr>
<td width="29%">Name:</td>
<td width="71%">Position:</td>
</tr>
<%
i=0
while not li.eof
i=i+1
%>
<tr>
<td><%=li(0)%></td>
<td><%=li(1)%> <a href='dev.asp?DelDev=1&devname=<%=li(0)%>'>Delete this device</a></td>
</tr>
<%
li.movenext
wend
response.Write "<script language=javascript>top.document.all.dev.height='"&(i+1)*25&"';</script>"
cdbli
%>
</table>
<%
end if
%>
default.asp
< %@LANGUAGE="VBSCRIPT " CODEPAGE="936"%>
<!--#include file="conn.asp"-->
<%
'************************************************
'Database backup and restore
'Programming: Magic Yang (MagicYang.CN)
'Completion date: 2004-4-11
'Explanation: Due to time constraints, the security of the data was not verified.
'Please verify the data when applying to ensure safety.
'QQ: 1168064 Welcome everyone to communicate with each other
'************************************************
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Database backup and restore</title>
</head>
<body>
<%
%>
<table width="80%" border="0" align="center">
<tr>
<td width="21%" valign="top">Database device:</td>
<td width="79%">
<iframe name="dev" src="dev.asp" width="100%" height="200" frameborder="0" scrolling="no"></iframe>
</td>
</tr>
<tr>
<td>Add device:</td>
<td>Device name:
<input name="devname" type="text" id="devname" size="10" maxlength="10"></td>
</tr>
<tr>
<td> </td>
<td>File path:
<input name="phyname" type="text" id="phyname" size="20" maxlength="50">
<input type="button" value="Add device" onClick="document.all.dev.src='dev.asp?AddDev=1&devname='+document.all.devname.value+'&phyname='+document.all .phyname.value;"></td>
</tr>
<tr>
<td valign="top">Backup/Restore:</td>
<td>
Database name:
<%
rec li,"select name from master..sysdatabases where status=16"
%>
<select name="b_data">
<%
while not li.eof
response.Write "<option value="&li(0)&">"&li(0)&"</option>"
li.movenext
wend
cdbli
%>
</select><br>
Backup to device: <%
rec li,"select name,phyname from master..sysdevices where status=16"
%>
<select name="b_dev">
<%
while not li.eof
response.Write "<option value="&li(0)&">"&li(0)&"(file:"&li(1)&")</option>"
li.movenext
wend
cdbli
%>
</select><br>
<input name="Button" type="button" value="Backup database" onClick="window.location='cmd.asp?action=backup&database='+document.all.b_data.value+'&dev='+document. all.b_dev.value;">
<input name="Button" type="button" value="Restore Database" onClick="window.location='cmd.asp?action=RESTORE&database='+document.all.b_data.value+'&dev='+document. all.b_dev.value;"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
cmd.asp
<!--#include file="conn.asp"-->
<%
on error resume next
if request("action") <> "" then
if request("action")="backup" then
sql ="BACKUP DATABASE "&request("database")&" To "& request("dev")
cmdsql
if err.number > 0 then
response.Write "<script language=javascript>alert('database"&request("database")&"Backup failed!');window.location='default.asp';</script>"
else
response.Write "<script language=javascript>alert('Database"&request("database")&"Backup successful!');window.location='default.asp';</script>"
end if
else
sql ="RESTORE DATABASE "&request("database")&" From "& request("dev")
cmdsql
if err.number > 0 then
response.Write "<script language=javascript>alert('Database"&request("database")&"Restore failed!');window.location='default.asp';</script>"
else
response.Write "<script language=javascript>alert('database"&request("database")&"Restored successfully!');window.location='default.asp';</script>"
end if
end if
end if
%>
Hope everyone can communicate with each other! QQ: 1168064