ASP如何备份还原数据库

数据库备份代码


<%
if request("submit")<>"" then
Dbpath=request.form("Dbpath")
Dbpath=server.mappath(Dbpath)
bkfolder=request.form("bkfolder")
bkdbname=request.form("bkdbname")
Set Fso=server.createobject("scripting.filesystemobject")
if fso.fileexists(dbpath) then
If CheckDir(bkfolder) = True Then
fso.copyfile dbpath,bkfolder& "\"& bkdbname
else
MakeNewsDir bkfolder
fso.copyfile dbpath,bkfolder& "\"& bkdbname
end if
response.write "<script>alert('数据库备份成功!');</script>"
Else
response.write "<script>alert('源数据库路径错误或不存在!');</script>"
End if
end if
'------------------检查某一目录是否存在-------------------
Function CheckDir(FolderPath)
folderpath=Server.MapPath(".")&"\"&folderpath
Set fso1 = CreateObject("Scripting.FileSystemObject")
If fso1.FolderExists(FolderPath) then
'存在
CheckDir = True
Else
'不存在
CheckDir = False
End if
Set fso1 = nothing
End Function
'-------------根据指定名称生成目录-----------------------
Function MakeNewsDir(foldername)
dim f
Set fso1 = CreateObject("Scripting.FileSystemObject")
Set f = fso1.CreateFolder(foldername)
MakeNewsDir = True
Set fso1 = nothing
End Function


%>



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="javascript1.2" src="../js/openwin.js"></script>
<link href="../css/button.css" rel="stylesheet" type="text/css">
<link href="../css/textfield.css" rel="stylesheet" type="text/css">
<link href="../css/button.css" rel="stylesheet" type="text/css">
<link href="../css/font12.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style3 {color: #FFFFFF}
-->
</style>
<link href="../css/font.css" rel="stylesheet" type="text/css">
<link href="../css/background.css" rel="stylesheet" type="text/css">
<link href="../css/button.css" rel="stylesheet" type="text/css">
</head>
<body class="backg_1">
<p> </p>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="23" height="34"><img src="../Images/background/ditu_1/l_up.gif" width="23" height="34"></td>
<td width="120" nowrap background="../Images/background/ditu_1/l_up_zhong.gif" class="font12_FFFFFF style3">备份数据库</td>
<td width="40"><img src="../Images/background/ditu_1/l_r_up.gif" width="40" height="34"></td>
<td height="34" background="../Images/background/ditu_1/zhong_up.gif"> </td>
<td width="25" background="../Images/background/ditu_1/r_up.gif"> </td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFEEA">
<tr>
<td width="23" background="../Images/background/ditu_1/l_zhong.gif"> </td>
<td><table width="100%" border="0">
<tr>
<td><div align="center">
<p class="edgingLabel"> </p>
<p class="edgingLabel">备份数据库(需要服务器FSO支持)

</p>
</div></td>
</tr>
<tr class="tableBorder">
<form name="form1" method="post" action="databf.asp">
<td height=100 class="forumrow"> <div align="center">当前数据库路径(相对路径):
<input type=password size=15 name=DBpath value="../65bddg89database/54vhqw3xwee.asa">

<BR>
备份数据库目录(相对路径):
<input type="text" size=15 name=bkfolder value=Databackup>

<BR>
备份数据库名称(填写名称):
<input type="text" size=15 name=bkDBname value=Databackup.asa>
</div>
<p align="center">
<input name="submit" type=submit id="submit" value="数据备份">
</p>
<p align="left"> 点击“数据备份”后即备份成功,您可以用这个功能来备份您的法规数据,以保证您的数据安全!
注:备份后如果存在相同的数据库名称,将直接覆盖旧的数据库</p></td></form>

</tr>
<tr>
<td><p> </p>
<p> </p></td>
</tr>
</table></td>
<td width="25" background="../Images/background/ditu_1/r_zhong.gif"> </td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="23"><img src="../Images/background/ditu_1/l_down.gif" width="23" height="19"></td>
<td background="../Images/background/ditu_1/zhong_down.gif"> </td>
<td width="25"><img src="../Images/background/ditu_1/r_down.gif" width="25" height="19"></td>
</tr>
</table></td>
</tr>
</table>

</body>
</html>
----------------------------------------------------------------------------
数据库恢复代码


<%
if request("submit")<>"" then

dim dbpath,bkfolder,bkdbname,fso,fso1
Dbpath=request.form("Dbpath")
backpath=request.form("backpath")
if dbpath="" then
response.write ""
else
Dbpath=server.mappath(Dbpath)
end if
backpath=server.mappath(backpath)

Set Fso=server.createobject("scripting.filesystemobject")
if fso.fileexists(dbpath) then
fso.copyfile Dbpath,Backpath
response.write "<script>alert('数据库恢复成功!');</script>"
else
response.write "<script>alert('源数据库路径错误或不存在!');</script>"
end if
end if
%>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="javascript1.2" src="../js/openwin.js"></script>
<style type="text/css">
<!--
.style3 {color: #FFFFFF}
-->
</style>
<link href="../css/font.css" rel="stylesheet" type="text/css">
<link href="../css/background.css" rel="stylesheet" type="text/css">
<link href="../css/button.css" rel="stylesheet" type="text/css">
</head>
<body class="backg_1">
<p> </p>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="23" height="34"><img src="../Images/background/ditu_1/l_up.gif" width="23" height="34"></td>
<td width="120" nowrap background="../Images/background/ditu_1/l_up_zhong.gif" class="font12_FFFFFF style3">恢复数据库</td>
<td width="40"><img src="../Images/background/ditu_1/l_r_up.gif" width="40" height="34"></td>
<td height="34" background="../Images/background/ditu_1/zhong_up.gif"> </td>
<td width="25" background="../Images/background/ditu_1/r_up.gif"> </td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFEEA">
<tr>
<td width="23" background="../Images/background/ditu_1/l_zhong.gif"> </td>
<td><table width="100%" border="0">
<tr>
<td><div align="center">
<p class="edgingLabel"> </p>
<p class="edgingLabel">恢复数据库(需要服务器FSO支持)

</p>
</div></td>
</tr>
<tr class="tableBorder">
<form name="form1" method="post" action="datahf.asp">
<td height=100 class="forumrow"><div align="center">
备份数据库路径(相对):
<input type=text size=30 name=DBpath value="Databackup\Databackup.asa">


目标数据库路径(相对):
<input type=password size=30 name=backpath value="..\65bddg89database\54vhqw3xwee.asa">
</div>
<p align="center"> <input name="submit" type=submit id="submit" value="恢复数据">
</p>
<p align="left"> 点击“恢复数据”即恢复数据成功,您可以用这个功能来备份您的法规数据,以保证您的数据安全!
注意:所有路径都是相对与程序空间根目录的相对路径</p> </td></form>

</tr>
<tr>
<td><p> </p>
<p> </p></td>
</tr>
</table></td>
<td width="25" background="../Images/background/ditu_1/r_zhong.gif"> </td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="23"><img src="../Images/background/ditu_1/l_down.gif" width="23" height="19"></td>
<td background="../Images/background/ditu_1/zhong_down.gif"> </td>
<td width="25"><img src="../Images/background/ditu_1/r_down.gif" width="25" height="19"></td>
</tr>
</table></td>
</tr>
</table>

</body>
</html>
posted @ 2005-09-22 13:16  QDuck  阅读(1347)  评论(0编辑  收藏  举报