Frequent, automatic backups


We've all got huge hard disks now with plenty of space for as many backups as anyone could need. The only restriction is the hassle of making the backup and the difficulty of finding a good name for each generation. We use this routine to solve both problems. This is the Visual FoxPro implementation, there is some similar Access VBA version here.

#DEFINE SU_HOME '\Projects\web\'

*-- Getting the date as yyyymmdd is easy.
lcToday = DTOS(DATE())

*-- The time has colons between hours, minutes, and seconds.
*-- These are illegal in a file name so change them to underscores.
lcNow = CHRTRAN(TIME(), ':', '-')
lcTimeStamp = lcToday + '_at_' + lcNow
lcDevDir = 'E:' + SU_HOME + 'Dev'

*-- The folder F:\DevBackup\....\Backup\ must exist
lcBackupDir = 'F:\DevBackup' + SU_HOME + 'Backup\' + lcTimeStamp

fso= CREATEOBJECT ('Scripting.FileSystemObject')
fso.CopyFolder (lcDevDir, lcBackupDir)
fso = null

The code takes the development folder for this project (defined as SU_HOME) and uses WSH (the Windows Scripting Host) to copy this folder to drive F: which has a folder with the same name as the development area. All the development files are copied here with a name like Backup\20021023_at_16-53-58. Not a pretty name but readable and almost certain to be unique.

A typical use is to copy:

E:\MyDevWork\*.*
to
F:\Devbackup\MyDevWork\Backup\20021023_at_16-53-58\*.*

Note that you will get a COM error if the folder F:\Devbackup\MyDevWork\Backup\ does not exist. A bit more work with error trapping and the File System Object will solve this problem.

In FoxPro development work, I have this routine tied to the F12 key with an ON KEY LABEL F12 ... statement. This allows me to create a complete backup at any stage of development by pressing F12.

You may think that regular backups will take too much space but today's hard disks are sized to hold hours of video and have plenty of space for a programmer's backups. At the time of writing we have 69,297 backup files covering 5.09 GB of a 40 GB drive.

Hints & tips

The textbox class in Visual FoxPro 9 has a new Autocomplete property which shows the user the previous values that have been entered in that textbox.
Autocomplete in VFP 9

Your Access database will look more impressive if you add custom toolbars...
Custom toolbars

FoxPro has always had functions to read and write files at a low level...
Foxpro low level file functions

More...
More pages of hints and tips for users of Microsoft FoxPro and Access databases.

Site Map