<%if Session("weight")<>5 then 
Response.Redirect "error.asp?cause=4"
 end if
%><html>
<head>
<link rel="stylesheet" href="index.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>数据库备份</title>
</head>
<body bgcolor="#ffffff">
<table cellpadding=0 cellspacing=0 border=0 width=100% align=center>
  <tr>
    <td>
      <table cellpadding=3 cellspacing=1 border=0 width=100%>
            <tr>
              <td width="100%" valign=top>
<%
	if request("action")="Backup" then
	call backupdata()
	else
%>
		 		<table width=100% cellspacing=0 cellpadding=0>		  							  				
  				<tr>
  					<td height=25 >
  					
                                    <p align="center"><font color="red">此功能需要FSO组件支持</font>
  					</td>
  				</tr>
  				<form method="post" action="Backup.asp?action=Backup">
  				<tr>
  					<td height=100 >
  						&nbsp;&nbsp;
						当前数据库路径(相对路径)：<input type=text size=15 name=DBpath value="..\db\sjxffriend.asa"><BR>&nbsp;&nbsp;
						备份数据库目录(相对路径)：<input type=text size=15 name=bkfolder value="..\Databackup">&nbsp;如目录不存在，程序将自动创建<BR>&nbsp;&nbsp;
						备份数据库名称(填写名称)：<input type=text size=15 name=bkDBname value="sjxffriend.asa">&nbsp;如备份目录有该文件，将覆盖，如没有，将自动创建<BR>
						&nbsp;&nbsp;<input type=submit value="备份"><br>
  						-------------------------------------------------------------------<br>
  						&nbsp;&nbsp;在上面填写本程序的数据库路径全名，本程序的默认数据库文件为mdb\data.asa<br>
  						&nbsp;&nbsp;您可以用这个功能来备份您的法规数据，以保证您的数据安全！<br>
  						&nbsp;&nbsp;注意：所有路径都是相对与程序空间根目录的相对路径				
  					</td>
  				</tr>	
  				</form>
  			</table>
<%end if%>
          </td>
                    <td>&nbsp;</td>
            </tr>
        </table>
        </td>
    </tr>
</table>

<%


sub backupdata()
		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
		Else
			response.write "找不到您所需要备份的文件。"
		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)
    Set fso1 = CreateObject("Scripting.FileSystemObject")
        Set f = fso1.CreateFolder(foldername)
        MakeNewsDir = True
    Set fso1 = nothing
End Function
%>