asp 在線備份與恢復(fù)sqlserver數(shù)據(jù)庫(kù)的代碼
更新時(shí)間:2010年07月12日 21:38:33 作者:
asp 在線備份 恢復(fù) sql server 數(shù)據(jù)庫(kù),對(duì)于遠(yuǎn)程沒(méi)有提供sqlserver遠(yuǎn)程連接或打包下載的朋友是個(gè)臨時(shí)解決方法,對(duì)于大數(shù)據(jù)來(lái)說(shuō)可能效果不好。
asp在線備份sql server數(shù)據(jù)庫(kù):
1、備份sqlserver
<%
SQL="backup database 數(shù)據(jù)庫(kù)名 to disk='"&Server.MapPath("backup")&"\"&"backuptext.dat"&"'"
set cnn=Server.createobject("adodb.connection")
cnn.open "driver={SQL Server};Server=服務(wù)器名;uid=sa;pwd="
cnn.execute SQL
on error resume next
if err<>0 then
response.wrITe "錯(cuò)誤:"&err.Descripting
else
response.wrITe "數(shù)據(jù)備份成功!"
end if
%>
2、恢復(fù)sqlserver
<%
SQL="Restore database 數(shù)據(jù)庫(kù)名 from disk='"&Server.MapPath("backup")&"\"&"backuptext.dat"&"'"
set cnn=Server.createobject("adodb.connection")
cnn.open "driver={SQL Server};Server=服務(wù)器名;uid=sa;pwd="
cnn.execute SQL
on error resume next
if err<>0 then
response.wrITe "錯(cuò)誤:"&err.Descripting
else
response.wrITe "數(shù)據(jù)恢復(fù)成功!"
end if
%>
ACCESS原理一樣
<%
'*****************************************
function CopyTo(ByVal cFile,ByVal toFile)
cFile=Server.MapPath(cFile) ‘所要備份的文件
toFile=Server.MapPath(toFile) ‘備份文件
Dim cFso,cf
set cFso=Server.CreateObject("Scripting.FileSystemObject")
cFso.fileexists(cFile)
cFso.Copyfile cFile,toFile
end function
'*********************************************
' ASP實(shí)現(xiàn)備份及恢復(fù)ACCESS數(shù)據(jù)庫(kù)操作
'本頁(yè)面為 databackup.asp
dim dbpath,bkfolder,bkdbname,fso,fso1
call main()
call main2()
conn.close
set conn=nothing
sub main()
if request("action")="Backup" then
call backupdata()
else
%>
<table cellspacing=1 cellpadding=1 align=center width="90%">
<tr>
<th height=25 >
<B>數(shù)據(jù)庫(kù)備份</B>
</th>
</tr>
<form method="post" action="databackup.asp?action=Backup">
<tr>
<td height=100 style="line-height:150%">
當(dāng)前數(shù)據(jù)庫(kù)路徑(相對(duì)路徑):
<input type=text size=15 name=DBpath value="../mdb/database.mdb"><BR>
備份數(shù)據(jù)庫(kù)目錄(相對(duì)路徑):
<input type=text size=15 name=bkfolder value=../Databackup> 如目錄不存在,程序?qū)⒆詣?dòng)創(chuàng)建<BR>
備份數(shù)據(jù)庫(kù)名稱(填寫(xiě)名稱):
<input type=text size=15 name=bkDBname value=database.mdb> 如備份目錄有該
文件,將覆蓋,如沒(méi)有,將自動(dòng)創(chuàng)建<BR>
<input type=submIT value="備份數(shù)據(jù)"><hr align="center" width="90%" color="#999999"></td>
</tr>
</form>
</table>
<%
end if
end sub
sub main2()
if request("action")="Restore" then
Dbpath=request.form("Dbpath")
backpath=request.form("backpath")
if dbpath="" then
response.wrITe "請(qǐng)輸入您要恢復(fù)成的數(shù)據(jù)庫(kù)全名"
else
Dbpath=server.mappath(Dbpath)
end if
backpath=server.mappath(backpath)
Response.wrITe Backpath
Set Fso=server.createobject("scripting.filesystemobject")
if fso.fileexists(dbpath) then
fso.copyfile Dbpath,Backpath
response.wrITe "<font color=red>成功恢復(fù)數(shù)據(jù)!</font>"
else
response.wrITe "<font color=red>備份目錄下并無(wú)您的備份文件!</font>"
end if
else
%>
<table align=center cellspacing=1 cellpadding=1 width="90%">
<tr>
<th height=25 >
<B>恢復(fù)數(shù)據(jù)庫(kù)</B>
</th>
</tr>
<form method="post" action="databackup.asp?action=Restore">
<tr>
<td height=100 >
備份數(shù)據(jù)庫(kù)路徑(相對(duì)):
<input type=text size=30 name=DBpath value="../Databackup/database.mdb"> <BR>
當(dāng)前數(shù)據(jù)庫(kù)路徑(相對(duì)):
<input type=text size=30 name=backpath value="../mdb/database.mdb"><BR>
<input type=submIT value="恢復(fù)數(shù)據(jù)"> <hr width="90%" align="center" color="#999999">
<font color="#666666">·注意:所有路徑都是相對(duì)路徑 </font></td>
</tr>
</form>
</table>
<%
end if
end sub
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 "<font color=red>備份數(shù)據(jù)庫(kù)成功,您備份的數(shù)據(jù)庫(kù)路徑為" &bkfolder& "\\"& bkdbname+"</font>"
Else
response.wrITe "<font color=red>找不到您所需要備份的文件。</font>"
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
'-------------根據(jù)指定名稱生成目錄---------
Function MakeNewsDir(foldername)
dim f
Set fso1 = CreateObject("Scripting.FileSystemObject")
Set f = fso1.CreateFolder(foldername)
MakeNewsDir = True
Set fso1 = nothing
End Function
%>
1、備份sqlserver
復(fù)制代碼 代碼如下:
<%
SQL="backup database 數(shù)據(jù)庫(kù)名 to disk='"&Server.MapPath("backup")&"\"&"backuptext.dat"&"'"
set cnn=Server.createobject("adodb.connection")
cnn.open "driver={SQL Server};Server=服務(wù)器名;uid=sa;pwd="
cnn.execute SQL
on error resume next
if err<>0 then
response.wrITe "錯(cuò)誤:"&err.Descripting
else
response.wrITe "數(shù)據(jù)備份成功!"
end if
%>
2、恢復(fù)sqlserver
復(fù)制代碼 代碼如下:
<%
SQL="Restore database 數(shù)據(jù)庫(kù)名 from disk='"&Server.MapPath("backup")&"\"&"backuptext.dat"&"'"
set cnn=Server.createobject("adodb.connection")
cnn.open "driver={SQL Server};Server=服務(wù)器名;uid=sa;pwd="
cnn.execute SQL
on error resume next
if err<>0 then
response.wrITe "錯(cuò)誤:"&err.Descripting
else
response.wrITe "數(shù)據(jù)恢復(fù)成功!"
end if
%>
ACCESS原理一樣
復(fù)制代碼 代碼如下:
<%
'*****************************************
function CopyTo(ByVal cFile,ByVal toFile)
cFile=Server.MapPath(cFile) ‘所要備份的文件
toFile=Server.MapPath(toFile) ‘備份文件
Dim cFso,cf
set cFso=Server.CreateObject("Scripting.FileSystemObject")
cFso.fileexists(cFile)
cFso.Copyfile cFile,toFile
end function
'*********************************************
' ASP實(shí)現(xiàn)備份及恢復(fù)ACCESS數(shù)據(jù)庫(kù)操作
'本頁(yè)面為 databackup.asp
dim dbpath,bkfolder,bkdbname,fso,fso1
call main()
call main2()
conn.close
set conn=nothing
sub main()
if request("action")="Backup" then
call backupdata()
else
%>
<table cellspacing=1 cellpadding=1 align=center width="90%">
<tr>
<th height=25 >
<B>數(shù)據(jù)庫(kù)備份</B>
</th>
</tr>
<form method="post" action="databackup.asp?action=Backup">
<tr>
<td height=100 style="line-height:150%">
當(dāng)前數(shù)據(jù)庫(kù)路徑(相對(duì)路徑):
<input type=text size=15 name=DBpath value="../mdb/database.mdb"><BR>
備份數(shù)據(jù)庫(kù)目錄(相對(duì)路徑):
<input type=text size=15 name=bkfolder value=../Databackup> 如目錄不存在,程序?qū)⒆詣?dòng)創(chuàng)建<BR>
備份數(shù)據(jù)庫(kù)名稱(填寫(xiě)名稱):
<input type=text size=15 name=bkDBname value=database.mdb> 如備份目錄有該
文件,將覆蓋,如沒(méi)有,將自動(dòng)創(chuàng)建<BR>
<input type=submIT value="備份數(shù)據(jù)"><hr align="center" width="90%" color="#999999"></td>
</tr>
</form>
</table>
<%
end if
end sub
sub main2()
if request("action")="Restore" then
Dbpath=request.form("Dbpath")
backpath=request.form("backpath")
if dbpath="" then
response.wrITe "請(qǐng)輸入您要恢復(fù)成的數(shù)據(jù)庫(kù)全名"
else
Dbpath=server.mappath(Dbpath)
end if
backpath=server.mappath(backpath)
Response.wrITe Backpath
Set Fso=server.createobject("scripting.filesystemobject")
if fso.fileexists(dbpath) then
fso.copyfile Dbpath,Backpath
response.wrITe "<font color=red>成功恢復(fù)數(shù)據(jù)!</font>"
else
response.wrITe "<font color=red>備份目錄下并無(wú)您的備份文件!</font>"
end if
else
%>
<table align=center cellspacing=1 cellpadding=1 width="90%">
<tr>
<th height=25 >
<B>恢復(fù)數(shù)據(jù)庫(kù)</B>
</th>
</tr>
<form method="post" action="databackup.asp?action=Restore">
<tr>
<td height=100 >
備份數(shù)據(jù)庫(kù)路徑(相對(duì)):
<input type=text size=30 name=DBpath value="../Databackup/database.mdb"> <BR>
當(dāng)前數(shù)據(jù)庫(kù)路徑(相對(duì)):
<input type=text size=30 name=backpath value="../mdb/database.mdb"><BR>
<input type=submIT value="恢復(fù)數(shù)據(jù)"> <hr width="90%" align="center" color="#999999">
<font color="#666666">·注意:所有路徑都是相對(duì)路徑 </font></td>
</tr>
</form>
</table>
<%
end if
end sub
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 "<font color=red>備份數(shù)據(jù)庫(kù)成功,您備份的數(shù)據(jù)庫(kù)路徑為" &bkfolder& "\\"& bkdbname+"</font>"
Else
response.wrITe "<font color=red>找不到您所需要備份的文件。</font>"
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
'-------------根據(jù)指定名稱生成目錄---------
Function MakeNewsDir(foldername)
dim f
Set fso1 = CreateObject("Scripting.FileSystemObject")
Set f = fso1.CreateFolder(foldername)
MakeNewsDir = True
Set fso1 = nothing
End Function
%>
您可能感興趣的文章:
- sqlserver數(shù)據(jù)庫(kù)加密后無(wú)法使用MDF,LDF,log文件名稱被修改的數(shù)據(jù)恢復(fù)
- SQLServer數(shù)據(jù)庫(kù)處于恢復(fù)掛起狀態(tài)的解決辦法
- 刪除sqlserver數(shù)據(jù)庫(kù)日志和沒(méi)有日志的數(shù)據(jù)庫(kù)恢復(fù)辦法
- SQLServer2005 沒(méi)有日志文件(*.ldf) 只有數(shù)據(jù)文件(*.mdf) 恢復(fù)數(shù)據(jù)庫(kù)的方法
- 設(shè)置密碼保護(hù)的SqlServer數(shù)據(jù)庫(kù)備份文件與恢復(fù)文件的方法
- 數(shù)據(jù)庫(kù)備份 SQLServer的備份和災(zāi)難恢復(fù)
- sqlserver 數(shù)據(jù)庫(kù)日志備份和恢復(fù)步驟
- 如何強(qiáng)制刪除或恢復(fù)SQLServer正在使用的數(shù)據(jù)庫(kù)
- SQLServer數(shù)據(jù)庫(kù)誤操作恢復(fù)的方法
相關(guān)文章
用ASP和SQL實(shí)現(xiàn)基于Web的事件日歷
用ASP和SQL實(shí)現(xiàn)基于Web的事件日歷...2006-09-09
為什么ASP中執(zhí)行動(dòng)態(tài)SQL總報(bào)錯(cuò)誤信息?提示語(yǔ)句語(yǔ)法錯(cuò)誤
為什么ASP中執(zhí)行動(dòng)態(tài)SQL總報(bào)錯(cuò)誤信息?提示語(yǔ)句語(yǔ)法錯(cuò)誤...2007-04-04
Asp Oracle存儲(chǔ)過(guò)程返回結(jié)果集的代碼
對(duì)于 Oracle 這個(gè)龐然大物,Asp使用起來(lái),確實(shí)是捉襟見(jiàn)肘的 。 尤其是要返回結(jié)果集(Recordset)的情況,更是讓很多人犯難。2008-11-11
asp獲取數(shù)據(jù)庫(kù)中表名和字段名的代碼
今天冒出來(lái)一個(gè)想法,在僅知道數(shù)據(jù)庫(kù)名的情況下,用asp得到數(shù)據(jù)庫(kù)中的所有表名、所有表的字段名、以及所有字段中的內(nèi)容。經(jīng)過(guò)一段時(shí)間查詢資料和修改,終于做出來(lái)了,現(xiàn)在與大家分享。2008-09-09
asp 在線備份與恢復(fù)sqlserver數(shù)據(jù)庫(kù)的代碼
asp 在線備份 恢復(fù) sql server 數(shù)據(jù)庫(kù),對(duì)于遠(yuǎn)程沒(méi)有提供sqlserver遠(yuǎn)程連接或打包下載的朋友是個(gè)臨時(shí)解決方法,對(duì)于大數(shù)據(jù)來(lái)說(shuō)可能效果不好。2010-07-07

