谁能告诉我asp access 数据库备份代码

谁能告诉我asp access 数据库备份代码,第1张

access,备份和恢复,完整,可用

<%

if session("username_tyadmin")="" then

response.redirect "index.asp"

response.end

end if

%>

<!--#include file="conn.asp" -->

<style type="text/css">

<!--

body,td,th {

font-size: 12px

}

.STYLE1 {

color: #FFFFFF

font-weight: bold

}

.STYLE2 {color: #FF0000}

-->

</style><BODY topMargin=0 leftmargin="0" marginheight="0">

<%

db="../xs_data/xs.mdb"

If Request.QueryString("action")="back" Then

currf=request.form("currf")

currf=server.mappath(currf)

backf=request.form("backf")

backf=server.mappath(backf)

backfy=request.form("backfy")

On error resume next

Set objfso = Server.CreateObject("Scripting.FileSystemObject")

if err then

err.clear

response.write "<script>alert(""不能建立fso对象,请确保你的空间支持fso:!"")history.back()</script>"

response.end

end if

if objfso.Folderexists(backf) = false then

Set fy=objfso.CreateFolder(backf)

end if

objfso.copyfile currf,backf&"\"&backfy

response.write "<script>alert(""备份数据库成功"")history.back()</script>"

End If

If Request.QueryString("action")="ys" Then

currf=request.form("currf")

currf = server.mappath(currf)

ys=request.form("ys")

Const JET_3X = 4

strDBPath = left(currf,instrrev(currf,"\"))

on error resume next

Set objfso = Server.CreateObject("Scripting.FileSystemObject")

if err then

err.clear

response.write "<script>alert(""不能建立fso对象,请确保你的空间支持fso:!"")history.back()</script>"

response.end

end if

if objfso.fileexists(currf) then

Set Engine = CreateObject("JRO.JetEngine")

response.write strDBPath

on error resume next

If ys = "1" Then

Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0Data Source=" &currf, _

"Provider=Microsoft.Jet.OLEDB.4.0Data Source=" &strDBPath &"tourtemp.mdb" _

&"Jet OLEDB:Engine Type=" &JET_3X

Else

Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0Data Source=" &currf, _

"Provider=Microsoft.Jet.OLEDB.4.0Data Source=" &strDBPath &"tourtemp.mdb"

End If

objfso.CopyFile strDBPath &"tourtemp.mdb",currf

objfso.DeleteFile(strDBPath &"tourtemp.mdb")

Set objfso = nothing

Set Engine = nothing

if err then

err.clear

response.write "<script>alert(""错误:"&err.description&""")history.back()</script>"

response.end

end if

response.write "<script>alert(""压缩数据库成功"")history.back()</script>"

response.end

Else

response.write "<script>alert(""错误:找不到数据库文件!"")history.back()</script>"

response.end

End If

end if

if Request.QueryString("action")="reload" then

currf=request.form("currf")

currf=server.mappath(currf)

backf=request.form("backf")

if backf="" then

response.write "<script>alert(""请输入您要恢复的数据库全名"")history.back()</script>"

else

backf=server.mappath(backf)

end if

on error resume next

Set objfso = Server.CreateObject("Scripting.FileSystemObject")

if err then

err.clear

response.write "<script>alert(""不能建立fso对象,请确保你的空间支持fso:!"")history.back()</script>"

response.end

end if

if objfso.fileexists(backf) then

objfso.copyfile ""&backf&"",""&currf&""

response.write "<script>alert(""恢复数据库成功"")history.back()</script>"

response.end

else

response.write "<script>alert(""错误:备份目录下无您的备份文件!"")history.back()</script>"

response.end

end if

end if

%>

<form name="form1" method="POST" action="bak.asp?action=back">

<div align="center">

<center>

<table border="0" cellpadding="3" style="border-collapse: collapse" bordercolor="#111111" width="98%" id="AutoNumber1" cellspacing="3">

<tr>

<td width="100%" bgcolor="#125E03"><span class="STYLE1">备份数据库</span></td>

</tr>

<tr>

<td width="100%" bgcolor="#FBFDFF">要求空间支持FSO</td>

</tr>

<tr>

<td width="100%" bgcolor="#FBFDFF">数据库路径

<span style="background-color: #F7FFF7">

<input type="text" name="currf" size="20" value="<%=db%>" readonly></span> 备份数据目录: <span style="background-color: #F7FFF7">

<input type="text" name="backf" size="20" value="dbback">

</span></td>

</tr>

<tr>

<td width="100%" bgcolor="#FBFDFF">数据库名称:<span style="background-color: #F7FFF7">

<input type="text" name="backfy" size="20" value="backup.mdb">

<input type="submit" name="Submit" value="备份" >

<span class="STYLE2">注:尽量不要更改以上项</span></span></td>

</tr>

</table>

</center>

</div>

</form>

<form name="form1" method="POST" action="bak.asp?action=reload">

<div align="center">

<center>

<table border="0" cellpadding="3" cellspacing="3" style="border-collapse: collapse" bordercolor="#111111" width="98%" id="AutoNumber3">

<tr>

<td width="100%" bgcolor="#125E03">

<span class="STYLE1">恢复数据库</span></td>

</tr>

<tr>

<td width="100%">要求空间支持FSO</td>

</tr>

<tr>

<td width="100%">当前数据库路径:<span style="background-color: #F7FFF7">

<input type="text" name="currf" size="20" value="<%=db%>" readonly>

</span> 备份数据库路径:<span style="background-color: #F7FFF7">

<input type="text" name="backf" size="20" value="dbback/backup.mdb"></span><span style="background-color: #F7FFF7">

<input type="submit" name="Submit" value="恢复" >

</span>

</td>

</tr>

</table>

</center>

</div>

</form>

要加分哦

我可是把整个代码都贴出来了

用着可好用 我正用的

有两个

一个简单的下面是代码

<form name="form1" method="post" action="?action=bf">

备份原数据库路径:

<input name="text1" type="text" id="text1">

<p>备份目标数据库路径:

<input name="text2" type="text" id="text2">

</p>

<p>

<label>

<input type="submit" name="Submit" value="备份">

</label>

</p>

</form>

<%

Function CopyFiles(TempSource,TempEnd)

Dim FSO

Set FSO = Server.CreateObject("Scripting.FileSystemObject")

IF FSO.FileExists(TempEnd) then

Response.Write "目标备份文件 <b>" &TempEnd &"</b>已存在,请先删除!"

Set FSO=Nothing

Exit Function

End IF

IF FSO.FileExists(TempSource) Then

Else

Response.Write "要复制的源数据库文件 <b>"&TempSource&"</b>不存在!"

Set FSO=Nothing

Exit Function

End If

FSO.CopyFile TempSource,TempEnd

Response.Write "已经成功复制文件 <b>"&TempSource&"</b>到 <b>"&TempEnd&"</b>"

Set FSO = Nothing

End Function

if request("action")="bf" then

ff=server.MapPath(request("text1"))

aa=server.MapPath(request("text2"))

call CopyFiles(ff,aa)

end if

%>

**************************************我是分割线************************

还有复杂的

<http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />

<title>数据库备份系统</title>

<style type="text/css">

<!--

body {

background-color: #F4FFD2

margin-left:5px

margin-top: 15px

margin-right: 5px

margin-bottom: 10px

}

html{

font-size:12px

scrollbar-face-color:#99cc66

scrollbar-arrow-color:#000000

scrollbar-track-color:#F4FFD2

scrollbar-3dlight-color:#FFFFFF

scrollbar-highlight-color:#fcfcfc

scrollbar-shadow-color:#99cc00

scrollbar-darkshadow-color:#99cc66

}

input{background-color:#FFFFFF

border-color:#333333

border:1px

font-style:normal

}

.title {

FONT-SIZE: 18pxCOLOR: #010000FONT-FAMILY: "黑体"

}

A:hover {

COLOR: #f18b01FONT-FAMILY: Verdana, Arial, Helvetica, sans-serifTEXT-DECORATION: none

}

TD {

FONT-SIZE: 9ptCOLOR: #666666WORD-BREAK: break-allLINE-HEIGHT: 170%TEXT-DECORATION: none

}

.白字 {

COLOR: #ffffff

}

.company {

FONT-SIZE: 12pxCOLOR: #2b2b2bLINE-HEIGHT: 22pxFONT-FAMILY: Verdana, Arial, Helvetica, sans-serif

}

.dot {

FONT-SIZE: 12pxCOLOR: #aeaeaeFONT-FAMILY: Verdana, Arial, Helvetica, sans-serif

}

.news {

FONT-SIZE: 12pxCOLOR: #515151FONT-FAMILY: Verdana, Arial, Helvetica, sans-serifTEXT-DECORATION: none

}

.word {

FONT-SIZE: 12pxCOLOR: #6f6f6fLINE-HEIGHT: 18pxFONT-FAMILY: Verdana, Arial, Helvetica, sans-serifTEXT-DECORATION: none

}

.caption_dark {

FONT-WEIGHT: boldFONT-SIZE: 12pxCOLOR: #000000FONT-FAMILY: Verdana, Arial, Helvetica, sans-serifTEXT-DECORATION: none

}

.caption_simple {

FONT-WEIGHT: boldFONT-SIZE: 12pxCOLOR: #ffffffFONT-FAMILY: Verdana, Arial, Helvetica, sans-serifTEXT-DECORATION: none

}

.button {

FONT-SIZE: 12pxCOLOR: #666666TEXT-DECORATION: none

}

.date {

FONT-SIZE: 10pxCOLOR: #acacacFONT-FAMILY: Verdana, Arial, Helvetica, sans-serif

}

.doman {

FONT-WEIGHT: normalFONT-SIZE: 12pxCOLOR: #0a52afFONT-FAMILY: Arial, Helvetica, sans-serifTEXT-DECORATION: none

}

.form {

BORDER-RIGHT: #e0e0e0 1px solidBORDER-TOP: #e0e0e0 1px solidFONT-SIZE: 12pxBORDER-LEFT: #e0e0e0 1px solidCOLOR: #333333BORDER-BOTTOM: #e0e0e0 1px solidFONT-FAMILY: Verdana, Arial, Helvetica, sans-serifBACKGROUND-COLOR: #f7f7f7

}

.web_button {

FONT-WEIGHT: boldFONT-SIZE: 12pxCOLOR: #616e43TEXT-DECORATION: none

}

.bbs_user {

FONT-WEIGHT: boldFONT-SIZE: 12pxCOLOR: #ff6600FONT-FAMILY: Verdana, Arial, Helvetica, sans-serifTEXT-DECORATION: none

}

.bbs_user_simple {

FONT-SIZE: 12pxCOLOR: #575757FONT-FAMILY: Verdana, Arial, Helvetica, sans-serifTEXT-DECORATION: none

}

.menu {

FONT-SIZE: 12pxCOLOR: #e4e4e4TEXT-DECORATION: none

}

.copright {

FONT-SIZE: 12pxCOLOR: #333333FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif

}

.bt_word {

FONT-SIZE: 12pxCOLOR: #333333LINE-HEIGHT: 18pxFONT-FAMILY: Verdana, Arial, Helvetica, sans-serifTEXT-DECORATION: none

}

.list {

FONT-SIZE: 12pxCOLOR: #424242FONT-FAMILY: "??"TEXT-DECORATION: none

}

.list_class {

FONT-SIZE: 12pxCOLOR: #808080FONT-FAMILY: "???"TEXT-DECORATION: none

}

.page {

FONT-SIZE: 12pxCOLOR:#000000TEXT-DECORATION: none

}

.bbs_bt {

FONT-WEIGHT: boldFONT-SIZE: 12pxCOLOR: #000000TEXT-DECORATION: none

}

.bbs_bt_simple {

FONT-WEIGHT: normalFONT-SIZE: 12pxCOLOR: #545454TEXT-DECORATION: none

}

.bbs_list_word {

FONT-SIZE: 12pxCOLOR: #171717FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif

}

.case {

FONT-SIZE: 12pxCOLOR: #5a5e61LINE-HEIGHT: 18pxFONT-FAMILY: Verdana, Arial, Helvetica, sans-serifTEXT-DECORATION: none

}

.date_simple {

FONT-SIZE: 10pxCOLOR: #666666FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif

}

.product_bt {

FONT-WEIGHT: boldFONT-SIZE: 12pxCOLOR: #333333LINE-HEIGHT: 16pxFONT-FAMILY: Verdana, Arial, Helvetica, sans-serifTEXT-DECORATION: none

}

.prodcut {

FONT-SIZE: 12pxCOLOR: #505050LINE-HEIGHT: 16pxFONT-FAMILY: Verdana, Arial, Helvetica, sans-serifTEXT-DECORATION: none

}

.form2 {

BORDER-RIGHT: #989898 1px solidBORDER-TOP: #989898 1px solidFONT-SIZE: 12pxBORDER-LEFT: #989898 1px solidCOLOR: #333333BORDER-BOTTOM: #989898 1px solidFONT-FAMILY: Verdana, Arial, Helvetica, sans-serifBACKGROUND-COLOR: #f6f6f6

}

.button3 {

FONT-SIZE: 12pxCOLOR: #7b7b7bFONT-FAMILY: Verdana, Arial, Helvetica, sans-serifTEXT-DECORATION: none

}

.bt1 {

FONT-WEIGHT: boldFONT-SIZE: 12pxCOLOR: #717171

}

.bt_line {

FONT-SIZE: 14pxCOLOR: #547db2FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif

}

.bt2 {

FONT-WEIGHT: boldFONT-SIZE: 12pxCOLOR: #ff9501FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif

}

A.nav:link {

FONT-SIZE: 12pxCOLOR: #ffffffTEXT-DECORATION: none

}

A.nav:visited {

FONT-SIZE: 12pxCOLOR: #ffffffTEXT-DECORATION: none

}

A.nav:hover {

FONT-SIZE: 12pxCOLOR: #ffff00TEXT-DECORATION: none

}

<font face="Verdana, Arial, Helvetica, sans-serif">

.sb{color:#000000font-size:13pxtext-decoration:none}

a.sb:visited{color:#6699FFfont-size:13}

a.sb:link{color:#3399CCfont-size:13px}

.tomg { color: #666666font-size:12pxtext-decoration:none}

a.tomg:link {color: #666666text-decoration:none}

a.tomg:visited {color: #666666text-decoration:none}

a.tomg:hover { color:#FF3300font-size:14pxtext-decoration:none}

.00 { color:#333333font-size:12pxtext-decoration:none}

a.00:hover { color: #FF6666text-decoration:underline}

a.00:link {color: #666666text-decoration:none}

a.00:visited {color: #000000text-decoration:none}

a.bb:link {color:#666666text-decoration:nonecursor:handfont-weight:bold}

a.bb:visited {color: #666666text-decoration:nonecursor:handfont-weight:bold}

a.bb:hover {color: #CC0000text-decoration:underlinecursor:handfont-weight:bold}

.cc{color:#FFFFFFfont-size:12pxtext-decoration:none}

.tomg1 { color: #000000font-size:12pxletter-spacing:1.5word-spacing:1line-height:2text-decoration:none}

a.tomg1:link {color: #000000text-decoration:none}

a.tomg1:visited {color: #000000text-decoration:none}

a.tomg1:hover { color:#99CC33 text-decoration:none}

.style1 {color: #000000}

.style2 {

color: #FF0000

font-weight: bold

}

-->

</style></head>

<body>

<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#99CC00">

<form name="form1" id="form1" method="post" action="?action=bf">

<tr>

<td height="71" bgcolor="#FFFFFF"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="1">

<tr>

<td height="29" colspan="2" align="center" background="afterimage/line2.jpg" class="product_bt">::数据库备份::</td>

</tr>

<tr>

<td height="25" colspan="2" background="afterimage/titleline.gif"> </td>

</tr>

<tr>

<td width="18%" height="25" align="center" bgcolor="#F9F9F9"><span class="style1">数据路径:

</span></td>

<td width="82%" bgcolor="#F9F9F9"><input name="text1" type="text" id="text1" size="50" /> </td>

</tr>

<tr>

<td height="25" align="center" bgcolor="#EEEEEE"><span class="style1"> 备份数据库路径:</span></td>

<td height="25" bgcolor="#EEEEEE"><input name="text2" type="text" id="text2" size="50" />

 

<input type="submit" name="Submit" value=" 备份数据库 " /></td>

</tr>

<tr>

<td height="25" colspan="2" align="center" bgcolor="#F3F3F3"><%

Function CopyFiles(TempSource,TempEnd)

Dim FSO

Set FSO = Server.CreateObject("Scripting.FileSystemObject")

IF FSO.FileExists(TempEnd) then

Response.Write "目标备份文件 <b>" &TempEnd &"</b>已存在,请先删除!"

Set FSO=Nothing

Exit Function

End IF

IF FSO.FileExists(TempSource) Then

Else

Response.Write "要复制的源数据库文件 <b>"&TempSource&"</b>不存在!"

Set FSO=Nothing

Exit Function

End If

FSO.CopyFile TempSource,TempEnd

Response.Write "已经成功复制文件 <b>"&TempSource&"</b>到 <b>"&TempEnd&"</b>"

Set FSO = Nothing

End Function

if request("action")="bf" then

ff=server.MapPath(request("text1"))

aa=server.MapPath(request("text2"))

ss=split(request("text2"),"/")

CreateFolder(ss(0))

call CopyFiles(ff,aa)

end if

Sub CreateFolder(strFolder)

'首选判断要建立的文件夹是否已经存在

strTestFolder = Server.Mappath(strFolder)

Set objFSO = CreateObject("Scripting.FileSystemObject")

' 检查文件夹是否存在

If objFSO.FolderExists(strTestFolder) Then

response.write "该文件夹已经存在!"

Else

Dim strTestFolder, objFSO

strTestFolder = Server.Mappath(strFolder)

Set objFSO = CreateObject("Scripting.FileSystemObject")

' 建立文件夹

objFSO.CreateFolder(strTestFolder)

Set objFSO = Nothing

End If

End Sub

%></td>

</tr>

</table></td>

</tr></form>

</table>

</body>

</html>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/6641358.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-26
下一篇 2023-03-26

发表评论

登录后才能评论

评论列表(0条)

保存