Get ready for BLACK FRIDAY shopping starting in

Forums

This topic is locked

Backup Access file on server by link

Posted 14 Feb 2004 22:17:27
1
has voted
14 Feb 2004 22:17:27 phil C posted:
Hi
Can 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.
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'>
&lt;% Option Explicit %&gt;
&lt;%
'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
%&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Compact and Repair Access Database&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h2&gt;Compact and Repair Access Database&lt;/h2&gt;
&lt;br /&gt;
&lt;%
'If this is a post back run the compact and repair
If Request.Form("postBack" Then %&gt;
&lt;table width="80%" border="0" cellspacing="0" cellpadding="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;ol&gt;
&lt;%

'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(" &lt;li&gt;Database backed up to:-&lt;br/&gt;&lt;span&gt;" & Replace(strDbPathAndName, ".mdb", "-backup.mdb", 1, -1, 1) & "&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;"




'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(" &lt;li&gt;New compacted database:-&lt;br/&gt;&lt;span&gt;" & strCompactDB & "&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;"

'Release Jet object
Set objJetEngine = Nothing




'Delete old database
objFSO.DeleteFile strDbPathAndName

'Display text that that old db is deleted
Response.Write(" &lt;li&gt;Old uncompacted database deleted:-&lt;br/&gt;&lt;span&gt;" & strDbPathAndName & "&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;"



'Rename temporary database to old name
objFSO.MoveFile strCompactDB, strDbPathAndName

'Display text that that old db is deleted
Response.Write(" &lt;li&gt;Rename compacted database from:-&lt;br/&gt;&lt;span&gt;" & strCompactDB & "&lt;/span&gt;&lt;br /&gt;To:-&lt;br /&gt;&lt;span&gt;" & strDbPathAndName & "&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;"


'Release FSO object
Set objFSO = Nothing


Response.Write(" The Access database is now compacted and repaired"

%&gt;&lt;/ol&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;%
Else

%&gt;
&lt;p class="text"&gt; Please note: If the 'Compact and Repair' procedure fails a backup of your database will be created ending with '-backup.mdb'.&lt;br /&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;form action="this_file_name.asp" method="post" name="frmCompact" id="frmCompact"&gt;
&lt;div align="center"&gt;&lt;br /&gt;
&lt;input name="postBack" type="hidden" id="postBack" value="true"&gt;
&lt;input type="submit" name="Submit" value="Compact and Repair Database"&gt;
&lt;/div&gt;
&lt;/form&gt;&lt;%

End If

%&gt;
&lt;br /&gt;
&lt;/body&gt;
&lt;/html&gt;

</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
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
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

Reply to this topic