ACCESS数据库的压缩,备份,还原,下载,删除的实现

复制代码 代码如下:html head
meta”Content-Language”content=”zh-cn”
meta”Content-Type”content=”text/html;charset=gb2312″
title数据库管理/title /head body divalign=center数据库管理连串/div br br
palign=”center” % DimZC_DATABASE_PATH ‘数据库的门径
ZC_DATABASE_PATH=”database/data.mdb”
data_array=Split(ZC_DATABASE_PATH,”/”卡塔尔(قطر‎ Dimaction
action=trim(request(“action”State of QatarState of Qatar Dimdbpath,bkfolder,bkdbname,fso,fso1
SelectCaseaction Case”” Callchushihua(State of Qatar Case”CompressData”‘压缩数量
Dimtmprs dimallarticle dimMaxid dimtopic,username,dateandtime,body
callCompressData(卡塔尔(قطر‎ case”BackupData”‘备份数据
ifrequest(“act”State of Qatar=”Backup”Then callupdata(State of Qatar else callBackupData(卡塔尔国 endIf
case”RestoreData”‘复苏数据 dimbackpath ifrequest(“act”卡塔尔国=”Restore”Then
Dbpath=request.form(“Dbpath”卡塔尔 backpath=request.form(“backpath”State of Qatarifdbpath=””Then response.write”PleaseinputyourdatabasewholeName” else
Dbpath=server.mappath(DbpathState of Qatar endIf backpath=server.mappath(backpath卡塔尔SetFso=server.CreateObject(“scripting.filesystemobject”卡塔尔国iffso.fileexists(dbpathState of QatarThen fso.copyfileDbpath,Backpath
response.write”数据库被成功还原!br” else
response.write”没找到您所急需的数据库!” endIf else callRestoreData(卡塔尔endIf Case”SpaceSize”‘系统空间攻陷 callSpaceSize(卡塔尔(قطر‎ Case”deletebackup”
Dimdbname dbpath=Request.QueryString(“dbpath”卡塔尔dbname=Request.QueryString(“dbname”卡塔尔国 dbpath=Server.MapPath(dbpath卡塔尔国dbpath=dbpath&”\”&dbname
setfso=CreateObject(“Scripting.FileSystemObject”)Iffso.FileExists(dbPath卡塔尔(قطر‎Then fso.DeleteFile(DBPath卡塔尔(قطر‎ Setfso=nothing
response.write”br您备份的数据库已经”&dbpath&”被成功删除!brbrahref=””data_s.asp””重回../a”
Else response.writedbpath
response.write”br输入的渠道错误,请确认后再一次输入!brbrahref=””data_s.asp””返回../a”
EndIf CaseElse EndSelect % /div % response.write”/body/html”
Subchushihua() % divalign=center form br/
ahref=”?action=CompressData”[减掉数据库]/a
br/br/ahref=”?action=BackupData”[备份数据库]/a
br/br/ahref=”?action=RestoreData”[还原数据库]/a
br/br/ahref=”?action=SpaceSize”[系统空间占有]/a br/br/ /form /div
%endsub% % ‘====================系统空间并吞=======================
SubSpaceSize(卡塔尔国 OnErrorResumeNext % divalign=center divalign=center
系统空间查看 br/br/ form br
数据库:%showSpaceinfo(“../”&data_array(1卡塔尔国&””卡塔尔%brbr
备份数据库:%showSpaceinfo(“databackup”State of Qatar%brbr
系统累加:%showSpaceinfo(“/”State of Qatar% brbr /form /div br br br
ahref=”data_s.asp”返回…/a /div % EndSub % %SubShowSpaceInfo(drvpath)
dimfso,d,size,showsize
setfso=server.CreateObject(“scripting.filesystemobject”)
drvpath=server.mappath(drvpath) setd=fso.getfolder(drvpath) size=d.size
showsize=size&”Byte” ifsize1024Then size=(Size/1024) showsize=size&”KB”
endIf ifsize1024Then size=(size/1024) showsize=formatnumber(size,2)&”MB”
endIf ifsize1024Then size=(size/1024) showsize=formatnumber(size,2)&”GB”
endIf response.write”fontface=verdana”&showsize&”/font” EndSub % %
SubRestoreData() % divalign=center divalign=center br/…

来源:”小小灰 “小灰”的专栏灰”的专栏
地址:

<%
‘文件名:updata.asp
‘远程地址
const url=””

action=request(“action”)
if action=”updata” then
 download(url&”config.txt”)
 download(url&”pack.jpg”)
 response.Write(“下载成功<a
href=’updata.asp?action=install’>安装</a>”卡塔尔
elseif action=”install” then
 str=openfile(“config.txt”)
 if str=”” then
  response.write “匮乏本地配置文件config.txt”
 else
  size=RegExpTest(“size”,str)
  call install(“pack.jpg”,size)
 end if
else
 str=getpage(url&”config.txt”)
 if str=”” then
  response.write “不设有可用更新也许地面配置不科学”
  response.end
 end if

 str1=openfile(“config.txt”)
 if str1=”” then
  response.write
“紧缺本地配置文件config.txt不也许获悉本地程序的安装时间”
  response.end
 end if

 updatatime=RegExpTest(“time”,str)
 updatatime1=RegExpTest(“time”,str1)

 if DateDiff(“d”,updatatime1,updatatime)>0 then
  response.Write(“存在可用更新,更新日期:”&updatatime&”<a
href=’updata.asp?action=updata’>下载</a>”State of Qatar
 else
  response.write “您的次序是时尚的了”
 end if
end if

function openfile(filename)
set fso=server.CreateObject(“scripting.filesystemobject”)
if fso.fileexists(server.MapPath(filename)) then
 set f1=fso.opentextfile(server.mappath(filename),1,true)
 openfile=f1.readall
 f1.close
else
 openfile=””
end if
set fso=nothing
end function

function getpage(url)
set
xmlhttp=server.createobject(“Microsoft.XMLHTTP”)
xmlhttp.open “get”,url,false
xmlhttp.send
if xmlhttp.status<>200 then
 getpage=””
else
 getpage=bytes2BSTR(xmlhttp.ResponseBody)
end if
end function

Function bytes2BSTR(vIn)
dim strReturn
dim i,ThisCharCode,NextCharCode
strReturn = “”
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 +
CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function

Function RegExpTest(patrn,strng)
Dim regEx,Match,Matches’建立变量。
Set regEx = New RegExp’建设构造正则表达式。
regEx.Pattern = patrn&”=(.+?卡塔尔/n”‘设置形式。
regEx.IgnoreCase = True’设置是或不是区分字符大小写。
regEx.Global = True’设置全局可用性。
Set Matches = regEx.Execute(strng卡塔尔国’推行寻找。
For Each Match in Matches’遍历相称集结。
RetStr = Match.Value
Next
RegExpTest = replace(RetStr,patrn&”=”,””)
End Function

function download(url)
 temp=split(url,”/”)
 filename=temp(ubound(temp))
 set
xmlhttp=server.createobject(“Microsoft.XMLHTTP”)
 xmlhttp.open “get”,url,false
 xmlhttp.send
 if xmlhttp.status<>200 then
  download=””
 else
  set fso=server.createobject(“scripting.filesystemobject”)
  if fso.fileexists(server.mappath(filename)) then
   fso.deletefile(server.mappath(filename))
  end if
  set fso=nothing
  img=xmlhttp.ResponseBody
  set objAdostream=server.createobject(“ADODB.Stream”)
  objAdostream.Open
  objAdostream.type=1
  objAdostream.Write(img)
  objAdostream.SaveToFile(server.mappath(filename))
  objAdostream.SetEOS
  set objAdostream=nothing
  download=filename
 end if
 set xmlhttp=nothing
end function

function install(filename,size)
on error resume next
path=server.mappath(“./”)

set fso=server.createobject(“scripting.filesystemobject”)

set s=server.createobject(“adodb.stream”)
set s1=server.createobject(“adodb.stream”)
set s2=server.createobject(“adodb.stream”)

s.open
s1.open
s2.open

s.type=1
s1.type=1
s2.type=1

s.loadfromfile(server.mappath(filename))
s.position=size
s1.write(s.read)
s1.position=0
s1.type=2
s1.charset=”gb2312″
s1.position=0
a=split(s1.readtext,vbcrlf)
s.position=0

i=0
while(i<ubound(a))
 b=split(a(i),”>”)
 if b(0)=”folder” then
  if not fso.folderexists(path&b(2)) then
   fso.createfolder(path&b(2))
  end if
 elseif b(0)=”file” then
  if fso.fileexists(path&b(2)) then
   fso.deletefile(path&b(2))
  end if
  s2.position=0
  s2.write(s.read(b(1)))
  s2.seteos
  s2.savetofile(path&b(2))
 end if
 i=i+1
wend

s.close
s1.close
s2.close
set s=nothing
set s1=nothing
set s2=nothing
set fso=nothing
if err.number<>0 then
 response.write err.description
else
 response.write “安装成功”
end if
end function

%>


<%
‘文件名称:pack.asp
on error resume next
set fso=server.createobject(“scripting.filesystemobject”)
if fso.fileexists(server.mappath(“./pack.jpg”)) then
 response.Write(“pack.jpg已经存在”卡塔尔(قطر‎
 response.End()
end if

dim str,s,s1,s2
set s=server.createobject(“ADODB.Stream”)
set s1=server.createobject(“ADODB.Stream”)
set s2=server.createobject(“ADODB.Stream”)

s.Open
s1.Open
s2.Open

s.Type=1
s1.type=1
s2.Type=2

call WriteFile(server.MapPath(“./”))

s2.charset=”gb2312″
s2.WriteText(str)
s2.Position=0
s2.type=1
s2.Position=0
bin=s2.Read

s2.Position=0
s2.type=2
s2.writeText(“time=”&now&vbcrlf)
s2.writeText(“size=”&s1.size&vbcrlf)
s2.writeText(“run=”&request.Form(“run”)&vbcrlf)
s2.seteos
s2.savetofile(server.mappath(“./config.txt”))

s1.write(bin)
s1.SetEOS
s1.SaveToFile(server.mappath(“./pack.jpg”))

s.close
s1.close
s2.close

set s=nothing
set s1=nothing
set s2=nothing

if err.number<>0 then
 response.write err.description
else
 response.Write(“完成”)
end if

Function WriteFile(folderspec)
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set f = fso.GetFolder(folderspec)

Set fc = f.Files
For Each f1 in fc
 if f1.name<>”pack.asp” then
  str=str&”file>”&f1.size&”>”&replace(folderspec&”/”&f1.name,server.MapPath(“./”),””)&vbcrlf
  s.LoadFromFile(folderspec&”/”&f1.name)
  img=s.Read()
  s1.Write(img)
 end if
Next

Set fc = f.SubFolders
For Each f1 in fc
  str=str&”folder>0>”&replace(folderspec&”/”&f1.name,server.MapPath(“./”),””)&vbcrlf
  WriteFile(folderspec&”/”&f1.name)
Next

set fso=nothing
End Function
%>


ASP升级程序选拔表明

本程序分两部分:
1、ASP文件打包程序pack.asp
 把那么些顺序和要打包的主次嵌入叁个目录下,然后运营pack.asp,取得pack.jpg和config.txt
2、ASP在线更新、下载、安装程序updata.asp
 那一个程序能够用来检查是或不是留存可用更新,和updata.asp同一目录要留存上边获得的config.txt,因为config里面有最近前后相继的设置日期,用来和网络的次序比较用的。
 使用前,先改正updata.asp里的url变量的值,使其极度你存放进级程序的UOdysseyL,运转updata.asp就可查看是或不是存在可用更新,固然存在就可用按着向导一步一步下载并设置更新了。

长途地址url下边存放用pack.asp得到的pack.jpg和config.txt

本程序不仅可以够用来做升高程序,当然若是原来安装目录下是空的,那就是贰个全体的安装程序,^_^,也得以把updata.asp放到后台的首页里,那样每一次登录都能够自动物检疫查是还是不是有可用更新

专心:本地也许远程未有config.txt会促成程序不可用,现在会思索加盟这一个容错机制。

小编音信:
QQ:103895
主页: 
 http://asp2004.net
版权注明:本程序可以轻便拷贝使用,但请不要删除此音讯。感谢!

发表评论

电子邮件地址不会被公开。 必填项已用*标注