欢迎大家测试:
<%
'复制备份原始->备份库压缩->压缩库覆盖原始
yuanPath = "data.mdb" '修改原始名称
tempdays = Datediff("s","2011-11-11 11:11:11",formatdatetime(now,0))
backPath = yuanPath & "_bak_"&tempdays&".asa" '备份名称(原始备份)
tempPath = yuanPath & "_yak_"&tempdays&".asa" '压缩名称(压缩备份)
'得到绝对路径
oldPath = server.mappath(yuanPath)
bakPath = server.mappath(backPath)
newPath = server.mappath(tempPath)
set Fso=Server.CreateObject("Scripting.FileSystemObject")
Fso.CopyFile oldPath,bakPath '复制备份原始:原始复制一份
if Fso.FileExists(bakPath) then
Set Engine =Server.CreateObject("JRO.JetEngine")
'备份库压缩压缩
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & bakPath, _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & newPath
'备份库压缩压缩
Fso.CopyFile newPath,oldPath
'不删除压缩备份
'Fso.DeleteFile(newPath)
set Fso = nothing
set Engine = nothing
response.Write "成功:数据库已经压缩成功!"
else
response.Write "失败:检查数据库是否存在!"
end if
%>