Database backup System

Source: Internet
Author: User

Database backup System

<meta http-equiv= "Content-language" content= "ZH-CN" >
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> Database Management </title>
<body>
<div align=center> Database management system </div>
<br>
<br>
<p align= "center" >
<%
Dim Zc_database_path
' The path to the database
Zc_database_path= "Database/data.mdb"
Data_array= Split (Zc_database_path, "/")
Dim Action
Action=trim (Request ("action"))
Dim DBPATH,BKFOLDER,BKDBNAME,FSO,FSO1
Select Case Action
Case ""
Call Chushihua ()
Case "Compressdata" ' compressed data
Dim Tmprs
Dim allarticle
Dim Maxid
Dim topic,username,dateandtime,body
Call Compressdata ()
Case "Backupdata" Backup data
If Request ("act") = "Backup" Then
Call Updata ()
Else
Call Backupdata ()
End If
Case "Restoredata" ' recovery data
Dim Backpath
If Request ("act") = "Restore" Then
Dbpath=request.form ("DBPath")
Backpath=request.form ("Backpath")
If Dbpath= "" Then
Response.Write "Please input your database whole Name"
Else
Dbpath=server.mappath (DBPath)
End If
Backpath=server.mappath (Backpath)
Set Fso=server. CreateObject ("Scripting.FileSystemObject")
If Fso.fileexists (DBPath) Then
Fso.copyfile Dbpath,backpath
Response.Write "Database was successfully restored!<br>"
Else
Response.Write "did not find the database you need!"
End If
Else
Call Restoredata ()
End If
Case "Spacesize" ' System space occupancy
Call Spacesize ()
Case "DeleteBackup"
Dim dbname
Dbpath=request.querystring ("DBPath")
Dbname=request.querystring ("dbname")
Dbpath=server.mappath (DBPath)
Dbpath=dbpath & "\" &dbname
Set fso = CreateObject ("Scripting.FileSystemObject")
If FSO. FileExists (DBPath) Then
Fso. DeleteFile (DBPath)
Set FSO = Nothing
Response.Write "<br> you backed up the database has been" & DBPath & "was successfully deleted!<br><br><a href=" "data_s.asp" "> Return. </a> "
Else
Response.Write DBPath
Response.Write "<br> Input path error, please confirm and re-enter!<br><br><a href=" "data_s.asp" > Return ... </a> "
End If
Case Else
End Select
%>
</div>
<%
Response.Write "</body>Sub Chushihua ()
%>
<div align=center>
<form id= "Edit" >
<a href= "? action=compressdata" >[Compressed database]</a>
<a href= "? action=backupdata" >[Backup Database]</a>
<a href= "? action=restoredata" >[Restore Database]</a>
<a href= "? action=spacesize" >[System space Occupancy]</a>

</form>
</div>
<%end sub%>
<%
' ==================== system space occupancy =======================
Sub spacesize ()
On Error Resume Next
%>
<div align=center>
<div align=center>
System Space View

<form id= "Edit" >
<br>
Database: <%showspaceinfo (".. /"&data_array (1) &" ")%><br><br>
Back up the database: <%showspaceinfo ("DataBackup")%><br><br>
Total system: <%showspaceinfo ("/")%>
<br><br>
</form>
</div>
<br >
<br >
<br >
<a href= "data_s.asp" > Return ...</a>
</div>
<%
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 Restoredata ()
%>
<div align=center>
<div align=center>
To restore a database:

<form id= "edit" method= "Post" action= "Data_s.asp?action=restoredata&act=restore" >
Path to restore (relative path): <input type=text size=30 name=dbpath value= "databackup\<%=date ()%>_bak.mdb" ><BR>
Path after restore (relative path): <input type=text size=30 name=backpath value= "<%=ZC_DATABASE_PATH%>" ><BR><BR>
<input type=submit value= "Start Restore" >
</form>
</div>
<br>
<br>
<a href= "data_s.asp" > Return ...</a>
</div>
<%
End Sub
Sub Updata ()
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 "<br> has been successfully backed up, your database path:" &bkfolder& "\" & Bkdbname
Response.Write "<br><br> Click here to download the database: <a href=" "& Zc_blog_host & Request.Form (" Bkfolder ") & "/" & Bkdbname & "" > "& Zc_blog_host & Request.Form (" Bkfolder ") &"/"& Bkdbname &" &L T;br><br> "
Response.Write "<br><br><a href=" "Data_s.asp?action=deletebackup&dbpath=" &request.form (" Bkfolder ") &" &dbname= "& Bkdbname &" "> When you have finished downloading, click here to delete the backed up database!</a><br><br>< Br><a href= "" data_s.asp "" > Return to ...</a> "
Else
Response.Write "Error, cannot find file!<br>"
End If
Set FSO = Nothing
End Sub
'------------------Check if a directory exists-------------------
Function Checkdir (FolderPath)
Folderpath=server.mappath (".") & "\" &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
Sub Backupdata ()
%>
<div align=center>

Backing up a database

<form id= "edit" method= "Post" action= "Data_s.asp?action=backupdata&act=backup" >
Path to the current database (relative path): <input type=text size=15 name=dbpath value= "<%=ZC_DATABASE_PATH%>" >
The path to the backup database (relative path): <input type=text size=15 name=bkfolder value= "DataBackup" >
If the directory does not exist, the system will automatically establish
Name of database after backup: <input type=text size=20 name=bkdbname value= "<%=date ()%>_bak.mdb" > automatically named by date
If the backup file does not exist will be established, if present, will automatically overwrite!
<input type=submit value= "Start Backup" ><br>
</form>
<br><br>
<a href= "data_s.asp" > Return. </a>
</div>
<%
End Sub
Sub Compressdata ()
%>
<div align=center>
To compress a database:

<form id= "edit" action= "Data_s.asp?action=compressdata" method= "POST" >
Enter the path where the database is located

The path to the compressed database: <input type= "text" name= "DBPath" value= "<%=ZC_DATABASE_PATH%>" >

<input type= "Submit" value= "start Compression" >
<input type= "checkbox" Name= "boolIs97" value= "True" > if it is ac97, please put the hook on. (default is Access) <br><br>
</form>
<br><br>
<a href= "data_s.asp" > Return. </a>
</div>
<%
Dim dbpath,boolis97
DBPath = Request ("DBPath")
BOOLIS97 = Request ("BOOLIS97")
If dbpath <> "" Then
DBPath = Server.MapPath (DBPath)
Response.Write (Compactdb (DBPATH,BOOLIS97))
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 oledb: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
COMPACTDB = "Your database" & DBPath & "has been successfully compressed!" & VbCrLf
Else
Compactdb = "<br> you have entered a wrong path, please confirm and re-enter!" & VbCrLf
End If
End Function
'////////////////////end////////////////////////
%>
</p>
</body>

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.