log and xac files

Jean-David Beyer jdbeyer@exit109.com
Tue, 27 Mar 2001 14:49:32 -0500


Phillip J Shelton wrote:
> 
> The *.xac files are old copies of the base data file. and the *.log
> files are a presently unused list of how the different *.xac files
> differed.  If you are the paranoid type you can keep the last few
> *.xac files around otherwise you can delete them all without
> worries.
> 
> Rich Shepard wrote:
> 
> >   What do folks do with the collection of *log and *xac files that
> > accrue in
> > the gnucash data directory? Are they ever incorporated into the
> > base data
> > file? Do I just rm them now and then?
> >
> >   I'd appreciate suggestions for what to do about them (including,
> > ignore
> > them).
> >
What I do is have an entry in my personal crontab file that looks like
this:

02 04         * * *  /home/jdbeyer/GnuCash/GAWK.cron

/home/jdbeyer/GnuCash/GAWK.cron is a trivial executable file that
looks like this:

#!/bin/bash

cd /home/jdbeyer/GnuCash
`ls -lt | /bin/gawk -f /home/jdbeyer/GnuCash/GAWK.script`
cd ..
/bin/mail jdbeyer -s "Cleaned ~/GnuCash" <<EOF
You might want to check it.
EOF

and /home/jdbeyer/GnuCash/GAWK.script` contains:

# GnuCash cleanup script.

# This (g)awk script rummages around in ~jdbeyer/GnuCash and removes
# all files a week older than the current (JeanDavid) file. I.e.,
# we return the current file and a week's previous .log and .xac
files.

# There may be a bug in the line: total *=  365.
# It will be off by all the leap years since 0000, but since
# we should never have backup files that much older than the
# current filee, I think it should be OK.

# Get into ~jdbeyer/GnuCash and run:

# `ls -lt | gawk -f GAWK.script`

function filedate(Month, Day, YearTime,  leap, total, timestamp)
{
        if(index(YearTime, ":") == 0) {
                total = YearTime;
        }
        else {
                timestamp = systime();
                total = strftime("%Y", timestamp)
        }
        if((total % 4) == 0) {
                leap = 1
        } else {
                leap = 0
        }
        total *= 365;
        total += leap;

        if(Month == "Jan") total += 0;
        if(Month == "Feb") total += 31;
        if(Month == "Mar") total += 59;
        if(Month == "Apr") total += 90;
        if(Month == "May") total += 120;
        if(Month == "Jun") total += 151;
        if(Month == "Jul") total += 181;
        if(Month == "Aug") total += 212;
        if(Month == "Sep") total += 243;
        if(Month == "Oct") total += 273;
        if(Month == "Nov") total += 304;
        if(Month == "Dec") total += 334;

        total += Day;

        return total;
}
$1 != "total" && !/GAWK.*/ && $9 == "JeanDavid" {newest = filedate($6,
$7, $8);
                                                 #print newest;
                                                }
$1 != "total" && !/GAWK.*/ && $9 != "JeanDavid" {#print filedate($6,
$7, $8), $6, $7, $8, $9;
                                                 if(filedate($6, $7,
$8) < (newest - 7))
                                                                print
"rm", $9
                                                }

My main data file is named JeanDavid, so all the others are either
JeanDavid.stuff or translog.stuff. What this setup does is examine the
last time the date that JeanDavid was most recently modified. It then
deletes all other files that are at least a week older than that. 

Or that is what it does if there are no serious bugs in the above
program. If there are bugs, I hope someone will let me know. 

The only bugs I know of is that it computes days from year 0000 and
gets the leap years wrong in the distant past, and I seem to get the
day off by 1 before Feb 29 in leap years. Since I keep files only for
a week (the 7 without the $), I have not bothered to fix these yet.

-- 
-- 
 .~.  Jean-David Beyer           Registered Linux User 85642.
 /V\                             Registered Machine    73926.
/( )\ Shrewsbury, New Jersey     http://counter.li.org 
^^-^^ 2:45pm up 1 day, 20:33, 3 users, load average: 2.10, 2.08, 2.01