Frequent and automatic backups
We've all got huge hard disks now with plenty of space to hold 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. A formal Source Control System would
solve both problems but that might be too restrictive in a small
development shop like ours. Instead, we use this routine to generate
a unique folder name based on the datestamp and copy the files across
to this folder.
This is the Visual FoxPro implementation, there is a similar
version here in
Access VBA
.
#DEFINE SU_HOME
'\Projects\web\'
lcToday =
DTOS(DATE())
lcNow =
CHRTRAN(TIME(),
':', '-')
lcTimeStamp = lcToday + '_at_' + lcNow
lcDevDir = 'D:' + SU_HOME + 'Dev'
lcBackupDir = 'E:\DevBackup' + SU_HOME + 'Backup\' + lcTimeStamp
fso=
CREATEOBJECT
('Scripting.FileSystemObject')
fso.CopyFolder (lcDevDir, lcBackupDir)
fso = null
This 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 E: which
has a folder with the same name as the development area. All the development
files are copied here into a new folder with a name like Backup\20021023_at_16-53-58.
It's not a pretty name but it is readable and it will be unique unless I manage to
run two backups within the same second.
A typical use is to copy:
D:\MyDevWork\*.*
to
E:\Devbackup\MyDevWork\Backup\20021023_at_16-53-58\*.*
Note that you will get a COM error if the folder E:\Devbackup\MyDevWork\Backup\ does not
exist. A bit more work with error trapping and the File System Object will solve this
problem.
In my 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 when a programmer's backups are
plain text files. At the time of writing we have 97,652 backup files taking up 8.62 GB
of a 80 GB drive that's installed in a spare drive bay. We've also got a library of
weekly and monthly backups on CD. The drive is just another level of insurance.
|