<!-- #include file="include/onlogin.asp" -->
<!-- #include file="include/conn.asp" -->
<%
tit="<a href='admin_sql.asp'>执行SQL</a> | " & _
      "<a href='admin_datamanage.asp?action=BackupData'>备份数据库</a> | " & _
      "<a href='admin_datamanage.asp?action=CompressData'>压缩数据库</a> | " & _
      "<a href='admin_datamanage.asp?action=RestoreData'>恢复数据库</a>"
response.write header(10,tit)

dim dbpath,bkfolder,bkdbname,fso,fso1
select case action
case "CompressData"
  titt="压缩数据库"
case "BackupData"
  titt="备份数据库"
case else
  titt="恢复数据库"
end select

response.write admin_bar(titt,1,"99%")
select case action
case "CompressData"
		if request("act")="Compress" then
		call CompactDB()
		else
		dim tmprs
		dim allarticle
		dim Maxid
		dim topic,username,dateandtime,body
		call CompressData()
		end if

case "BackupData"
		if request("act")="Backup" then
		call updata()
		else
		call BackupData()
		end if

case "RestoreData"
dim backpath
		if request("act")="Restore" then
		call restore()
		else
		call RestoreData()
		end if
end select

conn.close
set conn=nothing
response.write admin_bar("",2,"99%")
response.write ender()

'====================恢复数据库=========================
sub RestoreData()
%>
<table width='90%' border=0 align=center cellpadding=2 cellspacing=1>
<p><b>本功能需要FSO支持，FSO相关帮助请看微软网站</b></p>
<form method="post" action="admin_datamanage.asp?action=RestoreData&act=Restore">
<tr class=tdbg-tree><td width="100%" align="center" height="30" valign="middle" ><B>恢复备份数据库</B></td></tr>
<tr class=tdbg-dark><td height=90>
备份数据库路径(相对)：<input type=text size=40 name=DBpath value="databackup\<%=date()%>.asp">&nbsp;&nbsp;<BR>
目标数据库路径(相对)：<input type=text size=40 name="backpath" value="<%=objv7.web_var(web_config,6)%>">

</td></tr>
<tr class=tdbg-dark><td>&nbsp;&nbsp;&nbsp;<b>注意：</b><br>
&nbsp;&nbsp;&nbsp;● <b>默认情况下目标数据库为当前系统数据库，也可使用新名称自行命名（需修改conn.asp文件）</b><br>
&nbsp;&nbsp;&nbsp;● 所有路径都是相对于程序空间根目录的相对路径<br>
&nbsp;&nbsp;&nbsp;● 您可以用这个功能来备份您的法规数据，以保证您的数据安全！<br>
</td></tr>
<tr class=tdbg-dark><td align=center>
<input type=submit value="恢 复 数 据">
</td></tr></form>
</table>
<%
end sub

sub restore()
			Dbpath=request.form("Dbpath")
			backpath=request.form("backpath")
			if dbpath="" then
			response.write "请输入备份数据库的路径和全名<br><br>"	
			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 "<font color='#FF0000'><b>数据库已成功恢复！</b></font><br><br><a href='javascript:history.back(-1)'><<返回上一页</a>"
			else
			response.write "<font color='#FF0000'><b>没有找到备份数据库文件！</b></font><br><br><a href='javascript:history.back(-1)'><<返回上一页</a>"	
			end if
end sub

'====================备份数据库=========================
sub BackupData()
%>
<table width='90%' border=0 align=center cellpadding=2 cellspacing=1>
<p><b>本功能需要FSO支持，FSO相关帮助请看微软网站</b></p>
<form method="post" action="admin_datamanage.asp?action=BackupData&act=Backup">
<tr class=tdbg-dark><td>
当前数据库地址(相对路径)：<input type=text size=40 name=dbpath value="<%=objv7.web_var(web_config,6)%>"><BR>
备份数据库目录(相对路径)：<input type=text size=30 name=bkfolder value=databackup>&nbsp;如目录不存在，程序将自动创建<BR>
备份数据库名称(文件全名)：<input type=text size=30 name=bkDBname value="<%=date()%>.asp">&nbsp;如该文件存在将会被覆盖，如没有将自动创建<BR>
</td></tr>
<tr class=tdbg-dark><td>&nbsp;&nbsp;&nbsp;<b>注意：</b><br>
&nbsp;&nbsp;&nbsp;● 所有路径都是相对于程序空间根目录的相对路径<br>
&nbsp;&nbsp;&nbsp;● <b>请尽量避免使用 .mdb 的后缀名命名备份数据库</b><br>
&nbsp;&nbsp;&nbsp;● 您可以用这个功能来备份您的法规数据，以保证您的数据安全！<br>
</td></tr>
<tr class=tdbg-dark><td align=center>
<input type=submit value="开 始 备 份">
</td></tr></form>
</table>
<%
end sub

sub updata()
	    dbpath=server.mappath(request.form("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 "<font color='#FF0000'><b>备份数据库成功！</b></font> 您备份的数据库地址为：<br><br>" &bkfolder& "\"& bkdbname &"<br><br><a href='javascript:history.back(-1)'><<返回上一页</a>"
		Else
			response.write "找不到您所需要备份的数据库文件。<br><br><a href='javascript:history.back(-1)'><<返回上一页</a>"
		End if
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 CompressData()
%>
<table width='90%' border=0 align=center cellpadding=2 cellspacing=1>
<p><b>本功能需要FSO支持，FSO相关帮助请看微软网站</b></p>
<form action="admin_datamanage.asp?action=CompressData&act=Compress" method="post">
<tr class=tdbg-dark><td>
压缩数据库地址(相对路径)：<input type="text" name="dbpath" value='databackup\<%=date()%>.asp' size=40><br><br><br>
<b>注意：</b>正在使用中的数据库不能压缩，请选择备份数据库进行压缩操作
</td></tr>
<tr class=tdbg-dark><td align=center>
<input type=submit value="开 始 压 缩">
</td></tr></form>
</table>
<%
end sub

'=====================压缩参数=========================
Function CompactDB()
	Dim Engine, strDBPath
	dbpath=server.mappath(request.form("dbpath"))
	strDBPath = left(dbPath,instrrev(DBPath,"\"))
	Set fso = Server.CreateObject("Scripting.FileSystemObject")
	If fso.FileExists(dbPath) Then
		Set Engine = CreateObject("JRO.JetEngine")
		Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath," Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb"
		fso.CopyFile strDBPath & "temp.mdb",dbpath
		fso.DeleteFile(strDBPath & "temp.mdb")
		Set fso = nothing
		Set Engine = nothing
		response.write "<font color=#FF0000><b>数据库压缩成功！</b></font> 您压缩的数据库地址为：<br><br>" & dbpath &"<br><br><a href='javascript:history.back(-1)'><<返回上一页</a>"
	Else
		response.write "<font color=#FF0000><b>数据库没有找到！</b></font><br><br><a href='javascript:history.back(-1)'><<返回上一页</a>"
	End If
End Function 	
%>