ASP备份数据库

文件1:BackupDB.asp

1@ Language=VBScript 
 1<html>
 2<head>
 3<meta content="VBScript" name="VI60_defaultClientScript"/>
 4<meta content="Microsoft FrontPage 4.0" name="GENERATOR"/>
 5<script id="clientEventHandlersVBS" language="vbscript">   
 6<!--   
 7  
 8Sub btnbak_onclick   
 9if frmbak.txtsvr.value="" then   
10window.alert("'Server Name' is empty!")   
11frmbak.txtsvr.focus   
12exit sub   
13end if   
14if frmbak.txtuid.value="" then   
15window.alert("'Administrators' is empty!")   
16frmbak.txtuid.focus   
17exit sub   
18end if   
19if frmbak.txtdb.value="" then   
20window.alert("'Database' is empty!")   
21frmbak.txtdb.focus   
22exit sub   
23end if   
24if frmbak.txtto.value="" then   
25window.alert("'Backup To' is empty!")   
26frmbak.txtto.focus   
27exit sub   
28end if   
29frmbak.submit   
30End Sub   
31  
32\-->   
33</script>
34<link href="../../sheets/B2BStyle.css" rel="stylesheet"/>
35</head>
36<form action="backupdbsave.asp" id="frmbak" method="post" name="frmbak">
37<body class="bg_frame_up">
38<p class="heading"> Database --&gt; Backup</p>
39<p align="center">
40<div align="center">
41<center>
42<table align="center" border="0" cellpadding="1" cellspacing="1" width="60%">
43<tr>
44<td align="center" class="TD_Mand_FN" height="35" width="40%">Server Name:</td>
45<td class="TD_Mand_F" height="35" width="59%">
46<input id="txtsvr" name="txtsvr" size="20" style="font-family: Arial; font-size: 9pt"/></td>
47</tr>
48<tr>
49<td align="center" class="TD_Mand_FN" height="35" width="40%">Administrators:</td>
50<td class="TD_Mand_F" height="35" width="59%">
51<input id="txtuid" name="txtuid" size="20" style="font-family: Arial; font-size: 9pt"/></td>
52</tr>
53<tr>
54<td align="center" class="TD_Mand_FN" height="35" width="40%">Password:</td>
55<td class="TD_Mand_F" height="35" width="59%">
56<input id="txtpwd" name="txtpwd" style="font-family: Arial; font-size: 9pt" type="password"/></td>
57</tr>
58<tr>
59<td align="center" class="TD_Mand_FN" height="35" width="40%">Database:</td>
60<td class="TD_Mand_F" height="35" width="59%">
61<p align="left">
62<input id="txtdb" name="txtdb" size="20" style="font-family: Arial; font-size: 9pt"/></p>
63</td>
64</tr>
65<td align="center" class="TD_Mand_FN" height="35" width="40%">Backup To:<br/>
66<u>(Server Path)</u></td>
67<td class="TD_Mand_F" height="35" width="59%">
68<input id="txtto" name="txtto" style="font-family: Arial; font-size: 9pt"/></td>
69
70</table>
71</center> </div>
72<p align="center"><input id="btnbak" name="btnbak" style="font-family: Arial; font-size: 9pt" type="button" value="Start Backup"/></p>
73</p></body>
74</form>
75</html>

文件2:BackupDBSave.asp

1@ Language=VBScript 
 1   
 2dim msvr,muid,mpwd,mdb,mto   
 3msvr=Request.Form("txtsvr")   
 4muid=Request.Form("txtuid")   
 5mpwd=Request.Form("txtpwd")   
 6mdb=Request.Form("txtdb")   
 7mto=Request.Form("txtto")   
 8if mpwd="" then mpwd="''"   
 9  
10on error resume next   
11set dmosvr=server.CreateObject("SQLDMO.SQLServer")   
12dmosvr.connect msvr,muid,mpwd   
13  
14if err.number>0 then Response.Redirect("http:backuperr.asp?err="&err.number)   
15  
16mdevname="Backup_"&muid&"_"&mdb   
17set dmodev=server.CreateObject("SQLDMO.BackupDevice")   
18dmodev.name=mdevname   
19dmodev.type=2   
20dmodev.PhysicalLocation=mto   
21dmosvr.BackupDevices.Add dmodev   
22  
23if err.number>0 then Response.Redirect("http:backuperr.asp?err="&err.number)   
24  
25set dmobak=server.CreateObject("SQLDMO.Backup")   
26dmobak.database=mdb   
27dmobak.devices=mdevname   
1<html>
2<head>
3<meta content="Microsoft Visual Studio 6.0" name="GENERATOR"/>
4</head>
5<body background="../../Images/dot.gif">
6<p><strong>Backuping, wait please...</strong></p>   

dmobak.sqlbackup dmosvr
if err.number&gt;0 then Response.Redirect("http:backuperr.asp?err="&amp;err.number)

dmosvr.backupdevices(mdevname).remove
set dmobak=nothing
set dmodev=nothing
dmosvr.disconnect
set dmosvr=nothing

1<p><strong>Database '```
2=mdb
3```' backup successed!</strong></p>
4</body>
5</html>

文件3:BackupErr.asp

1@ Language=VBScript 
 1   
 2dim errno,errstr   
 3errno=Request.QueryString("err")   
 4errstr=""   
 5select case cstr(errno)   
 6case "18456"   
 7errstr="administrators or password error!"   
 8case "20482"   
 9errstr="server name error or server cannot connect!"   
10case "911"   
11errstr="database not found!"   
12case "15026"   
13errstr="server path not found!"   
14case "3201"   
15errstr="server path not found!"   
16case "3254"   
17errstr="restore from file lawlessness!"   
18case else   
19errstr="unknown error! retry later please!"   
20end select   
 1<html>
 2<head>
 3<meta content="VBScript" name="VI60_defaultClientScript"/>
 4<meta content="Microsoft FrontPage 4.0" name="GENERATOR"/>
 5<script id="clientEventHandlersVBS" language="vbscript">   
 6<!--   
 7  
 8Sub btnret_onclick   
 9history.back   
10End Sub   
11  
12\-->   
13</script>
14<title></title>
15</head>
16<body class="bg_frame_up">
17<p align="center"><font color="#006666">```
18=errstr
19```</font></p>
20<p align="center"><input id="btnret" name="btnret" style="font-family: Arial; font-size: 9pt" type="button" value="Return"/></p>
21</body>
22</html>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus