-- 作者:稻草人 -- 发布时间:2006-4-11 17:45:40
-- ACCESS数据库的压缩,备份,还原,下载,删除的实现
数据库管理
数据库管理系统
<% Dim ZC_DATABASE_PATH /'数据库的路径 ZC_DATABASE_PATH="database/data.mdb" data_array= Split(ZC_DATABASE_PATH,"/") Dim action action=trim(request("action")) Dim dbpath,bkfolder,bkdbname,fso,fso1 Select Case action Case "" Call chushihua() Case "CompressData" /'压缩数据 Dim tmprs dim allarticle dim Maxid dim topic,username,dateandtime,body call CompressData() case "BackupData" /'备份数据 if request("act")="Backup" Then call updata() else call BackupData() end If case "RestoreData" /'恢复数据 dim backpath if request("act")="Restore" Then Dbpath=request.form("Dbpath") backpath=request.form("backpath") if dbpath="" Then response.write "Please input your database whole Name" 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 "数据库被成功还原! " else response.write "没找到您所需要的数据库!" end If else call RestoreData() end If Case "SpaceSize" /'系统空间占用 call SpaceSize() Case "deletebackup" Dim dbname dbpath=Request.QueryString("dbpath") dbname=Request.QueryString("dbname") dbpath=Server.MapPath(dbpath) dbpath=dbpath &"//"&dbname set fso = CreateObject("Scripting.FileSystemObject") If fso.FileExists(dbPath) Then fso.DeleteFile(DBPath) Set fso = nothing response.write " 您备份的数据库已经" & dbpath &"被成功删除!
返回.." Else response.write dbpath response.write " 输入的路径错误,请确认后重新输入!
返回.." End If Case Else End Select %>
<% response.write"" Sub chushihua() %>
<%end sub%> <% /'====================系统空间占用======================= Sub SpaceSize() On Error Resume Next %>
<% End Sub %> <% Sub ShowSpaceInfo(drvpath) dim fso,d,size,showsize set fso=server.CreateObject("scripting.filesystemobject") drvpath=server.mappath(drvpath) set d=fso.getfolder(drvpath) size=d.size showsize=size & " Byte" if size>1024 Then size=(Size/1024) showsize=size & " KB" end If if size>1024 Then size=(size/1024) showsize=formatnumber(size,2) & " MB" end If if size>1024 Then size=(size/1024) showsize=formatnumber(size,2) & " GB" end If response.write "" & showsize & "" End Sub %> <% Sub RestoreData() %> <% End Sub Sub updata() 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 " 已经成功备份,你的数据库的路径:" &bkfolder& "//"& bkdbname response.write "
点击此处将数据库下载下来:" & ZC_BLOG_HOST & request.form("bkfolder") & "/" & bkdbname &"
" response.write "
当您下载完毕后,点击此处将删除备份的数据库!
返回..." Else response.write "Error ,,找不到文件! " End If Set fso = nothing End Sub /'------------------检查某一目录是否存在------------------- 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 Sub BackupData() %>
<% End Sub Sub CompressData() %>
<% Dim dbpath,boolIs97 dbpath = request("dbpath") boolIs97 = request("boolIs97") If dbpath <> "" Then dbpath = server.mappath(dbpath) response.write(CompactDB(dbpath,boolIs97)) End If End Sub /'=====================压缩参数========================= Function CompactDB(dbPath, boolIs97) Dim fso, Engine, strDBPath,JET_3X strDBPath = Left(dbPath,InStrRev(DBPath,"/")) Set fso = CreateObject("Scripting.FileSystemObject") If fso.FileExists(dbPath) Then fso.CopyFile dbpath,strDBPath & "temp.mdb" Set Engine = CreateObject("JRO.JetEngine") If boolIs97 = "True" Then Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb", _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp1.mdb;" _ & "Jet OLEDB:Engine Type=" & JET_3X Else Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb", _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp1.mdb" End If fso.CopyFile strDBPath & "temp1.mdb",dbpath fso.DeleteFile(strDBPath & "temp.mdb") fso.DeleteFile(strDBPath & "temp1.mdb") Set fso = nothing Set Engine = nothing CompactDB = "您的数据库" & dbpath & "已经被成功压缩!" & vbCrLf Else CompactDB = " 您输入的路径错误,请确认后重新输入!" & vbCrLf End If End Function /'////////////////////end//////////////////////// %> |