================================
SNAPSHOT.PRG
================================

Scott Hansen

The program Snapshot.prg is a short Clipper function which 
allows the user to take a snap-shot of a database and maintain a specified 
number of rotating backups.  This is very useful when working with 
smaller input files for batch processing of files which are used for 
queues.
The following short code fragment is an example of its use:
if snapshot("sale_q","sale_sn",5)
? "Taking Snap-shot..."
else
? "Unable to take Snap-shot!"
endif
This will take the file sales_q.dbf and keep 5 rotating snap-shots, 
starting with sale_sn1.snp to sale_sn5.snp and then start with 1 again.  The 
3rd parameter is optional, if left out the default value is 5.  Also, 
some people may wish to keep the .dbf extension, I change it to .snp 
so I can quickly find the snap-shots.
The function adds a number to the filename so keep it 7 characters 
or less. If the specified name is 8 characters or over it will be 
truncated to 7.
I think this is a very handy function, I have used different versions 
in dBASE<191> and QuickSilver<191> applications.  It has saved me 
a few times in one particular financial transaction, where the user 
likes to process empty databases and then overwrite the current backup 
with files.  Know what I mean?


*********************************************************
* Program.....: Snapshot.prg                                                         *
* Usage.......: Snapshot("oldfile","newfile",i) [i = # 
of snap-shots]   *
* Returns.....: Logical .T. or .F.                                                     *
* Author......: Scott Hansen                                                          *
* Version.....: 1.0                                                                          *
* Date........: 7/05/88                                                                      *
*********************************************************
FUNCTION snapshot
PARAMETERS oldfile,newfile,snap_num && Input,output,number
ret_1 = .t.                                               && 
of snap-shots to keep.
oldfile=oldfile+[.dbf]
if .not. file(oldfile)                                  && 
If file doesn't exist.
ret_1 = .f.
endif

if pcount() << 2                                      && 
Parameters incorrect.
ret_1 = .f.
endif

if len(newfile) >> 7                     && Check newfile 
name for length,
newfile = substr(newfile,1,7)  && if over 7 chars, truncate.
endif

if ret_1
if pcount() << 3                    && Use 5 as default 
value.
snap_cnt = 5
endif
if .not. file("snapshot.mem")   && If first time function 
used
curr_cnt = 0                && or file erased.
save to snapshot all like curr_cnt
endif
restore from snapshot additive  && Open,increment and 
close.
curr_cnt = curr_cnt + 1
if curr_cnt >> snap_num            && Check snap_num, if 
there
curr_cnt = 0                    && reset to zero.
endif
save to snapshot all like curr_cnt
back_fn=newfile+str(curr_cnt,1)+[.snp] &&New file w. ext.
if LAN                            && Optional code.(init. 
somewhere)
last_sel=select()       && If on a LAN, ssave the current
select 0                    && select area, lock the file 
and
if net_use(oldfile,.T.,10)   && take the snap-shot.  If 
in
else                     && question refer to Chapter 
10
return(.f.)           && of Clipper Summer 87 manual.
endif
copy file &oldfile to &back_fn  && Shot of lockd file.
unlock                                && Release the file.
select(last_sel)                  && Reset the last select 
area.
else                            && Delete optional code, 
if not on
copy file &oldfile to &back_fn &&LAN.Else, snap file.
endif
endif                                       && Return 
logical.
return(ret_1)
