[wellylug] bash scripting help
Jaisankar Arunachalam
jsankar at slingshot.co.nz
Wed Aug 4 13:29:21 NZST 2004
Hi Mark,
Just a thought.
May be you can have all your backup files starting with name like
'somename_yyyyddmmhhmm'.
You can get previous dates using the command " date --date='7 days ago' "
(you can substitute 7 with any number).
In your script you can remove/move all the file names created 7 days ago.
The sample script may look some thing like this.
SYSDATE=`date "+%Y%m%d_%H:%M %Y/%m/%d %H:%M"`
PREVWEEK=`date --date='7 days ago' +%Y%m%d`
rm somename_$PREVWEEK*.txt
cp somefile some_name_$SYSDATE.txt
Cheers
Jai
----- Original Message -----
From: "Mark Signal" <mark at databackup.co.nz>
To: "Wellylug" <wellylug at lists.naos.co.nz>
Sent: Wednesday, August 04, 2004 12:18 PM
Subject: [wellylug] bash scripting help
> Hi
>
> I have started playing with rsync's -b and -backup-dir options which
creates
> backups of files prior to changing or deleting them.
>
> by using the date +%A I can have backup/Monday backup/Tuesday
> backup/Wednesday etc (I only want to keep 7 days data)
>
> to avoid these directories being deleted by the next rsync (--delete is
> used) I use the rsync --exclude=backup/ option
>
> this means that the data stored in the backup directories is cumulative
> which I don't want. I can run a "rm -rf backup/`date +%A` at the beginning
> of each rsync which is fine if the backup is only run once every day. BUT
if
> rsync is run multiple times on the same day it will delete the prior
backup
> of today's changed/deleted data....
>
> if you are still with me... what I need to do is ensure that the rm -rf
> portion of the rsync script only runs on the first time that the scrip is
> run each day.
>
> Maybe I could create a unique token file at the end of the first days
rsync
> and check for it each time rsync is run..
>
> something like ... (on Monday for examples sake)
>
> at the end of each rsync: touch (or mkdir -P?) backup\Monday\token\`date
> +%j` (day of year)
>
> at the beginning of each rsync: compare date +%j with
> /backup/Monday/token/* and if they are the different then
> rm -rf backup/Monday/
>
> I am unsure if this is the best way to do this and how exactly to script
the
> if-compare-then part of it.
>
> any thoughts/suggestions appreciated
>
> cheers
>
> Mark
>
>
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.733 / Virus Database: 487 - Release Date: 2/08/2004
>
>
> --
> Wellington Linux Users Group Mailing List: wellylug at lists.naos.co.nz
> To Leave: http://lists.naos.co.nz/mailman/listinfo/wellylug
More information about the wellylug
mailing list