Forums
This topic is locked
Backup Access file on server by link
14 Feb 2004 22:17:27 phil C posted:
HiCan someone please help me out here.
i have an access DB run site and need to be able to backup(copy) the access .mdb to either another folder on the server or the same folder under a new name using a link on my secure admin page.
after adding new products it would be a good idea to Backup the work i've just spent 2 hours doing.
Many thanks in advance
Phil C
Replies
Replied 16 Feb 2004 02:50:41
16 Feb 2004 02:50:41 Phil Shevlin replied:
Hopefully your DB is stored in an area NOT accessible via the web. Then a script using file sytem functions could work. Which language are you using?
Replied 16 Feb 2004 06:06:58
16 Feb 2004 06:06:58 phil C replied:
Hi
The DB is in a private dir outside of normal http access so is safe as is the admin pages, using VBScript V2 or should i say UD4 is. i'm just along for the ride.
The DB is in a private dir outside of normal http access so is safe as is the admin pages, using VBScript V2 or should i say UD4 is. i'm just along for the ride.
Replied 16 Feb 2004 16:25:20
16 Feb 2004 16:25:20 Phil Shevlin replied:
You'll need to hard code it. Look into the File System Object.
Replied 17 Feb 2004 10:56:55
17 Feb 2004 10:56:55 Tom Dude replied:
<font face='Verdana'>
Here ya go mate!
Try this, may need some customisation
</font id='Verdana'>
<font face='Comic Sans MS'>
<% Option Explicit %>
<%
'Dimension variables
Dim objJetEngine 'Holds the jet database engine object
Dim objFSO 'Holds the FSO object
Dim strCompactDB 'Holds the destination of the compacted database
Dim strDbPathAndName
Dim strCon
strDbPathAndName = Server.MapPath("database.mdb"
strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & strDbPathAndName
%>
<html>
<head>
<title>Compact and Repair Access Database</title>
</head>
<body>
<h2>Compact and Repair Access Database</h2>
<br />
<%
'If this is a post back run the compact and repair
If Request.Form("postBack" Then %>
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<ol>
<%
'Create an intence of the FSO object
Set objFSO = Server.CreateObject("Scripting.FileSystemObject"
'Back up the database
objFSO.CopyFile strDbPathAndName, Replace(strDbPathAndName, ".mdb", "-backup.mdb", 1, -1, 1)
Response.Write(" <li>Database backed up to:-<br/><span>" & Replace(strDbPathAndName, ".mdb", "-backup.mdb", 1, -1, 1) & "</span><br /><br /></li>"
'Create an intence of the JET engine object
Set objJetEngine = Server.CreateObject("JRO.JetEngine"
'Get the destination and name of the compacted database
strCompactDB = Replace(strDbPathAndName, ".mdb", "-tmp.mdb", 1, -1, 1)
'Compact database
objJetEngine.CompactDatabase strCon, "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & strCompactDB
'Display text that new compact db is created
Response.Write(" <li>New compacted database:-<br/><span>" & strCompactDB & "</span><br /><br /></li>"
'Release Jet object
Set objJetEngine = Nothing
'Delete old database
objFSO.DeleteFile strDbPathAndName
'Display text that that old db is deleted
Response.Write(" <li>Old uncompacted database deleted:-<br/><span>" & strDbPathAndName & "</span><br /><br /></li>"
'Rename temporary database to old name
objFSO.MoveFile strCompactDB, strDbPathAndName
'Display text that that old db is deleted
Response.Write(" <li>Rename compacted database from:-<br/><span>" & strCompactDB & "</span><br />To:-<br /><span>" & strDbPathAndName & "</span><br /><br /></li>"
'Release FSO object
Set objFSO = Nothing
Response.Write(" The Access database is now compacted and repaired"
%></ol></td>
</tr>
</table>
<%
Else
%>
<p class="text"> Please note: If the 'Compact and Repair' procedure fails a backup of your database will be created ending with '-backup.mdb'.<br />
</p>
</div>
<form action="this_file_name.asp" method="post" name="frmCompact" id="frmCompact">
<div align="center"><br />
<input name="postBack" type="hidden" id="postBack" value="true">
<input type="submit" name="Submit" value="Compact and Repair Database">
</div>
</form><%
End If
%>
<br />
</body>
</html>
</font id='Comic Sans MS'>
Here ya go mate!
Try this, may need some customisation
</font id='Verdana'>
<font face='Comic Sans MS'>
<% Option Explicit %>
<%
'Dimension variables
Dim objJetEngine 'Holds the jet database engine object
Dim objFSO 'Holds the FSO object
Dim strCompactDB 'Holds the destination of the compacted database
Dim strDbPathAndName
Dim strCon
strDbPathAndName = Server.MapPath("database.mdb"
strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & strDbPathAndName
%>
<html>
<head>
<title>Compact and Repair Access Database</title>
</head>
<body>
<h2>Compact and Repair Access Database</h2>
<br />
<%
'If this is a post back run the compact and repair
If Request.Form("postBack" Then %>
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<ol>
<%
'Create an intence of the FSO object
Set objFSO = Server.CreateObject("Scripting.FileSystemObject"
'Back up the database
objFSO.CopyFile strDbPathAndName, Replace(strDbPathAndName, ".mdb", "-backup.mdb", 1, -1, 1)
Response.Write(" <li>Database backed up to:-<br/><span>" & Replace(strDbPathAndName, ".mdb", "-backup.mdb", 1, -1, 1) & "</span><br /><br /></li>"
'Create an intence of the JET engine object
Set objJetEngine = Server.CreateObject("JRO.JetEngine"
'Get the destination and name of the compacted database
strCompactDB = Replace(strDbPathAndName, ".mdb", "-tmp.mdb", 1, -1, 1)
'Compact database
objJetEngine.CompactDatabase strCon, "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & strCompactDB
'Display text that new compact db is created
Response.Write(" <li>New compacted database:-<br/><span>" & strCompactDB & "</span><br /><br /></li>"
'Release Jet object
Set objJetEngine = Nothing
'Delete old database
objFSO.DeleteFile strDbPathAndName
'Display text that that old db is deleted
Response.Write(" <li>Old uncompacted database deleted:-<br/><span>" & strDbPathAndName & "</span><br /><br /></li>"
'Rename temporary database to old name
objFSO.MoveFile strCompactDB, strDbPathAndName
'Display text that that old db is deleted
Response.Write(" <li>Rename compacted database from:-<br/><span>" & strCompactDB & "</span><br />To:-<br /><span>" & strDbPathAndName & "</span><br /><br /></li>"
'Release FSO object
Set objFSO = Nothing
Response.Write(" The Access database is now compacted and repaired"
%></ol></td>
</tr>
</table>
<%
Else
%>
<p class="text"> Please note: If the 'Compact and Repair' procedure fails a backup of your database will be created ending with '-backup.mdb'.<br />
</p>
</div>
<form action="this_file_name.asp" method="post" name="frmCompact" id="frmCompact">
<div align="center"><br />
<input name="postBack" type="hidden" id="postBack" value="true">
<input type="submit" name="Submit" value="Compact and Repair Database">
</div>
</form><%
End If
%>
<br />
</body>
</html>
</font id='Comic Sans MS'>
Replied 17 Feb 2004 15:46:24
17 Feb 2004 15:46:24 phil C replied:
WOW <img src=../images/dmxzone/forum/icon_smile_big.gif border=0 align=middle>
What can i say.....
Sir you are a gent.
Your code works like a dream, thankyou very very much, if i should ever meet you in a pud the drinks on me..
Thanks again..
Phil C
What can i say.....
Sir you are a gent.
Your code works like a dream, thankyou very very much, if i should ever meet you in a pud the drinks on me..
Thanks again..
Phil C
Replied 17 Feb 2004 15:57:46
17 Feb 2004 15:57:46 Dave Thomas replied:
yeah nice post m8.
/me saves this to my snippets file <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Regards,
Dave
[DWMX 2004]|[FlashMX 2004 Pro]|[Studio MX 2004]|[SQL]|[Access2000/2002]|[ASP/VBScript]|[XP-Pro]
If you like online gaming, please register @ www.nova-multigaming.com
/me saves this to my snippets file <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Regards,
Dave
[DWMX 2004]|[FlashMX 2004 Pro]|[Studio MX 2004]|[SQL]|[Access2000/2002]|[ASP/VBScript]|[XP-Pro]
If you like online gaming, please register @ www.nova-multigaming.com
Replied 06 Jun 2006 18:59:04
06 Jun 2006 18:59:04 Jurgen Gurgen replied:
this is great but where do i specify the directory to save the backup. I want to save it on a seperate server on the network