473,473 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to automate database backup

12 New Member
I'm creating a database to store records of user accounts and want to have a way to automate backups. I know Access has the backup database function. Is it possible to use that so that it backups on some sort of regular basis, say every day at 5PM or something? Or would this be more of a Windows function?
Mar 4 '11 #1
4 7838
Rabbit
12,516 Recognized Expert Moderator MVP
Since you can't ensure that Access will be running all the time, I would schedule the backup through Windows.
Mar 4 '11 #2
beacon
579 Contributor
I second Rabbit's suggestion. I use Windows' Scheduled Tasks and a VBScript to backup the databases I maintain.

If you'd like a sample script, I'll be happy to post one.
Mar 5 '11 #3
neelsfer
547 Contributor
Thx it would be nice to get it Beacon. I am looking for code to backup with vba
Mar 6 '11 #4
beacon
579 Contributor
The code isn't VBA...it's VBScript. Like Rabbit mentioned, the more reliable way to schedule the backup is using Windows, specifically Windows Scheduled Tasks.

I use a VBScript that I've placed in my C:\Temp folder and have a Windows schedule set to run it everyday at 6:00 AM. I also have written a subroutine that emails me if the script runs to completion. I guess technically it doesn't necessarily guarantee that the database will be backed up, but it has worked for me for a few years now.

I should mention that the code backs up the database every day for a maximum of 14 days. The 15th backup is deleted in an effort to save space...you can always remove that part of the code if you want to save ALL copies of the database.

Here's sample code (this code needs to be written in a text editor, like Notepad, and save with a .vbs extension...you'll also need to change the paths, folder names, and email info to match your own):
Expand|Select|Wrap|Line Numbers
  1. '*********************
  2. '*  Main Code Block  *
  3. '*********************
  4.  
  5. dim strDriveLetter, strRemotePath, objNetwork, objMessage
  6.  
  7. strDriveLetter = "Z:"
  8. strRemotePath = "YOUR_PATH_HERE"    'You need the literal path, not just the drive letter
  9.  
  10. set objNetwork = CreateObject("WScript.Network")
  11.  
  12. On Error Resume Next 'if drive is already mapped, go to next statement
  13. objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
  14.  
  15. Call BackUpDatabase
  16.  
  17. Call CleanUpFolder
  18.  
  19. Call SendEmail
  20.  
  21.  
  22. '*****************
  23. '*  End of Main  *
  24. '*****************
  25.  
  26. Sub BackUpDatabase()
  27.  
  28.     dim strDriveLetter, strRemotePath, objNetwork
  29.     dim mydate, location, path, filename
  30.     dim filesys, destination
  31.  
  32.     strDriveLetter = "Z:"
  33.     strRemotePath = "YOUR_PATH_HERE"
  34.  
  35.     set objNetwork = CreateObject("WScript.Network")
  36.  
  37.     On Error Resume Next 'if drive is already mapped go to next statement
  38.     objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
  39.  
  40.     mydate = replace(date, "/", "-")
  41.  
  42.     location = "FOLDER_PATH_AND_NAME_OF_THE_DATABASE_THAT_NEEDS_TO_BE_BACKED_UP"
  43.     path = "PATH_WHERE_THE_DATABASE_WILL_BE_BACKED_UP+MINUS_THE_FILE_NAME"
  44.     filename = "DATABASE_BACKUP_COPY_NAME"
  45.  
  46.     set filesys=CreateObject("Scripting.FileSystemObject")
  47.  
  48.     destination = path & filename & mydate & ".mdb"
  49.  
  50.     If filesys.FileExists(location) Then
  51.        filesys.CopyFile location, destination
  52.     End If
  53.  
  54.     objNetwork.RemoveNetworkDrive strDriveLetter
  55.  
  56. End Sub
  57.  
  58. Sub CleanUpFolder()
  59.  
  60.     dim path, filename, filesys, choice
  61.     dim myArray()
  62.     redim myArray(45)
  63.     dim counter, dcounter, thedate, rdate
  64.  
  65.     path = "PATH_WHERE_THE_DATABASE_WILL_BE_BACKED_UP+MINUS_THE_FILE_NAME"
  66.     filename = "DATABASE_BACKUP_COPY_NAME"
  67.  
  68.     set filesys=CreateObject("Scripting.FileSystemObject")
  69.  
  70.     dcounter = 60
  71.  
  72.     for counter = 1 to ubound(myArray)
  73.         thedate = date - dcounter
  74.  
  75.         rdate = replace(thedate, "/", "-")
  76.  
  77.         rfile = path & filename & rdate & ".mdb"
  78.  
  79.                 if filesys.fileexists(rfile) then
  80.                     filesys.deletefile rfile
  81.         end if
  82.  
  83.         dcounter = dcounter - 1
  84.     next
  85.  
  86. End Sub
  87.  
  88. Sub SendEmail()
  89.  
  90.     dim htmlOpen, htmlFontOpen, myText, htmlFontClose, htmlClose
  91.  
  92.     htmlOpen = "<HTML><Body>"
  93.     htmlFontOpen = "<Font Face=Verdana Size=2 Color=Navy>"
  94.     myText = "Script Successful..."
  95.     htmlFontClose = "</Font>"
  96.     htmlClose = "</Body></HTML>"
  97.  
  98.     Set objMessage = CreateObject("CDO.Message") 
  99.  
  100.     With objMessage
  101.         .Subject = "Scheduled Task Successful " & date & " -- YOUR DATABASE NAME"
  102.         .From = "YOUR_EMAIL_ADDRESS" 
  103.         .To = "YOU_EMAIL_ADDRESS" 
  104.         .HTMLBody = htmlOpen & htmlFontOpen & myText & htmlFontClose & htmlClose
  105.  
  106.         '==This section provides the configuration information for the remote SMTP server.
  107.         '==Normally you will only change the server name or IP.
  108.         .Configuration.Fields.Item _
  109.         ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
  110.  
  111.         'Name or IP of Remote SMTP Server
  112.         .Configuration.Fields.Item _
  113.         ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "YOUR_EXCHANGE_SERVER"
  114.  
  115.         'Server port (typically 25)
  116.         .Configuration.Fields.Item _
  117.         ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
  118.  
  119.         .Configuration.Fields.Update
  120.  
  121.         '==End remote SMTP server configuration section==
  122.  
  123.         .Send
  124.  
  125.     End With
  126.  
  127. End Sub
  128.  
Mar 7 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Konrad | last post by:
I have an internet portal based on MySql database and what I need is to make a database backup , after each actualization of data. I know how should PHP code look like but I have no idea how to...
2
by: newbiegca_sqlsever2000 | last post by:
Question 1 3 GHZ CPU (Intel pentium 4) single cpu + 2 GB Memory + SCSI HDD Database size 10 GB - How long will full database backup take if the backup is writing a file to the hard disk...
0
by: Vincento Harris | last post by:
I implement manual log shipping per http://www.sql-server-performance.com/sql_server_log_shipping.asp Full Backups are configured to overwrite current backups(backup with init) The process...
12
by: siliconmike | last post by:
How do I synchronize MySQL table data of my home PC with latest data from a remote server ? My home PC is on a very slow internet connection, so implementing replication will cause long time...
2
by: mxd349 | last post by:
Operating system: Linux 7.X DB2 version: 8.1 I am new to DB2 and I have 2 problems: 1- Although I have schedule a database backup for 9:30 PM nightly, it runs at 10:16 PM. I have scheduled...
1
by: Najm | last post by:
Hi All, I am facing this issue very frist time. I add a logical device as following: USE master GO EXEC sp_addumpdevice 'disk', 'AdvWorksData',
3
by: Bernard Dhooghe | last post by:
Suppose a running database (DB2 UDB) with all containers being SMS based (file system as JFS or JFS2 on AIX). How to make a backup (online) by doing a file system backup and not a database...
0
by: chinna | last post by:
Hi , Can anybody help me in taking up the database backup. I don't have any idea about db2 and know a bit in oracle. In oracle we can import and export data that may be in the same database...
0
by: Varan | last post by:
hai, now we are using batch file for take backup at time of start services and stop services. we need option for take database backup at time 1. System Start ...
1
by: viper888 | last post by:
Hi there, How can I automate may database backup using query analyser? My routine goes this way: 1. Every 5:00pm check Enterprise manager who is currenlty logged on to sql server. 2. If there...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.