Asp online backup SQL server database:
1. Back up sqlserver
Copy codeThe Code is as follows: <%
SQL = "backup database name to disk = '" & Server. MapPath ("backup") & "\" & "backuptext. dat "&"'"
Set cnn = Server. createobject ("adodb. connection ")
Cnn. open "driver = {SQL Server}; Server = Server name; uid = sa; pwd ="
Cnn.exe cute SQL
On error resume next
If err <> 0 then
Response. wrITe "error:" & err. Descripting
Else
Response. wrITe "Data Backup successful! "
End if
%>
2. Restore sqlserverCopy codeThe Code is as follows: <%
SQL = "Restore database name from disk = '" & Server. MapPath ("backup") & "\" & "backuptext. dat "&"'"
Set cnn = Server. createobject ("adodb. connection ")
Cnn. open "driver = {SQL Server}; Server = Server name; uid = sa; pwd ="
Cnn.exe cute SQL
On error resume next
If err <> 0 then
Response. wrITe "error:" & err. Descripting
Else
Response. wrITe "data recovery successful! "
End if
%>
The same principle of ACCESSCopy codeThe Code is as follows: <%
'*************************************** **
Function CopyTo (ByVal cFile, ByVal toFile)
CFile = Server. MapPath (cFile) 'file to be backed up
ToFile = Server. MapPath (toFile) 'backup File
Dim cFso, cf
Set cFso = Server. CreateObject ("Scripting. FileSystemObject ")
CFso. fileexists (cFile)
CFso. Copyfile cFile, toFile
End function
'*************************************** ******
'Asp: Back up and restore the ACCESS database
'This page is 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> Database Backup </B>
</Th>
</Tr>
<Form method = "post" action = "databackup. asp? Action = Backup ">
<Tr>
<Td height = 100 style = "line-height: 150%">
Current Database path (relative path ):
<Input type = text size = 15 name = DBpath value = "../mdb/database. mdb"> <BR>
Backup database directory (relative path ):
<Input type = text size = 15 name = bkfolder value = ../Databackup> If the directory does not exist, the program is automatically created. <BR>
Backup Database Name (enter the name ):
<Input type = text size = 15 name = bkDBname value = database. mdb> If the Backup Directory has
The file will be overwritten. If not, it will be automatically created <BR>
<Input type = submIT value = "Backup Data"> </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 "Enter the full name of the database to be restored"
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> data is successfully restored! </Font>"
Else
Response. wrITe "<font color = red> no backup file exists in the backup directory! </Font>"
End if
Else
%>
<Table align = center cellspacing = 1 cellpadding = 1 width = "90%">
<Tr>
<Th height = 25>
<B> restore a database </B>
</Th>
</Tr>
<Form method = "post" action = "databackup. asp? Action = Restore ">
<Tr>
<Td height = 100>
Backup database path (relative ):
<Input type = text size = 30 name = DBpath value = ".../Databackup/database. mdb"> <BR>
Current Database path (relative ):
<Input type = text size = 30 name = backpath value = "../mdb/database. mdb"> <BR>
<Input type = submIT value = "recover data"> <Font color = "#666666"> · Note: All paths are relative paths </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> the database is successfully backed up. The path of the database you backed up is" & bkfolder & "\" & bkdbname + "</font>"
Else
Response. wrITe "<font color = red> the file to be backed up cannot be found. </Font>"
End if
End sub
'---------------- Check whether a directory exists -------------------
Function CheckDir (FolderPath)
Folderpath = Server. MapPath (".") & "\" & folderpath
Set fso1 = CreateObject ("Scripting. FileSystemObject ")
If fso1.FolderExists (FolderPath) then
'Exist
CheckDir = True
Else
'Does not exist
CheckDir = False
End if
Set fso1 = nothing
End Function
'------------- Generate the directory --------- Based on the specified name ---------
Function MakeNewsDir (foldername)
Dim f
Set fso1 = CreateObject ("Scripting. FileSystemObject ")
Set f = fso1.CreateFolder (foldername)
MakeNewsDir = True
Set fso1 = nothing
End Function
%>