Re: File backup question


Subject: Re: File backup question
From: David J. Weller-Fahy (dave-lists-aklug@weller-fahy.com)
Date: Wed Feb 04 2004 - 21:17:42 AKST


* Bob Crosby <bob@estimations.com> [2004-02-04 16:48 -0900]:
> I'm trying to make a simple backup system, to do nightly backups to a
> removable hard drive. What I have in mind is to run a cron job that
> will write a set of tar files to this drive.
>
> ls -l /home/jobs/active-jobs/ | awk '{print $9}' >outfile
>
> And this one takes the input from 'outfile' and sends only files
> starting with letters A-D to newoutfile.
>
> awk '/^[A-D]+/{print $0}' outfile >newoutfile
>
> Now I want to concatenate the pathname 'home/jobs/active-jobs' to each line
> of newoutfile, to produce the file that tar can take as input.
>
> Can anyone tell me how to concatenate path and filename?
>
> (Or maybe make some better suggestions than the whole approach I'm
> taking...?)

Hrm. As long as you don't have a ton of weird characters in the file
names (don't know which ones, just remember to watch out for them when
shell scripting), the following should build you separate list files for
each group of letters which you could then feed to tar. I'll comment on
the bits that were not obvious to me.

#v+
#!/bin/sh
BAKLSTDIR=/home/jobs/active-jobs/
BAKLST=/path/to/backup/BAKLST-temp
BAKDIR=/path/to/backup/

cd ${BAKDIR}
# if ${BAKLST} exists then add the prefix 'old.' to it
[ -f ${BAKLST} ] && mv ${BAKLST} old.${BAKLST}
find ${BAKLSTDIR} | sed -e '1d' > ${BAKLST}

for LETTER in ABCD EFGH IJKL MNOP QRST UVWX YZ
do
        # grep returns 1 when it finds nothing matching the pattern
        # given to it: 1 == false, ! false == true, true means the
        # second bit of the expression is evaluated, and the empty file
        # created by grep finding no lines is deleted
        ! grep -i -e "^${BAKLSTDIR}[${LETTER}].*" ${BAKLST} > ${BAKLST}.${LETTER} && rm ${BAKLST}.${LETTER}
done
#v-

Sorry for sending the first copy directly to you.

Hope that helps,

-- 
dave [ please don't CC me ]
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.



This archive was generated by hypermail 2a23 : Wed Feb 04 2004 - 21:17:47 AKST