ASP Database Backup Code

Source: Internet
Author: User
Tags error code microsoft sql server trim microsoft website
The code is as follows Copy Code

<%
Server.ScriptTimeout = 99999
Admin_header
' Response.Write ' <body oncontextmenu= "return false" "Ondragstart=" "return false" "Onselectstart=" "return false" > "
'=====================================================================
' Software name: New Cloud Website Management system
' Current version: Newcloud Site Management System version 2.1
' File name: admin_database.asp
' Update Date: 2004-11-20

'=====================================================================
' Copyright 2002-2005 newasp.net-all Rights Reserved.
' Newasp is a trademark of newasp.net
'=====================================================================
Dim Bkfolder, Bkdbname, FSO, FSO1
Dim Action
Action = LCase (Request ("action")

Select Case Action


Case "Renamedata" database renamed


If not Chkadmin ("Renamedata") Then


Server.Transfer ("showerr.asp")


Request.end


End If


Call Renamedata ()


Case "Backupdata" Backup data


If not Chkadmin ("Backupdata") Then


Server.Transfer ("showerr.asp")


Request.end


End If


If Request ("act") = "Backup" Then


If issqldatabase = 1 Then


Call Backupsqldatabase ()


Else


Call BackupDatabase ()


End If


Else


Call Backupdata ()


End If


Case "Compressdata" ' compressed data


If not Chkadmin ("Compressdata") Then


Server.Transfer ("showerr.asp")


Request.end


End If


If Request ("act") = "Compress" Then


Call Compressdatabase ()


Else


Call Compressdata ()


End If


Case "Restoredata" ' recovery data


If not Chkadmin ("Restoredata") Then


Server.Transfer ("showerr.asp")


Request.end


End If


If Request ("act") = "Restore" Then


If issqldatabase = 1 Then


Call Restoresqldatabase ()


Else


Call Restoredatabase


End If


Application.Contents.RemoveAll


Else


Call Restoredata ()


End If

Case "Spacesize" ' System space occupancy
If not Chkadmin ("Spacesize") Then
Server.Transfer ("showerr.asp")
Request.end
End If
Call Spacesize ()

Case Else
ErrMsg = errmsg + <BR><li> Select the appropriate action. "
Returnerror (errmsg)

End Select


If Founderr = True Then


Returnerror (errmsg)


End If


Admin_footer


Saveloginfo (AdminName)


Closeconn


' ==================== system space occupancy =======================


Sub spacesize ()


On Error Resume Next


%&gt;


Border= "0" cellspacing= "1" cellpadding= "5" height= "1" align=center width= "&lt;table" class= "Tableborder" &gt; &lt;t R&gt;


&lt;th height=25&gt;


Space occupancy of &amp;nbsp;&amp;nbsp; system


&lt;/th&gt;


&lt;/tr&gt;


&lt;tr&gt;


&LT;TD class= "TableRow1" &gt;


&lt;blockquote&gt;


&lt;br&gt;


Regulatory Data Occupation Space: &amp;nbsp;&lt;img src= "Images/bar1.gif" Width=&lt;%=drawbar (". /database ")%&gt; height=10&gt;&amp;nbsp;&lt;%showspaceinfo (". /database ")%&gt;&lt;br&gt;&lt;br&gt;


Backup data footprint: &amp;nbsp;&lt;img src= "Images/bar1.gif" Width=&lt;%=drawbar ("DataBackup")%&gt; height=10&gt;&amp;nbsp; &lt;%showspaceinfo ("DataBackup")%&gt;&lt;br&gt;&lt;br&gt;


Admin occupy Space: &amp;nbsp;&lt;img src= "Images/bar1.gif" Width=&lt;%=drawbar ("./")%&gt; height=10&gt;&amp;nbsp;&lt;% Showspaceinfo ("./")%&gt;&lt;br&gt;&lt;br&gt;


Software channel occupancy space: &amp;nbsp;&lt;img src= "Images/bar1.gif" Width=&lt;%=drawbar (". /soft ")%&gt; height=10&gt;&amp;nbsp;&lt;%showspaceinfo (". /soft ")%&gt;&lt;br&gt;&lt;br&gt;


Article Channel occupancy space: &amp;nbsp;&lt;img src= "Images/bar1.gif" Width=&lt;%=drawbar (". /article ")%&gt; height=10&gt;&amp;nbsp;&lt;%showspaceinfo (". /article ")%&gt;&lt;br&gt;&lt;br&gt;


Template pictures occupy space: &amp;nbsp;&lt;img src= "Images/bar1.gif" Width=&lt;%=drawbar (". /skin ")%&gt; height=10&gt;&amp;nbsp;&lt;%showspaceinfo (". /skin ")%&gt;&lt;br&gt;&lt;br&gt;


Picture files occupy space: &amp;nbsp;&lt;img src= "Images/bar1.gif" Width=&lt;%=drawbar (". /images ")%&gt; height=10&gt;&amp;nbsp;&lt;%showspaceinfo (". /images ")%&gt;&lt;br&gt;&lt;br&gt;


User files Occupy space: &amp;nbsp;&lt;img src= "Images/bar1.gif" Width=&lt;%=drawbar (". /user ")%&gt; height=10&gt;&amp;nbsp;&lt;%showspaceinfo (". /user ")%&gt;&lt;br&gt;&lt;br&gt;


Upload files occupy space: &amp;nbsp;&lt;img src= "Images/bar1.gif" Width=&lt;%=drawbar (". /uploadfile ")%&gt; height=10&gt;&amp;nbsp;&lt;%showspaceinfo (". /uploadfile ")%&gt;&lt;br&gt;&lt;br&gt;


Total space occupied by the system: &amp;nbsp;&lt;img src= "Images/bar2.gif" width=400 height=10&gt; &lt;%showspecialspaceinfo ("All")%&gt;


&lt;/blockquote&gt;


&lt;/td&gt;


&lt;/tr&gt;


&lt;/table&gt;


&lt;%


End Sub

Sub Sqluserreadme ()


%&gt;


Border= "0" cellspacing= "1" cellpadding= "5" height= "1" align=center width= "&lt;table" class= "Tableborder" &gt; &lt;t R&gt;


&lt;th height=25&gt;


&amp;nbsp;&amp;nbsp; SQL database Data processing instructions


&lt;/th&gt;


&lt;/tr&gt;


&lt;tr&gt;


&LT;TD class= "TableRow1" &gt;


&lt;blockquote&gt;


&lt;B&gt; A, backup database &lt;/B&gt;


&lt;BR&gt;&lt;BR&gt;


1, open SQL Enterprise Manager, in the console root directory in turn open Microsoft SQL server&lt;br&gt;


2, SQL Server group--&gt; double hit Open your server--&gt; double-click to open the database directory &lt;BR&gt;


3, select your database name (such as System database newasp)--&gt; then click the Tools in the above menu--&gt; Select Backup Database &lt;BR&gt;


4, Backup options Select Full Backup, the purpose of the backup to the original if there is a path and name then select the name Point Delete, then click Add, if there is no path and name is directly selected to add, and then specify the path and filename, specify the back-point of the Backup window, and then click OK


&lt;BR&gt;&lt;BR&gt;


&lt;B&gt; II, RESTORE Database &lt;/B&gt;&lt;BR&gt;&lt;BR&gt;


1, open SQL Enterprise Manager, in the console root directory in turn open Microsoft SQL server&lt;br&gt;


2, SQL Server group--&gt; double hit Open your server--&gt; point icon Bar of the new database icon, the name of the new database to pick &lt;BR&gt;


3, click on the new database name (such as System database newasp)--&gt; then click the Tools in the above menu--&gt; select Restore Database &lt;BR&gt;


4, in the pop-up window of the Restore option select from the device--&gt; point Select Device--&gt; Point add--&gt; and then select your backup file name--&gt; Add after the point of return, this time the device bar should appear you just select the database backup file name, The backup number defaults to 1 (if you have multiple backups of the same file, you can click on the view next to the backup number, select the latest backup point in the check box)--&gt; then click the option button next to the general section above &lt;BR&gt;


5. Select the Force restore on the existing database in the window that appears, and select the option to keep the database running but not to restore other transaction logs in the recovery completion state. In the middle of the window to restore the database file to here to follow the installation of your SQL settings (you can also specify your own directory), the logical file name does not need to change, to move to the physical file name to change according to the machine condition you restored, such as your SQL database installed in D:\Program files\ Microsoft SQL Server\MSSQL\Data, then follow the changes that you have made to the directory where you restored the machine, and the last file name is best changed to your current database name (such as the original Newcloud_ Data.mdf, now the database is newasp, changed to Newasp_data.mdf), log and data files are to do in this way related changes (log file name is *_ Log.ldf end of), here's the recovery directory you can set freely, provided that the directory must exist (such as you can specify D:\sqldata\NewCloud_data.mdf or d:\sqldata\NewCloud_log.ldf), otherwise recovery will be an error &lt;BR&gt;


6, after the completion of the modification, click on the determination of the following recovery, there will be a progress bar, prompt recovery progress, the system will automatically prompt success after recovery, such as the middle of the prompt error, please record the relevant errors and ask about the SQL operation more familiar with the personnel, The general error is simply a directory error or file name duplication or file name error or lack of space or database is in use error, database is using the error you can try to close all about the SQL window and then reopen for recovery operations, If you also hint that the error you are using can stop the SQL service and then restart it, the other errors mentioned above can be restored after the error content is changed &lt;BR&gt;&lt;BR&gt;

<B> Shrinking Database </B><BR><BR>
In general, the contraction of the SQL database does not greatly reduce the size of the database, its primary role is to shrink the log size, this should be done periodically to avoid the database log too large <BR>
1, set the database mode to Simple mode: Open SQL Enterprise Manager, in the console root in turn, click the Microsoft SQL Server-->sql Server group--> double hit Open your server--> double-click to open the database directory--> Select your database name (such as System database newasp)--> and then right-click to select Properties--> Select option--> in the failover mode select "Simple" and then press OK to save <BR>
2, in the current database point right, look at all tasks in the shrinking database, the general inside the default settings do not need to adjust, direct point determine <BR>
3, <font color=blue> shrink the database is complete, it is recommended to reset your database properties to standard mode, the operation method with the 1th, because the log in some unusual circumstances is often the important basis for the recovery of the database </font>
<BR><BR>

&lt;B&gt; set up daily automatic backup database &lt;/B&gt;&lt;BR&gt;&lt;BR&gt;


&lt;font Color=red&gt; strongly recommends that a conditional user do this! &lt;/font&gt;&lt;BR&gt;


1, open Enterprise Manager, in the console root directory in turn open Microsoft SQL Server--&gt;sql Server group--&gt; double hit Open your server &lt;BR&gt;


2, then click the Tools in the above menu--&gt; Select Database Maintenance Planner &lt;BR&gt;


3, next select the data to be automatically backed up--&gt; next update data optimization information, here generally do not choose--&gt; Next check data integrity, also generally do not choose &lt;BR&gt;


4, the next step to specify the database maintenance plan, the default is 1 weeks backup, click Change Select Daily Backup After the point of determination &lt;BR&gt;


5, next specify the backup disk directory, select the specified directory, such as you can create a new directory in D disk such as: D:\databak, and then choose to use this directory here, if your database is more than best choose to create subdirectories for each database, and then choose to delete the backup earlier than how many days ago, Generally set 4-7 days, this depends on your specific backup requirements, backup file extensions are generally bak with the default &lt;BR&gt;


6, next specify the transaction log backup plan, see your needs to make a choice--&gt; next to generate reports, generally do not choose--&gt; Next maintenance Plan history, preferably with the default option--&gt; next step to complete &lt;BR&gt;


7, after the completion of the system is likely to prompt the SQL Server Agent service is not started, the first point to determine the completion plan, and then find the desktop rightmost status bar in the SQL Green icon, double-click Point Open, select SQL Server Agent in the service, and then click the run arrow, Start the service automatically when you start the OS &lt;BR&gt;


8, this time the database plan has been successfully run, he will follow the settings above you to automatically back up


&lt;BR&gt;&lt;BR&gt;


Modify Schedule:&lt;br&gt;


1, open Enterprise Manager, in the console root directory in order to open Microsoft SQL Server--&gt;sql Server group--&gt; double hit Open your server--&gt; admin--&gt; Database Maintenance Plan--&gt; open to see the plan you set , you can modify or delete an operation


&lt;BR&gt;&lt;BR&gt;


&lt;B&gt; v. Transfer of data (new database or transfer server) &lt;/B&gt;&lt;BR&gt;&lt;BR&gt;


Under normal circumstances, it is best to use Backup and restore operations to transfer data, in special cases, you can use the Import export method to transfer, here is the Import Export mode, import Export mode transfer data one function is to reduce (shrink) the size of the database in the case of shrinking the database. This operation by default for you have a certain understanding of the operation of the SQL, if some of the operations do not understand, you can consult the network related personnel or inquiries online information &lt;BR&gt;


1, the original database of all the tables, stored procedures exported to a SQL file, export time note in the option to write index script and write primary key, foreign key, default value and check Constraint script options &lt;BR&gt;


2. Create a new database, execute the SQL file created in the first step of the new database &lt;BR&gt;


3, with SQL import and export way, to the new database to import all the table content in the original database &lt;BR&gt;


&lt;/blockquote&gt;


&lt;/td&gt;


&lt;/tr&gt;


&lt;/table&gt;


&lt;%


End Sub


' ==================== database renamed =========================


Sub Renamedata ()


If issqldatabase = 1 Then


Sqluserreadme ()


Exit Sub


End If


Dim Accdatapath,accdataname,saccdatapath


Accdatapath = Replace (db, "/", "\")


Saccdatapath = Split (Accdatapath, "\")


Accdataname = Saccdatapath (UBound (Saccdatapath))


%&gt;


&lt;table width= "border=" 0 "align=" center "cellpadding=" 2 "cellspacing=" 1 "class=" Tableborder "&gt;


&lt;tr&gt;&lt;th colspan=2 height= "&gt;&amp;nbsp;&amp;nbsp;" library renamed (Need FSO support, FSO related help please see Microsoft website) &lt;/th&gt;&lt;/tr&gt;


&LT;TD width= "30%" class= "tablerow1highlight" height=23&gt; Please enter the database name &lt;BR&gt; operations you want to change before you best back up the database! &lt;/td&gt;


&lt;form action= "Admin_datarename.asp?action=rename" method= "POST" &gt;


&lt;input type=hidden name= "Olddataname" value= "&lt;%=db%&gt;" &gt;


&LT;TD width= "70%" class= "TableRow1" &gt;&lt;input name= "Newdataname" value= "&lt;%=AccDataName%&gt;" size= "&gt;"


&lt;input name= "B1" type= "Submit" Class=button value= "Confirm renaming" &gt;&lt;/td&gt;&lt;/form&gt;


&lt;/tr&gt;


&lt;/table&gt;


&lt;%


End Sub

' ==================== Recovery Database =========================

Sub Restoredata ()


If issqldatabase = 1 Then


%&gt;


Border= "0" cellspacing= "1" cellpadding= "5" height= "1" align=center width= "&lt;table" class= "Tableborder" &gt;


&lt;tr&gt;


&lt;th height=25 &gt;


&amp;nbsp;&amp;nbsp; Recover SQL data


&lt;/th&gt;


&lt;/tr&gt;


&lt;form method= "POST" action= "Action=restoredata&amp;act=restore" &gt;


&lt;tr&gt;


&LT;TD height=100 class= "TableRow1" &gt;


&amp;nbsp;&amp;nbsp;


Restore SQL database name: &lt;input type=text size=25 name=sqldataname value= "&lt;%=SqlDatabaseName%&gt;" &gt;&lt;BR&gt;&amp;nbsp; &amp;nbsp;


SQL database user name: &lt;input type=text size=25 name=sqluserid value= "&lt;%=SqlUsername%&gt;" &gt;&amp;nbsp; Please enter your SQL database username &lt;BR&gt;&amp;nbsp;&amp;nbsp;


SQL database user password: &lt;input type=password size=25 name=sqluserpass value= "&lt;%=SqlPassword%&gt;" &gt;&amp;nbsp; Please enter your SQL database connection password &lt;BR&gt;&amp;nbsp;&amp;nbsp;


SQL database server name: &lt;input type=text size=25 name=sqlserver value= "&lt;%=SqlLocalName%&gt;" &gt;&amp;nbsp; connection server name (locally with local , field with IP) &lt;BR&gt;&amp;nbsp;&amp;nbsp;


Backup SQL database directory: &lt;input type=text size=25 name=backupsqldir value= "databackup" &gt;&amp;nbsp; Please enter the database directory you backed up &lt;BR&gt; &amp;nbsp;&amp;nbsp;


Backup SQL database name: &lt;input type=text size=25 name=backupsqlname value= "$1.bak" &gt;&amp;nbsp; Please enter the database name you backed up &lt;BR&gt;


&amp;nbsp;&amp;nbsp;&lt;input type=submit value= "RESTORE Database" class=button&gt;&lt;br&gt;


-----------------------------------------------------------------------------------------&lt;br&gt;


&amp;nbsp;&amp;nbsp; You can use this feature to restore your regulatory data, please make sure that your database users have the relevant permissions to restore! &lt;br&gt;


&amp;nbsp;&amp;nbsp; Note: Database may not be restored in use &lt;/font&gt;


&lt;/td&gt;


&lt;/tr&gt;


&lt;/form&gt;


&lt;/table&gt;


&lt;%


Else


%&gt;


&lt;table border= "0" cellspacing= "1" cellpadding= "5" height= "1" align=center width= "over" class= "" Tableborder "&lt;tr" &gt;


&lt;th height=25 &gt;


&amp;nbsp;&amp;nbsp; Restore System data (need FSO support, FSO related help please see Microsoft website)


&lt;/th&gt;


&lt;/tr&gt;


&lt;form method= "POST" action= "Action=restoredata&amp;act=restore" &gt;





&lt;tr&gt;


&LT;TD height=100 class= "TableRow1" &gt;


&amp;nbsp;&amp;nbsp; Backup Database path (relative): &lt;input type=text size=45 name=dbpath value= "Databackup\newcloud_backup.mdb" &gt; &amp;nbsp;&amp;nbsp;&lt;BR&gt;


&amp;nbsp;&amp;nbsp; Target database path (relative): &lt;input type=text size=45 name=backpath value= "&lt;%=db%&gt;" &gt;&lt;BR&gt;&amp; nbsp;&amp;nbsp; fill in the database path you are currently using, if you do not want to overwrite the current file, you can name it (note that the path is correct), and then modify the conn.asp file, if the target file name and the current database name is the same, do not need to modify the conn.asp file &lt; Br&gt;


&amp;nbsp;&amp;nbsp;&lt;input type=submit value= "RESTORE Database" class=button&gt; &lt;br&gt;


-----------------------------------------------------------------------------------------&lt;br&gt;


&amp;nbsp;&amp;nbsp; in the above fill in this program's database path full name, this program's default backup database file is Databackup\newcloud_backup.mdb, please follow your backup file to modify. &lt;br&gt;


&amp;nbsp;&amp;nbsp; You can use this feature to back up your regulatory data to keep your data secure! &lt;br&gt;


&amp;nbsp;&amp;nbsp; Note: All paths are relative to the program space root directory relative path &lt;/font&gt;


&lt;/td&gt;


&lt;/tr&gt;


&lt;/form&gt;


&lt;/table&gt;


&lt;%


End If


End Sub


' ==================== Backup Database =========================


Sub Backupdata ()


If issqldatabase = 1 Then


%&gt;


Border= "0" cellspacing= "1" cellpadding= "5" height= "1" align=center width= "&lt;table" class= "Tableborder" &gt;


&lt;tr&gt;


&lt;th height=25 &gt;


&amp;nbsp;&amp;nbsp; Backup SQL data


&lt;/th&gt;


&lt;/tr&gt;


&lt;form method= "POST" action= "Action=backupdata&amp;act=backup" &gt;


&lt;tr&gt;


&LT;TD height=100 class= "TableRow1" &gt;


&amp;nbsp;&amp;nbsp;


Current SQL database name: &lt;input type=text size=25 name=sqldataname value= "&lt;%=SqlDatabaseName%&gt;" &gt;&lt;BR&gt;&amp;nbsp; &amp;nbsp;


SQL database user name: &lt;input type=text size=25 name=sqluserid value= "&lt;%=SqlUsername%&gt;" &gt;&amp;nbsp; Please enter your SQL database username &lt;BR&gt;&amp;nbsp;&amp;nbsp;


SQL database user password: &lt;input type=password size=25 name=sqluserpass value= "&lt;%=SqlPassword%&gt;" &gt;&amp;nbsp; Please enter your SQL database connection password &lt;BR&gt;&amp;nbsp;&amp;nbsp;


SQL database server name: &lt;input type=text size=25 name=sqlserver value= "&lt;%=SqlLocalName%&gt;" &gt;&amp;nbsp; connection server name (locally with local , field with IP) &lt;BR&gt;&amp;nbsp;&amp;nbsp;


Backup SQL database directory: &lt;input type=text size=25 name=backupsqldir value= "databackup" &gt;&amp;nbsp; if directory does not exist, the program will automatically create &lt;BR&gt; &amp;nbsp;&amp;nbsp;


Backup SQL database name: &lt;input type=text size=25 name=backupsqlname value= "$1.bak" &gt;&amp;nbsp; if you use the default backup name, The system will automatically create a backup name by date time &lt;BR&gt;


&amp;nbsp;&amp;nbsp;&lt;input type=submit value= "Backup Database" class=button&gt;&lt;br&gt;


-----------------------------------------------------------------------------------------&lt;br&gt;


&amp;nbsp;&amp;nbsp; You can use this feature to back up your regulatory data to keep your data secure! &lt;br&gt;


&amp;nbsp;&amp;nbsp; Note: All paths are relative to program space management directory relative path &lt;/font&gt;


&lt;/td&gt;


&lt;/tr&gt;


&lt;/form&gt;


&lt;/table&gt;


&lt;%


Else


%&gt;


Border= "0" cellspacing= "1" cellpadding= "5" height= "1" align=center width= "&lt;table" class= "Tableborder" &gt;


&lt;tr&gt;


&lt;th height=25 &gt;


&amp;nbsp;&amp;nbsp; Backup system data (need FSO support, FSO related help please see Microsoft website)


&lt;/th&gt;


&lt;/tr&gt;


&lt;form method= "POST" action= "Action=backupdata&amp;act=backup" &gt;


&lt;tr&gt;


&LT;TD height=100 class= "TableRow1" &gt;


&amp;nbsp;&amp;nbsp;


Current database path (relative path): &lt;input type=text size=45 name=dbpath size=45 value= "&lt;%=db%&gt;" &gt;&lt;BR&gt;&amp;nbsp;&amp; nbsp


Backup database directory (relative path): &lt;input type=text size=20 name=bkfolder size=45 value=databackup&gt;&amp;nbsp; If directory does not exist, the program will automatically create &LT;BR &gt;&amp;nbsp;&amp;nbsp;


Backup database name (fill in name): &lt;input type=text size=20 name=bkdbname size=45 value=newcloud_backup.mdb&gt;&amp;nbsp; If the backup directory has the file, Will overwrite, if not, will automatically create &lt;BR&gt;


&amp;nbsp;&amp;nbsp;&lt;input type=submit value= "Backup Database" class=button&gt;&lt;br&gt;


-----------------------------------------------------------------------------------------&lt;br&gt;


&amp;nbsp;&amp;nbsp; fill in the above database path full name of this program, the default database file for this program is &lt;%=db%&gt;,&lt;B&gt; please be sure you cannot name the backup database with the default name &lt;/B&gt;&lt;br&gt;


&amp;nbsp;&amp;nbsp; You can use this feature to back up your regulatory data to keep your data secure! &lt;br&gt;


&amp;nbsp;&amp;nbsp; Note: All paths are relative to program space management directory relative path &lt;/font&gt;


&lt;/td&gt;


&lt;/tr&gt;


&lt;/form&gt;


&lt;/table&gt;


&lt;%


End If


End Sub

Sub BackupDatabase ()


DBPath = Request. Form ("DBPath")


If InStr (DBPath, ":") = 0 Then


DBPath = Server.MapPath (DBPath)


Else


DBPath = DBPath


End If


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&amp; "\" &amp; Bkdbname


Else


Makenewsdir Bkfolder


Fso. CopyFile dbpath, bkfolder&amp; "\" &amp; Bkdbname


End If


SUCCEED ("Backup database is successful, your backup database path is" &amp;bkfolder&amp; \ "&amp; Bkdbname)


Else


Founderr = True


ErrMsg = "The file you need to back up is not found. "


Exit Sub


End If


End Sub


Sub Restoredatabase ()


Dim Backpath,dbpath


DBPath = Request. Form ("DBPath")


Backpath = Request. Form ("Backpath")


If DBPath = "" Then


Founderr = True


ErrMsg = "Please enter the full name of the database you want to restore"


Exit Sub


End If


If InStr (DBPath, ":") = 0 Then


DBPath = Server.MapPath (DBPath)


Else


DBPath = DBPath


End If


If InStr (Backpath, ":") = 0 Then


Backpath = Server.MapPath (Backpath)


Else


Backpath = Backpath


End If


Set Fso = server. CreateObject ("Scripting.FileSystemObject")


If FSO. FileExists (DBPath) Then


Fso. CopyFile DBPath, Backpath


Succeed ("Recover data successfully!") ")


Else


Founderr = True


ErrMsg = "Backup directory does not have your backup file!" "


Exit Sub


End If


End Sub


'------------------Check if a directory exists-------------------


Function Checkdir (FolderPath)


FolderPath = Server.MapPath (".") &amp; "\" &amp;folderpath


Set Fso1 = CreateObject ("Scripting.FileSystemObject")


If Fso1. FolderExists (FolderPath) Then


' Existence


Checkdir = True


Else


' does not exist


Checkdir = False


End If


Set Fso1 = Nothing


End Function


'-------------generate a 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


' ==================== Compressed Database =========================


Sub Compressdata ()

If issqldatabase = 1 Then


Sqluserreadme ()


Exit Sub


End If


%&gt;


Border= "0" cellspacing= "1" cellpadding= "5" height= "1" align=center width= "&lt;table" class= "Tableborder" &gt;


&lt;tr&gt;


&lt;th height=25 &gt;


&amp;nbsp;&amp;nbsp; compressed database (need FSO support, FSO related help please see Microsoft website)


&lt;/th&gt;


&lt;form action= "? action=compressdata&amp;act=compress" method= "POST" &gt;


&lt;tr&gt;


&LT;TD class= "TableRow1" height=25&gt;&lt;b&gt; note:&lt;/b&gt;&lt;br&gt; the relative path where the database is entered and enter the database name (the database in use cannot be compressed. Please select BACKUP database for compression operation) &lt;/td&gt;


&lt;/tr&gt;


&lt;tr&gt;


&LT;TD class= "TableRow1" &gt; Compressed database: &lt;input type= "text" name= "DBPath" size=45 value=&lt;%=db%&gt;&gt;&amp;nbsp;


&lt;input type= "Submit" value= "start Compression" class=button&gt;&lt;/td&gt;


&lt;/tr&gt;


&lt;tr&gt;


&LT;TD class= "TableRow1" &gt;&lt;input type= "checkbox" Name= "boolIs97" value= "True" &gt; If you use an Access 97 database, select


(The default is Access 2000 database) &lt;br&gt;&lt;br&gt;&lt;/td&gt;


&lt;/tr&gt;


&lt;form&gt;


&lt;/table&gt;


&lt;%


End Sub

Sub Compressdatabase ()
Dim DBPath, BOOLIS97
DBPath = Request ("DBPath")
BOOLIS97 = Request ("BOOLIS97")

If dbpath <> "" Then
If InStr (DBPath, ":") = 0 Then
DBPath = Server.MapPath (DBPath)
Else
DBPath = DBPath
End If
Response.Write (Compactdb (DBPath, BOOLIS97))
Else
Founderr = True
ErrMsg = "Please enter the database path to compress!" "
Exit Sub
End If
End Sub
' ===================== compression parameter =========================
Function Compactdb (DBPath, BOOLIS97)
Dim FSO, Engine, Strdbpath, jet_3x
Strdbpath = Left (DBPath, InStrRev (DBPath, "\"))
Set fso = CreateObject ("Scripting.FileSystemObject")

If FSO. FileExists (DBPath) Then
Fso. CopyFile DBPath, Strdbpath & "Temp.mdb"
Set Engine = CreateObject ("JRO. JetEngine ")

  if boolIs97 = "True" Then
   engine.compactdatabase "provider= Microsoft.jet.oledb.4.0;data source= "& Strdbpath &" Temp.mdb ", _
    " provider= Microsoft.jet.oledb.4.0;data source= "& Strdbpath &" Temp1.mdb; "_
    &" Jet OLE DB : Engine type= "& jet_3x
  else
   engine.compactdatabase" provider= Microsoft.jet.oledb.4.0;data source= "& Strdbpath &" Temp.mdb ", _
    " provider= Microsoft.jet.oledb.4.0;data source= "& Strdbpath &" Temp1.mdb "
  end If

  fso. CopyFile Strdbpath & "Temp1.mdb", DBPath
  fso. DeleteFile (Strdbpath & "Temp.mdb")
  fso. DeleteFile (Strdbpath & "Temp1.mdb")
  set fso = Nothing
  set Engine = Nothing
   succeed ("Your Database," & DBPath & ", has been compressed successfully!")
 else
  returnerror ("The database name or path is incorrect.) Please try again! ")
 end If

End Function
' ===================== system space parameter =========================
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 & &nbsp; Byte
 if size>1024 Then
  size = (size/1024)
  showsize = FormatNumber (Size, 2) & "&nbsp; KB '
 end If
 if size>1024 Then
  size = (size/1024)
  showsize = Format Number (Size, 2) & "&nbsp; MB '
 end If
 if size>1024 Then
  size = (size/1024)
  showsize = Format Number (Size, 2) & "&nbsp; 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 (".. /")
' 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 & &nbsp; Byte "
If size>1024 Then
Size = (size/1024)
Showsize = FormatNumber (Size, 2) & "&nbsp; KB "
End If
If size>1024 Then
Size = (size/1024)
Showsize = FormatNumber (Size, 2) & "&nbsp; MB "
End If
If size>1024 Then
Size = (size/1024)
Showsize = FormatNumber (Size, 2) & "&nbsp; 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 (".. /pic ")
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 = CDBL ((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 (".. /pic ")
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 = CDBL ((size/totalsize) * 400)
Drawspecialbar = Barsize
End Function

Sub Checksql ()


If Trim (Request.Form ("Sqldataname")) = "" Then


Founderr = True


ErrMsg = errmsg &amp; &lt;li&gt; Please enter the SQL database name! &lt;/li&gt; "


End If


If Trim (Request.Form ("Sqluserpass")) = "" Then


Founderr = True


ErrMsg = errmsg &amp; &lt;li&gt; Please enter the SQL database user password! &lt;/li&gt; "


End If


If Trim (Request.Form ("SQLUserID")) = "" Then


Founderr = True


ErrMsg = errmsg &amp; &lt;li&gt; Please enter the SQL database user name! &lt;/li&gt; "


End If


If Trim (Request.Form ("SQL Server") = "" Then


Founderr = True


ErrMsg = errmsg &amp; &lt;li&gt; Please enter the SQL database connection name (locally with local, field IP)! &lt;/li&gt; "


End If


If Trim (Request.Form ("Backupsqlname")) = "" Then


Founderr = True


ErrMsg = errmsg &amp; &lt;li&gt; Please enter the SQL database backup name! &lt;/li&gt; "


End If


If Trim (Request.Form ("Backupsqldir")) = "" Then


Founderr = True


ErrMsg = errmsg &amp; &lt;li&gt; Please enter the SQL database backup directory! &lt;/li&gt; "


End If


End Sub


' ==================== Backup SQL database =========================


Sub Backupsqldatabase ()


On Error Resume Next


Dim Sqldataname, Sqluserpass, SQLUserID, SQL Server, Sqllogintimeout


Dim srv, bak, Backupfilepath, Backupsqldir, Backupsqlname,backupfilename


Sqldataname = Trim (Request.Form ("Sqldataname"))


Sqluserpass = Trim (Request.Form ("Sqluserpass"))


SQLUserID = Trim (Request.Form ("SQLUserID"))


SQL Server = Trim (Request.Form ("SQL Server"))


Backupsqldir = Trim (Request.Form ("Backupsqldir"))


Backupsqlname = Trim (Request.Form ("Backupsqlname"))


Sqllogintimeout = 20 ' login timeout


Checksql


If Founderr = True Then Exit Sub


If Checkdir (backupsqldir) = False Then


Makenewsdir Backupsqldir


End If


BackupFileName = Sqldataname &amp; "_" &amp; Replace (FormatDateTime (now,2), "-", "") &amp; "_" &amp; Replace (Formatdatetim E (now,3), ":", "")


Backupfilepath = backupsqldir &amp; "\" &amp; Backupsqlname


Backupfilepath = Replace (Backupfilepath, "$", BackupFileName)


Set srv = Server.CreateObject ("SQLDMO.") SQL Server ")


Srv. LoginTimeout = Sqllogintimeout


Srv. Connect SQL Server, SQLUserID, Sqluserpass


Set bak = Server.CreateObject ("SQLDMO.") Backup ")


Bak. Database = Sqldataname


' Bak. Devices = Files


Bak. Files = Backupfilepath


Bak. SQLBackup SRV


If err.number&gt;0 Then


Response.Write Err.Number &amp; "&lt;font color=red&gt;&lt;br&gt;"


Response.Write Err.Description &amp; "&lt;/font&gt;"


End If


Set srv = Nothing


Set bak = Nothing


Succeed ("&lt;li&gt;sql database backup succeeded!") &lt;/li&gt; ")


End Sub


' ==================== Restore SQL database =========================


Sub Restoresqldatabase ()


On Error Resume Next


Dim Sqldataname, Sqluserpass, SQLUserID, SQL Server, Sqllogintimeout


Dim srv, rest, Backupfilepath, Backupsqldir, Backupsqlname, FSO


Sqldataname = Trim (Request.Form ("Sqldataname"))


Sqluserpass = Trim (Request.Form ("Sqluserpass"))


SQLUserID = Trim (Request.Form ("SQLUserID"))


SQL Server = Trim (Request.Form ("SQL Server"))


Backupsqldir = Trim (Request.Form ("Backupsqldir"))


Backupsqlname = Trim (Request.Form ("Backupsqlname"))


Sqllogintimeout = 20 ' login timeout


Checksql


If Founderr = True Then Exit Sub


Backupfilepath = Backupsqldir &amp; "/" &amp; Backupsqlname


Backupfilepath = Replace (Backupfilepath, "$", Sqldataname)


Backupfilepath = Server.MapPath (Backupfilepath)


Set FSO = Server.CreateObject ("Scripting.FileSystemObject")


If FSO. FileExists (Backupfilepath) Then


Set srv = Server.CreateObject ("SQLDMO.") SQL Server ")


Srv. LoginTimeout = Sqllogintimeout


Srv. Connect SQL Server, SQLUserID, Sqluserpass


Set rest = Server.CreateObject ("SQLDMO.") Restore ")


Rest. Action = 0


Rest. Database = Sqldataname


' Rest. Devices = Files


Rest. Files = Backupfilepath


Rest. ReplaceDatabase = True


Rest. SQLRestore SRV


If err.number&gt;0 Then


ErrMsg = errmsg &amp; &lt;li&gt; An error occurred while backing up the database! &lt;/li&gt; "


ErrMsg = errmsg &amp; &lt;li&gt; error code: "


ErrMsg = errmsg &amp; Err.Number &amp; "&lt;/li&gt;&lt;li&gt;&lt;font color=red&gt;"


' Response.Write err.number&amp; ' &lt;font color=red&gt;&lt;br&gt; '


ErrMsg = errmsg &amp; err.description&amp; "&lt;/font&gt;&lt;/li&gt;"


Founderr = True


Exit Sub


End If


Set srv = Nothing


Set rest = Nothing


Succeed ("&lt;li&gt;sql database restored successfully!") &lt;/li&gt; ")


Else


Founderr = True


ErrMsg = "Backup directory does not have your backup file!" "


Exit Sub


End If


Set FSO = Nothing


End Sub


%&gt;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.