Solved

How to run nightly backup of ms access 2007 database tables only

Posted on 2010-11-18
11
578 Views
Last Modified: 2012-05-10
Hi, I have a database.  I have seen another system in which the programmer set  the db to create a backup of itself on the drive nightly.  How can I set this? Thanks
0
Comment
Question by:LadyHagood
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 57
ID: 34165997

  A JET/ACE database can't really backup itself because you can't backup a open file accurately.

  What you need is another DB that has code to perform the backup (which would be a simple file copy), a batch file, or use some type of backup utility.

JimD.
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 250 total points
ID: 34166135
try this codes, place in a regular module



Option Compare Database
Option Explicit

Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long

Public Function fnc_CopyFile(ByVal strCurrentDB As String, ByVal strBackUpCopy As String) As Boolean

    Dim ret As Long

    On Error Resume Next
   
    DoCmd.Hourglass True
    ret = CopyFile(strCurrentDB, strBackUpCopy, True)
    If ret = 0 Then
        MsgBox "File Copy failed.", vbCritical, "File Copy"
        fnc_CopyFile = False
    Else
        fnc_CopyFile = True
    End If
    DoCmd.Hourglass False
End Function

to use, pass the path and name of the currentdb and the path and name of the backup copy

fnc_CopyFile(pathOfcurrentdb,pathofbackupcopy)

Open in new window

0
 
LVL 7

Accepted Solution

by:
shaydie earned 250 total points
ID: 34166373
Another approach.. if you only want to backup the tables and not the entire db.. It will take some modification.

Place the code (Function) below in a module, Create a query for each table data you want to backup, in the code change the 'LocalQueryNameTable?'s to the name of the queries and the 'BackupTable?'s to the name of the backed up tables, add entries as needed for each table to be backed up, change the Path ("S:\Backup\DataBase\") to the actual path of where you want the backups stored.

Create a macro that calls the DBBackup function and then exits the database.

Create a batch file to open the db and run the macro you created.
Something like this:

"C:\Program Files\Microsoft Office\Office12\msaccess.exe" "Path to your Database" /x MacroName


Setup a scheduled task to run the batch file you created.





Public Function DBBackup()
    Set wrkDefault = DBEngine.Workspaces(0)
    Set DB = CurrentDb
   
date1 = Format(Date, "DDMMMYYYY")

        Set dbsNew = wrkDefault.CreateDatabase("S:\Backup\DataBase\" & date1 & "-DBBackup.mdb", dbLangGeneral)
        dbsNew.Close

    DoCmd.TransferDatabase acExport, "Microsoft Access", "S:\Backup\DataBase\" & date1 & "-DBBackup.mdb", acTable, "LocalQueryNameTable1", "BackupTable1"
    DoCmd.TransferDatabase acExport, "Microsoft Access", "S:\Backup\DataBase\" & date1 & "-DBBackup.mdb", acTable, "LocalQueryNameTable2", "BackupTable2"
    DoCmd.TransferDatabase acExport, "Microsoft Access", "S:\Backup\DataBase\" & date1 & "-DBBackup.mdb", acTable, "LocalQueryNameTable3", "BackupTable3"

End Function
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34166503


btw,
the codes a posted at http:#a34166135 is placed in the db and called in the same db that you want to backup..

to use, you can call the function from the click event of a button

private sub cmdBackUp_Click()
dim x  as integer
x = fnc_CopyFile(CurrentDb.Name, CurrentProject.Path & "\BackUp.mdb")
end sub
0
 
LVL 57
ID: 34166755
<<the codes a posted at http:#a34166135 is placed in the db and called in the same db that you want to backup..>>

  While that will work, it's not a hot idea.  If the DB has any activity during the backup, you may end up with an inconsistent backup.

  Only backup utlitities with a special open file option, which reach into the OS and ensures a quiet point and does a atomic move (ensures that the file is copied in it's entirety without any I/O to it occuring) will give you a consistent backup on an open file.

JimD.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34166855
<If the DB has any activity during the backup, > 
i don't think, someone with a sane mind will backup a db that is not idle..
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 34169545

<i don't think, someone with a sane mind will backup a db that is not idle..>
The issue is that the OP did not state if the DB might be open or not.

besides, as you know, there are dozens of posts here where people try just that...
;-)

Jeff
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34169555
...and as a developer, you should prevent that from happening.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 34169590
LadyHagood,

<I have seen another system in which the programmer set  the db to create a backup of itself on the drive nightly.>
Then can you ask that programmer what they did?

The other issue here is the state of the machine that will be doing the backup.
Can you be sure that this machine will be On?
(Not, Hibernating, Asleep or on Standby)

Suppose a night gets skipped for some reason, is this OK?
Suppose the Backup fails or is incomplete?

JeffCoachman
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 34169641
<...and as a developer, you should prevent that from happening.>
...It is not clear if the OP is a Developer or just a person being asked to do a backup.

My point was that you can be perfectly sane and make a mistake about something you don't know.

For example what I first started driving, I was "Sane" but I did not know you had to check the oil in your engine.  So I didn't and the engine blew.

Now, you could argue that no sane person would drive a car for months and never check the oil, but in this situation I did not know.

The same could apply here.
It's just that a comment like:
<i don't think, someone with a sane mind will backup a db that is not idle..>
...implies that if a person did this, that they were "not" sane...

;-)

Jeff




0
 
LVL 75
ID: 34171000
"How to run nightly backup of ms access 2007 database tables only"
                                                                            ^^^^^^^^^^^^^^^^^^^^
LadyHagood:
Let me ask a question:
Is this "access 2007 database tables only" ... a  'back end' db that only has tables and nothing else?  

If so, then I would have to ask how ... the CopyFile solution present above is going 'run itself' ... per your statement "create a backup of itself" ?

And clicking a command button to run that code would imply that ... you are 'manually' in that db to do so.  And if that is the case, then yes, it will back up the db ... which eliminates the issue of

"If the DB has any activity during the backup, you may end up with an inconsistent backup." ...

because that *is* the 'activity' ... executing the code to backup the db you are in.  No other activity is going to occur while that code is execution.   Well ... unless there are some front ends connected to this back end ... and someone is writing data at that moment.  Who knows what would happen then ??  And even if this is still a standalone db, it's not really going to back 'itself' up, short of some Timer scheme that triggers at a specific time and runs the CopyFile code.  But that would imply that someone has the db open, and they could be doing some 'activity' that might would interfere with the CopyFile process.

So, this all seems a bit ... convoluted to me ...

mx






0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question