?? bs_database.asp
字號(hào):
<%@ LANGUAGE=VBScript CodePage=936%>
<%
option explicit
response.buffer=true
Const strDBPath = "Databackup\"
%>
<!--#include file="bsconfig.asp"-->
<%
dim Action,FoundErr,ErrMsg
Action=trim(request("Action"))
dim dbpath
dim ObjInstalled
ObjInstalled=IsObjInstalled("Scripting.FileSystemObject")
%>
<!-- #include file="Inc/Head.asp" -->
<BR>
<table cellpadding="2" cellspacing="1" border="0" width="600" align="center" class="a2">
<tr>
<td class="a1" height="25" align="center" colspan="2"><strong>數(shù) 據(jù) 庫(kù) 管 理</strong></td>
</tr>
<tr class="a4">
<td width="75" height="30"> <strong>管理導(dǎo)航:</strong></td>
<td height="30"> <a href="Bs_Database.asp?Action=Backup">備份數(shù)據(jù)庫(kù)</a> | <a href="Bs_Database.asp?Action=Restore">恢復(fù)數(shù)據(jù)庫(kù)</a> | <a href="Bs_Database.asp?Action=Compact">壓縮數(shù)據(jù)庫(kù)</a> | <a href="Bs_Database.asp?Action=SpaceSize">系統(tǒng)空間占用情況</a>
</td>
</tr>
</table>
<BR>
<%
if Action="Backup" or Action="BackupData" then
call ShowBackup()
set conn=nothing
elseif Action="Compact" or Action="CompactData" then
call ShowCompact()
set conn=nothing
elseif Action="Restore" or Action="RestoreData" then
call ShowRestore()
set conn=nothing
elseif Action="SpaceSize" then
call SpaceSize()
set conn=nothing
else
FoundErr=True
ErrMsg=ErrMsg & "<br><li>錯(cuò)誤參數(shù)!</li>"
set conn=nothing
end if
if FoundErr=True then
call WriteErrMsg()
end if
'--------備份數(shù)據(jù)庫(kù)--------
sub ShowBackup()
%>
<table cellpadding="2" cellspacing="1" border="0" width="600" align="center" class="a2">
<form method="post" action="Bs_Database.asp?action=BackupData">
<tr>
<td colspan="3" align="center" height="25" class="a1"><FONT COLOR="#CC0000"><b>備 份 數(shù) 據(jù) 庫(kù)</b></FONT></td>
</tr>
<%
if request("action")="BackupData" then
call backupdata()
else
%>
<tr class="a4">
<td width="80" height="40" align="right">當(dāng)前數(shù)據(jù)庫(kù):</td>
<td><input name="db" type="text" size="40" value="<%=db%>"></td>
<td>相對(duì)路徑目錄</td>
</tr>
<tr class="a4">
<td width="80" height="40" align="right">備份目錄:</td>
<td><input type=text size=40 name=bkfolder value="Databackup"></td>
<td>相對(duì)路徑目錄,如目錄不存在,將自動(dòng)創(chuàng)建</td>
</tr>
<tr class="a4">
<td width="80" height="40" align="right">備份名稱:</td>
<td height="40"><input type=text size=40 name=bkDBname value="Bs_DataBack"></td>
<td height="40">不用輸入文件名后綴(默認(rèn)為“.asa”)。如有同名文件,將覆蓋</td>
</tr>
<tr class="a4">
<td height="40" colspan="3" align="center"><input name="submit" type=submit value=" 開(kāi)始備份 " <%If ObjInstalled=false Then response.Write "disabled"%> style="cursor: hand;background-color: #cccccc;"></td>
</tr>
<%
If ObjInstalled=false Then
Response.Write "<b><font color=red>你的服務(wù)器不支持 FSO(Scripting.FileSystemObject)! 不能使用本功能</font></b>"
end if
end if
%>
</form>
</table>
<%
end sub
'--------恢復(fù)數(shù)據(jù)庫(kù)--------
sub ShowRestore()
%>
<table cellpadding="2" cellspacing="1" border="0" width="600" align="center" class="a2">
<form method="post" action="Bs_Database.asp?action=RestoreData">
<tr>
<td colspan="2" align="center" height="25" class="a1"><FONT COLOR="#CC0000"><b>數(shù) 據(jù) 庫(kù) 恢 復(fù)</b></FONT></td>
</tr>
<%
if request("action")="RestoreData" then
call RestoreData()
else
%>
<tr class="a4">
<td width="150" height="40" align="right">備份數(shù)據(jù)庫(kù)路徑(相對(duì)):</td>
<td height="40"><input name=backpath type=text id="backpath" value="Databackup/Bs_DataBack.asa" size=50 maxlength="200"></td>
</tr>
<tr class="a4">
<td width="150" height="40" align="right">當(dāng)前數(shù)據(jù)庫(kù)路徑(相對(duì)):</td>
<td><input name="db" type="text" size="50" maxlength="200" value="<%=db%>"></td>
</tr>
<tr align="center" class="a4">
<td colspan="2"><input name="submit" type=submit value=" 恢復(fù)數(shù)據(jù) " <%If ObjInstalled=false Then Response.Write "disabled"%> style="cursor: hand;background-color: #cccccc;"></td>
</tr>
<%
If ObjInstalled=false Then
Response.Write "<b><font color=red>你的服務(wù)器不支持 FSO(Scripting.FileSystemObject)! 不能使用本功能</font></b>"
end if
end if
%>
</form>
</table>
<%
end sub
'--------壓縮數(shù)據(jù)庫(kù)--------
sub ShowCompact()
%>
<table cellpadding="2" cellspacing="1" border="0" width="600" align="center" class="a2">
<form method="post" action="Bs_Database.asp?action=CompactData">
<tr align="center">
<td class="a1" height="25"><FONT COLOR="#CC0000"><b>數(shù) 據(jù) 庫(kù) 在 線 壓 縮</b></FONT></td>
</tr>
<%
if request("action")="CompactData" then
call CompactData()
else
%>
<tr align="left" class="a4">
<td valign="middle" style="line-height: 150%"><br><font color="#FF6600"><b>注1:</b></font>壓縮前,建議先備份數(shù)據(jù)庫(kù),以免發(fā)生意外錯(cuò)誤。 <br>
<font color="#FF6600"><b>注2:</b></font>正在使用中數(shù)據(jù)庫(kù)不能壓縮,請(qǐng)選擇備份數(shù)據(jù)庫(kù)進(jìn)行壓縮操作(當(dāng)前壓縮數(shù)據(jù)庫(kù)名為默認(rèn)備份文件名)</td>
</tr>
<tr align="left" class="a4">
<td height="40">數(shù)據(jù)庫(kù)位置: <input name="db" type="text" id="db" size="50" value="Databackup/Bs_DataBack.asa"></td>
</tr>
<tr align="center" class="a4">
<td height="40"><input name="submit" type=submit value=" 壓縮數(shù)據(jù)庫(kù) " <%If ObjInstalled=false Then Response.Write "disabled"%> style="cursor: hand;background-color: #cccccc;"></td>
</tr>
<%
If ObjInstalled=false Then
Response.Write "<b><font color=red>你的服務(wù)器不支持 FSO(Scripting.FileSystemObject)! 不能使用本功能</font></b>"
end if
end if
%>
</form>
</table>
<%
end sub
'--------統(tǒng)空間占用情況--------
sub SpaceSize()
on error resume next
%>
<table cellpadding="2" cellspacing="1" border="0" width="600" align="center" class="a2">
<tr>
<td colspan="2" align="center" height="25" class="a1"><FONT COLOR="#CC0000"><b>系 統(tǒng) 空 間 占 用 情 況</b></FONT></td>
</tr>
<tr class="a4">
<td width="100%" height="150" valign="middle">
<blockquote><br>
系統(tǒng)數(shù)據(jù)占用空間: <img src="images/bar.gif" width=<%=drawbar("../database")%> height=10>
<%showSpaceinfo("../database")%>
<br>
<br>
備份數(shù)據(jù)占用空間: <img src="images/bar.gif" width=<%=drawbar("databackup")%> height=10>
<%showSpaceinfo("databackup")%>
<br>
<br>
程序文件占用空間: <img src="images/bar.gif" width=<%=drawspecialbar%> height=10>
<%showSpecialSpaceinfo("Program")%>
<br>
<br>
配色模板占用空間: <img src="images/bar.gif" width=<%=drawbar("../Skin")%> height=10>
<%showSpaceinfo("../Images")%>
<br>
<br>
系統(tǒng)圖片占用空間: <img src="images/bar.gif" width=<%=drawbar("../Img")%> height=10>
<%showSpaceinfo("../Img")%>
<br>
<br>
上傳文件占用空間: <img src="images/bar.gif" width=<%=drawbar("../UploadFiles")%> height=10>
<%showSpaceinfo("../UploadFiles")%>
<br>
<br>
系統(tǒng)占用空間總計(jì):<BR><BR><img src="images/bar.gif" width=400 height=10>
<%showspecialspaceinfo("All")%>
</blockquote>
</td>
</tr>
</table>
<%
end sub
%>
<BR>
<%htmlend%>
<%
'--------備份數(shù)據(jù)庫(kù)--------
sub BackupData()
dim bkfolder,bkdbname,fso
db=trim(request.form("db"))
bkfolder=trim(request("bkfolder"))
bkdbname=trim(request("bkdbname"))
if db="" then
FoundErr=True
ErrMsg=ErrMsg & "<br><li>請(qǐng)指定當(dāng)數(shù)據(jù)庫(kù)位置!</li>"
end if
if bkfolder="" then
FoundErr=True
ErrMsg=ErrMsg & "<br><li>請(qǐng)指定備份目錄!</li>"
end if
if bkdbname="" then
FoundErr=True
ErrMsg=ErrMsg & "<br><li>請(qǐng)指定備份文件名</li>"
end if
if FoundErr=True then exit sub
dbpath = server.mappath(db)
bkfolder=server.MapPath(bkfolder)
Set Fso=server.createobject("scripting.filesystemobject")
if fso.FileExists(dbpath) then
If fso.FolderExists(bkfolder)=false Then
fso.CreateFolder(bkfolder)
end if
fso.copyfile dbpath,bkfolder & "\" & bkdbname & ".asa"
response.write "<center>備份數(shù)據(jù)庫(kù)成功,備份的數(shù)據(jù)庫(kù)為 " & bkfolder & "\" & bkdbname & ".asa</center>"
Else
response.write "<center>找不到源數(shù)據(jù)庫(kù)文件,請(qǐng)檢查inc/conn.asp中的配置。</center>"
End if
end sub
'--------恢復(fù)數(shù)據(jù)庫(kù)--------
sub RestoreData()
dim backpath,fso
backpath=request.form("backpath")
db=trim(request.form("db"))
if backpath="" then
FoundErr=True
ErrMsg=ErrMsg & "<br><li>請(qǐng)指定原備份的數(shù)據(jù)庫(kù)文件名!<li>"
exit sub
end if
if db="" then
FoundErr=True
ErrMsg=ErrMsg & "<br><li>請(qǐng)指定當(dāng)前數(shù)據(jù)庫(kù)文件名!<li>"
exit sub
end if
backpath=server.mappath(backpath)
dbpath = server.mappath(db)
Set Fso=server.createobject("scripting.filesystemobject")
if fso.fileexists(backpath) then
fso.copyfile Backpath,dbpath
response.write "成功恢復(fù)數(shù)據(jù)!"
else
response.write "找不到指定的備份文件!"
end if
end sub
'--------壓縮數(shù)據(jù)庫(kù)--------
sub CompactData()
Dim fso, Engine,strDBPath
DB=trim(request.form("db"))
DBPath = server.mappath(DB)
' strDBPath = server.mappath("data_backup\")
if instr(DBPath,"/") then
strDBPath = left(DBPath,instrrev(DBPath,"\"))
else
strDBPath = left(DBPath,instrrev(DBPath,"\"))
end if
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 "數(shù)據(jù)庫(kù)壓縮成功!"
Else
response.write "數(shù)據(jù)庫(kù)沒(méi)有找到!"
End If
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 "<font face=verdana>" & showsize & "</font>"
End Sub
Sub Showspecialspaceinfo(method)
dim fso,d,fc,f1,size,showsize,drvpath
set fso=server.createobject("scripting.filesystemobject")
drvpath=server.mappath("../Inc")
drvpath=left(drvpath,(instrrev(drvpath,"\")-1))
set d=fso.getfolder(drvpath)
if method="All" then
size=d.size
elseif method="Program" then
set fc=d.Files
for each f1 in fc
size=size+f1.size
next
end if
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 "<font face=verdana>" & showsize & "</font>"
end sub
Function Drawbar(drvpath)
dim fso,drvpathroot,d,size,totalsize,barsize
set fso=server.createobject("scripting.filesystemobject")
drvpathroot=server.mappath("../Inc")
drvpathroot=left(drvpathroot,(instrrev(drvpathroot,"\")-1))
set d=fso.getfolder(drvpathroot)
totalsize=d.size
drvpath=server.mappath(drvpath)
set d=fso.getfolder(drvpath)
size=d.size
barsize=cint((size/totalsize)*400)
Drawbar=barsize
End Function
Function Drawspecialbar()
dim fso,drvpathroot,d,fc,f1,size,totalsize,barsize
set fso=server.createobject("scripting.filesystemobject")
drvpathroot=server.mappath("../Inc")
drvpathroot=left(drvpathroot,(instrrev(drvpathroot,"\")-1))
set d=fso.getfolder(drvpathroot)
totalsize=d.size
set fc=d.files
for each f1 in fc
size=size+f1.size
next
barsize=cint((size/totalsize)*400)
Drawspecialbar=barsize
End Function
%>
<%
'**************************************************
'函數(shù)名:IsObjInstalled
'作 用:檢查組件是否已經(jīng)安裝
'參 數(shù):strClassString ----組件名
'返回值:True ----已經(jīng)安裝
' False ----沒(méi)有安裝
'**************************************************
Function IsObjInstalled(strClassString)
On Error Resume Next
IsObjInstalled = False
Err = 0
Dim xTestObj
Set xTestObj = Server.CreateObject(strClassString)
If 0 = Err Then IsObjInstalled = True
Set xTestObj = Nothing
Err = 0
End Function
'------------------檢查某一目錄是否存在-------------------
Function CheckDir(FolderPath)
dim fso
folderpath=Server.MapPath(".")&"\"&folderpath
Set fso1 = Server.CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(FolderPath) then
'存在
CheckDir = True
Else
'不存在
CheckDir = False
End if
Set fso = nothing
End Function
'-------------根據(jù)指定名稱生成目錄---------
Function MakeNewsDir(foldername)
dim fso,f
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateFolder(foldername)
MakeNewsDir = True
Set fso = nothing
End Function
'**************************************************
'過(guò)程名:WriteErrMsg
'作 用:顯示錯(cuò)誤提示信息
'參 數(shù):無(wú)
'**************************************************
sub WriteErrMsg()
dim strErr
strErr=strErr & "<html><head><title>錯(cuò)誤信息</title><meta http-equiv='Content-Type'content='text/html; charset=gb2312'>" & vbcrlf
strErr=strErr & "<link href='style.css'rel='stylesheet'type='text/css'></head><body><br><br>" & vbcrlf
strErr=strErr & "<table cellpadding=2 cellspacing=1 border=0 width=400 class='border' align=center>" & vbcrlf
strErr=strErr & " <tr align='center' class='title'><td height='22'><strong>錯(cuò)誤信息</strong></td></tr>" & vbcrlf
strErr=strErr & " <tr class='tdbg'><td height='100'valign='top'><b>產(chǎn)生錯(cuò)誤的可能原因:</b>" & errmsg &"</td></tr>" & vbcrlf
strErr=strErr & " <tr align='center' class='tdbg'><td><a href='javascript:history.go(-1)'><< 返回上一頁(yè)</a></td></tr>" & vbcrlf
strErr=strErr & "</table>" & vbcrlf
strErr=strErr & "</body></html>" & vbcrlf
response.write strErr
end sub
%>
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -