《数据库备份与恢复.doc》由会员分享,可在线阅读,更多相关《数据库备份与恢复.doc(13页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、数据库备份与恢复.txt我是天使,回不去天堂是因为体重的原因。别人装处,我只好装经验丰富。泡妞就像挂QQ,每天哄她2个小时,很快就可以太阳了。access,备份和恢复,完整,可用 % 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 re
2、sume next Set objfso = Server.CreateObject(Scripting.FileSystemObject) if err then err.clear response.write alert(不能建立fso对象,请确保你的空间支持fso:!);history.back(); response.end end if if objfso.Folderexists(backf) = false then Set fy=objfso.CreateFolder(backf) end if objfso.copyfile currf,backf& & backfy re
3、sponse.write alert(备份数据库成功);history.back(); 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.FileSystemObj
4、ect) if err then err.clear response.write alert(不能建立fso对象,请确保你的空间支持fso:!);history.back(); 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.0
5、;Data Source= & currf, _ Provider=Microsoft.Jet.OLEDB.4.0;Data Source= & strDBPath & tourtemp.mdb; _ & Jet OLEDB:Engine Type= & JET_3X Else Engine.CompactDatabase Provider=Microsoft.Jet.OLEDB.4.0;Data Source= & currf, _ Provider=Microsoft.Jet.OLEDB.4.0;Data Source= & strDBPath & tourtemp.mdb End If
6、objfso.CopyFile strDBPath & tourtemp.mdb,currf objfso.DeleteFile(strDBPath & tourtemp.mdb) Set objfso = nothing Set Engine = nothing if err then err.clear response.write alert(错误:&err.description&);history.back(); response.end end if response.write alert(压缩数据库成功);history.back(); response.end Else re
7、sponse.write alert(错误:找不到数据库文件!);history.back(); 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 alert(请输入您要恢复的数据库全名);history.back(); else backf=server.mappath(backf) e
8、nd if on error resume next Set objfso = Server.CreateObject(Scripting.FileSystemObject) if err then err.clear response.write alert(不能建立fso对象,请确保你的空间支持fso:!);history.back(); response.end end if if objfso.fileexists(backf) then objfso.copyfile &backf&,&currf& response.write alert(恢复数据库成功);history.back
9、(); response.end else response.write alert(错误:备份目录下无您的备份文件!);history.back(); response.end end if end if % 备份数据库 要求空间支持FSO 数据库路径: input type=text name=currf size=20 value= readonly 备份数据目录: 数据库名称: 注:尽量不要更改以上项 恢复数据库 要求空间支持FSO 当前数据库路径: input type=text name=currf size=20 value= readonly 备份数据库路径: =数据库管理数据
10、库管理系统%Dim ZC_DATABASE_PATH数据库的路径ZC_DATABASE_PATH=database/data.mdbdata_array= Split(ZC_DATABASE_PATH,/)Dim actionaction=trim(request(action)Dim dbpath,bkfolder,bkdbname,fso,fso1Select Case actionCase Call chushihua()Case CompressData 压缩数据Dim tmprsdim allarticledim Maxiddim topic,username,dateandtime
11、,bodycall CompressData()case BackupData 备份数据if request(act)=Backup Thencall updata()elsecall BackupData()end Ifcase RestoreData 恢复数据dim backpathif request(act)=Restore ThenDbpath=request.form(Dbpath)backpath=request.form(backpath)if dbpath= Thenresponse.write Please input your database whole Name el
12、seDbpath=server.mappath(Dbpath)end Ifbackpath=server.mappath(backpath)Set Fso=server.CreateObject(scripting.filesystemobject)if fso.fileexists(dbpath) Then fso.copyfile Dbpath,Backpathresponse.write 数据库被成功还原!elseresponse.write 没找到您所需要的数据库! end Ifelsecall RestoreData()end IfCase SpaceSize 系统空间占用call
13、SpaceSize()Case deletebackupDim dbnamedbpath=Request.QueryString(dbpath)dbname=Request.QueryString(dbname)dbpath=Server.MapPath(dbpath)dbpath=dbpath &dbnameset fso = CreateObject(Scripting.FileSystemObject)If fso.FileExists(dbPath) Thenfso.DeleteFile(DBPath)Set fso = nothingresponse.write 您备份的数据库已经
14、& dbpath &被成功删除!返回.Elseresponse.write dbpath response.write 输入的路径错误,请确认后重新输入!返回.End IfCase ElseEnd Select%response.writeSub chushihua()%压缩数据库备份数据库还原数据库系统空间占用系统空间查看数据库:备份数据库:系统总共:返回. 1024 Thensize=(Size/1024)showsize=size & KBend Ifif size1024 Thensize=(size/1024)showsize=formatnumber(size,2) & MB en
15、d Ifif size1024 Thensize=(size/1024)showsize=formatnumber(size,2) & GB end If response.write & showsize & End Sub %还原数据库:还原的路径(相对路径):input type=text size=30 name=DBpath value=DataBackup_Bak.mdb还原后的路径(相对路径):input type=text size=30 name=backpath value=返回.%End SubSub updata()Dbpath=request.form(Dbpath)
16、Dbpath=server.mappath(Dbpath)bkfolder=request.form(bkfolder)bkdbname=request.form(bkdbname)Set Fso=server.CreateObject(scripting.filesystemobject)if fso.fileexists(dbpath) ThenIf CheckDir(bkfolder) = True Thenfso.copyfile dbpath,bkfolder& & bkdbnameelseMakeNewsDir bkfolderfso.copyfile dbpath,bkfolde
17、r& & bkdbnameend Ifresponse.write 已经成功备份,你的数据库的路径: &bkfolder& & bkdbnameresponse.write 点击此处将数据库下载下来: & ZC_BLOG_HOST & request.form(bkfolder) & / & bkdbname &response.write 当您下载完毕后,点击此处将删除备份的数据库!返回.Elseresponse.write Error ,找不到文件!End IfSet fso = nothingEnd Sub-检查某一目录是否存在-Function CheckDir(FolderPath)
18、folderpath=Server.MapPath(.)&folderpathSet fso1 = CreateObject(Scripting.FileSystemObject)If fso1.FolderExists(FolderPath) Then存在CheckDir = TrueElse不存在CheckDir = FalseEnd IfSet fso1 = nothingEnd Function-根据指定名称生成目录-Function MakeNewsDir(foldername)dim fSet fso1 = CreateObject(Scripting.FileSystemObje
19、ct)Set f = fso1.CreateFolder(foldername)MakeNewsDir = TrueSet fso1 = nothingEnd FunctionSub BackupData()%备份数据库当前数据库的路径(相对路径):input type=text size=15 name=DBpath value=备份数据库的路径(相对路径):如果该目录不存在,系统将自动建立备份后数据库的名称:input type=text size=20 name=bkDBname value=_bak.mdb 按日期自动命名如果备份文件不存在将建立,如果存在,将自动覆盖!返回.压缩数据库
20、:输入数据库的所在路径压缩数据库的路径:input type=text name=dbpath value=如果是ac97,请将钩打上.(默认是Access 2000)返回.%Dim dbpath,boolIs97dbpath = request(dbpath)boolIs97 = request(boolIs97)If dbpath Thendbpath = server.mappath(dbpath)response.write(CompactDB(dbpath,boolIs97)End IfEnd Sub=压缩参数=Function CompactDB(dbPath, boolIs97)
21、Dim fso, Engine, strDBPath,JET_3XstrDBPath = Left(dbPath,InStrRev(DBPath,)Set fso = CreateObject(Scripting.FileSystemObject)If fso.FileExists(dbPath) Thenfso.CopyFile dbpath,strDBPath & temp.mdbSet Engine = CreateObject(JRO.JetEngine)If boolIs97 = True ThenEngine.CompactDatabase Provider=Microsoft.J
22、et.OLEDB.4.0;Data Source= & strDBPath & temp.mdb, _Provider=Microsoft.Jet.OLEDB.4.0;Data Source= & strDBPath & temp1.mdb; _& Jet OLEDB:Engine Type= & JET_3XElseEngine.CompactDatabase Provider=Microsoft.Jet.OLEDB.4.0;Data Source= & strDBPath & temp.mdb, _Provider=Microsoft.Jet.OLEDB.4.0;Data Source= & strDBPath & temp1.mdbEnd Iffso.CopyFile strDBPath & temp1.mdb,dbpathfso.DeleteFile(strDBPath & temp.mdb)fso.DeleteFile(strDBPath & temp1.mdb)Set fso = nothingSet Engine = nothingCompactDB = 您的数据库 & dbpath & 已经被成功压缩! & vbCrLfElseCompactDB = 您输入的路径错误,请确认后重新输入! & vbCrLfEnd IfEnd Function/end/%