how do we create an automatic backup of a database

sunilvedula

Sunil
Local time
Today, 05:40
Joined
Jan 18, 2007
Messages
138
Hi to all,

what i want is to be able to create a backup of the database with a click of a button. If the admin wants to do that.

How do i do that. Any code or procedure to follow would be of great help.

thank you

sunil.v
 
Well, ...

Technically this cannot be done from inside the database. You see, you probably have it open at the time. Windows file locking might stop you even if Access would let you try it.

But...

If anything will work, look in VBA help for a COPY or FILECOPY verb.

If you try it and get file lock messages, you were warned. Normally the only way to make a really good backup of a file is when it is totally closed.
 
i tried this code but there is an error

Code:
Public Function BackupAndZipit()

'This function will allow you to copy a db that is open,
'rename the copied db and zip it up to anther folder.

'You must set a reference to the 'Microsoft Scripting Runtime' for the CopyFile piece to work!

'Thanks to Ricky Hicks for the .CopyFile code

Dim fso As FileSystemObject

Dim sSourcePath As String
Dim sSourceFile As String
Dim sBackupPath As String
Dim sBackupFile As String

sSourcePath = "J:\Disputes_PE\Database"
sSourceFile = "O4_Data.mdb"
sBackupPath = "C:\Database\Backups\"
sBackupFile = "BackupDB_" & Format(Date, "mmddyyyy") & "_" & Format(Time, "hhmmss") & ".mdb"

Set fso = New FileSystemObject


[QUOTE]fso.CopyFile sSourcePath & sSourceFile, sBackupPath & sBackupFile, True  [/QUOTE]


Set fso = Nothing

Dim sWinZip As String
Dim sZipFile As String
Dim sZipFileName As String
Dim sFileToZip As String

sWinZip = "C:\Program Files\WinZip\WinZip32.exe" 'Location of the WinZip program
sZipFileName = Left(sBackupFile, InStr(1, sBackupFile, ".", vbTextCompare) - 1) & ".zip"
sZipFile = sBackupPath & sZipFileName
sFileToZip = sBackupPath & sBackupFile

Call Shell(sWinZip & " -a " & sZipFile & " " & sFileToZip, vbHide)

Beep
MsgBox "Backup was successful and saved @ " & Chr(13) & Chr(13) & sBackupPath & Chr(13) & Chr(13) & "The backup file name is " & Chr(13) & Chr(13) & sZipFileName, vbInformation, "Backup Completed"

If Dir(sBackupPath & sBackupFile) <> "" Then Kill (sBackupPath & sBackupFile)

End Function

The error comes in the selected quote. It says file not found. do we have to create a file in the specified drive or would the program create it automatically. pls help me out!
 
How do we create a password for backup

Hi,

The backup was successful! However, we are now required to create a password for the backup file.

It should prompt us to create a password for the backup file when we click on the 'Backup' Button. Is it possible? If so, how?:o

Thank you in advance.

Its
Sunil V.
 
can you tell me how did you manage to do it.

1- where did you put the function code
2- from where did you call the function (a button click or upon exit application)
3- how did you solve the not found issue in you message above

thanks
 
I am sorry for the delay in responding. I was stuck with worin in office all these days. I initially created the path where it was to be stored and then i checked the refernces "Microsoft Scripting Runtime",. The code which i am follwoing right now is below: I called the function with a button click placed on a form. I put the function code in modules in general declarations. I have taken out winzip function as it would nothelp me in xp.

Public Function BackupAndZipit()


Dim fso As FileSystemObject
Dim sSourcePath As String
Dim sSourceFile As String
Dim sBackupPath As String
Dim sBackupFile As String
Dim DB As New Access.Application

sSourcePath = "J:\Disputes_PE\Database\"
sSourceFile = "O4_Data.mdb"
sBackupPath = "J:\Disputes_PE\CORE\Backup\"
sBackupFile = "BackupDB_" & Format(Date, "mmddyyyy") & "_" & Format(Time, "hhmmss") & ".mdb"

Set fso = New FileSystemObject

fso.CopyFile sSourcePath & sSourceFile, sBackupPath & sBackupFile, True

Set fso = Nothing

Beep
MsgBox "Backup was successful and saved @ " & Chr(13) & Chr(13) & sBackupPath & Chr(13) & Chr(13) & "The backup file name is " & Chr(13) & Chr(13) & sBackupFile, vbInformation, "Backup Completed"

End Function
 
Im sure theres a billion reasons why you shouldnt do this from more seasoned access developers out there, but being a noobie, I decided to simply use 1 line of code for each table in my database.... The transferdatabase command can make a copy of whatever you desire inside of your database to another database file.

On a side note, if anyone can tell me why this would be a bad idea over the examples sited, please do 8)
 
I tried Mr.Sunilvidula's code. But it is not working. Would you please explain it more how to do it? Thanks in advance.
 
HI,

what was teh error you received. It is working for me till date. Any issue please let me know so that i can be of help. Sorrry for being so late
 
Thanks Mike the link http://www.members.shaw.ca/AlbertKallal/zip/index.htm works extremly fine. we can use this too....:)

I was able to get this to work with my code, but how do I eliminate all the folders it preserves.

For example: When I double click the ZIP, it has all the original folders from my Documents & Settings/user/desktop/etc...

I would like the ZIP to open up to the files only, not a directory tree, 10 folders deep.

Any ideas?

Code:
MakeZip [COLOR="Red"]dbPath & "\Exports\" & Year(Now - 1) & " - 12\" & strRepID & " - " & strRep & "\*.pdf"[/COLOR], [COLOR="Blue"]dbPath & "\Exports\" & Year(Now - 1) & " - 12\" & strRepID & " - " & strRep & ".zip"[/COLOR]

:confused:
 
Hello,

Does anyone know any switches for this method, that will allow me to eliminate the subfolders from the archive?

Any help is appreciated.
 
I went to the authors websiye, and sent him an email requesting some help, but I'm sure he is far to busy to help me. I figured it couldn't hurt. If anyone has any more suggestions, please let me know.
 
I am not with the relevant DB at the moment as I am in the process of moving. But should be OK in a couple of days to look.

But mine was only producing a Zipped version of the DB, nothing else. I ran it from within the DB itself.

As to my own code that only dealt with the Zipped file that was produced. Copied it to another folder and with date/time stamp on the file name.
 
I just found a copy of the DB on this laptop.

The DB is called Viper. Ran the zipper from within Viper which produces Viper.zip. Each time it is run it simple replaces Viper.zip. Nothing else is there except the DB.

I wonder if he has made some changes to it?
 
The original author responded to my email, and informed me that he has updated the program with the modifications completes. You must redownload his example, and replace your existing modules for it to work. Now my ZIP files contain only the PDFs, instead of having 10 subfolders, and then the PDFs.

Here's the link: http://www.members.shaw.ca/AlbertKallal/zip/index.htm
 
The original author responded to my email, and informed me that he has updated the program with the modifications completes. You must redownload his example, and replace your existing modules for it to work. Now my ZIP files contain only the PDFs, instead of having 10 subfolders, and then the PDFs.

Here's the link: http://www.members.shaw.ca/AlbertKallal/zip/index.htm

I was under the impression that Zip did not reduced a PDF by much.

As a side note the reason I use his Zip program is simply to back up the DB while it is open.
 

Users who are viewing this thread

Back
Top Bottom