Amiga Computing - Commodore Is Awesome
Amiga Computing - Commodore Is Awesome
Amiga Computing - Commodore Is Awesome
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Looking for on easy<br />
way to organise<br />
backup operations?:<br />
Paul Overaa shows<br />
you how<br />
On many platforms, including the PC,<br />
REXX (the language upon which<br />
ARexx is based) is used primarily as a<br />
^^^ macro language for system house<br />
keeping operations. Moving and renaming sets of<br />
files, batch editing of text files, performing stan<br />
dardised backup operations and so on.<br />
This system-oriented use is perfectly under<br />
standable on these other platforms since the<br />
operating system is, to a large extent, the only<br />
other 'process' that can be communicated with.<br />
ARexx of course, has no such restrictions and in<br />
this sense <strong>Amiga</strong> users are extremely fortunate.<br />
ARexx's ability to communicate easily with<br />
other programs does tend to result however, in<br />
the potentially useful batch processing links with<br />
<strong>Amiga</strong>DOS, often taking a back seat Now this is<br />
clearly a shame because for these types of appli<br />
cations, ARexx is far more powerful than<br />
<strong>Amiga</strong>DOS's own scripting language and you<br />
need look no further than the rather neglected<br />
area of data backup to realise the possibilities.<br />
Whilst data safety is obviously the primary con<br />
cern, the objective of any type of backup arrange<br />
ments ought really to be to get some sort of sys<br />
tem going which makes routine data backup as<br />
easy as possible. It is, after all, a well known fact<br />
that procedures which are awkward tend not to<br />
get followed.<br />
Fortunately for most users, backing up a com<br />
plete high-capacity hard disk on a regular basis is<br />
almost never necessary. For example, programs<br />
themselves, once backup copies of the master<br />
disks have been made, do not need further regu<br />
lar backing up. The unwritten rule with data files<br />
of course is that you back up files only as fre<br />
quently as they change.<br />
The key to success is organisation. Make sure<br />
you have appropriate directory structures and/or<br />
hard disk partitioning (ie the creation of a number<br />
of different logical drives). One big help is to make<br />
sure you keep data files separate from the applica<br />
tions programs which create and use them.<br />
Within this highest level division of programs<br />
versus data, the next most useful hierarchy criteria<br />
is the required file backup frequency. If, for exam<br />
ple, an order file is backed up once a day, it is<br />
worth keeping that data in a directory (or hard<br />
disk partition) that contains only those files that<br />
need to be backed up with this frequency.<br />
An ARexx Example<br />
Once you have a workable backup plan available<br />
ARexx can, in most cases, completely eliminate<br />
the need for using dedicated backup utilities. Let's<br />
say, for instance, you're interested in automating<br />
the backup of a directory called 'daily' that exists<br />
on a partition called Work. In short you want to<br />
copy, to floppy disk, any files present in that direc<br />
tory whose contents have changed since the<br />
With a little organisation, plus some help from ARexx,<br />
almost all backup operations can become a piece of cake!<br />
/* backup.ren */<br />
TEHP='fiaa:T/te»pl<br />
BACKUPJ£ST='dfO:daily'<br />
A«CHlVEjn='ar<br />
drawer was last backed up.<br />
The trick here is to adopt the same method as<br />
used by most archiving utilities. Whenever a file is<br />
backed up the archive bit of the source file gets<br />
set If, when the next backup is performed, that<br />
bit is still set the file hasn't changed and does not<br />
need recopying to your backup disk.<br />
As far as doing this type of thing via ARexx is<br />
concerned the important first step is identifying<br />
the names of the files present in the chosen<br />
source directory. ARexx's address command can<br />
be used in conjunction with <strong>Amiga</strong>DOS's LIST<br />
command to generate just such a list.<br />
One approach is to set up a couple of constant<br />
definitions to point to the source directory and to<br />
a temporary file for storing the list command out<br />
put. The files, nodates and nohead switches inci-<br />
address cowaitd 'list' BACKUPJOURCE 'to' TEMP 'file; nodates nohead'<br />
if Opentfh,TEHP,'r'> then<br />
do<br />
do uhile "EOF(fli)<br />
Une=Readlri(fb)<br />
if Length(Line)>0 then<br />
do<br />
parss var line file date flags<br />
if PosURCHIVE BIT,flags)=O then<br />
end<br />
do<br />
fi Le=BACKUP_SOURCE j|fi Le<br />
say 'Batting up...' file<br />
address coanand 'copy >NIL:' file 'to' BACKJPJEST<br />
address cossand ■protect >HIL:' file '+a add1<br />
end<br />
end<br />
call Closc(fh)<br />
address comnd 'delete >HIL:' TENP<br />
say 'Operations conplete!'<br />
enc<br />
dentally can be used on the LIST command line to<br />
ensure that only the file names, size and protec<br />
tion flags values are sent to the output file. ARexx<br />
code such as...<br />
BAC«:UP_SIJUSCE=1«ort:daiLy/1<br />
TENP='Hai:t/teip'<br />
address conarancE 'list' BACKUPJOURCE 'to' TEUP<br />
'files<br />
Itodatss "ahead1<br />
therefore ends up generating a temporary file con<br />
sisting of text lines whose general format is... ,<br />
By reading these lines and splitting them into<br />
individual name, size and protection flag values<br />
using the ARexx PARSE instruction it's then easy<br />
enough to check each flag set to see whether the<br />
archive bit is clear or not Any file whose archive<br />
bit is not set represents a file that has been altered<br />
since the last backup, so all we need to do is copy<br />
all such files to the destination backup directory -<br />
resetting the archive bits of each source file as we<br />
do so.<br />
Now your individual requirements for backup<br />
are doubtless going to be different from mine but<br />
the example shown in listing 1 should give a rea<br />
sonable starting point for creating your own back<br />
up scripts. In this case it's the general ideas that<br />
are the important thing - so the thing to do is to<br />
set up some dummy source/destination directo<br />
ries on your own system (modifying the script's<br />
directory references to suit) and then experiment.<br />
Once you see how these archive bit arrangements<br />
work you should then be easily able to incorpo<br />
rate similar ideas into your own backup arrange<br />
ments!<br />
Listing 1: A typical archive bit based ARexx backing up script. Notice how the >NIL: statement<br />
is used to discard output from the copy, protect and delete commands'.<br />
<strong>Amiga</strong> <strong>Computing</strong><br />
MARCH 1997