procmail
[Top] [All Lists]

Re: Mail backup

1997-08-13 08:53:00
On Wed, 13 Aug 1997 10:29:31 -0400 (EDT),
Brock Rozen <brozen(_at_)webdreams(_dot_)com> wrote:
I'm using the following script to backup my mail. Then, using cron, I run
a program that automatically limits the number of messages in the backup
file. The problem is that it removes from the end and appends to the end
-- so all the old messages stay and all the new ones get removed. 

Uh-oh. Double-plus ungood :-)

cat $HOME/Misc/Backup/mail.general.backup | \
     /usr/local/bin/formail -1000s > $HOME/Misc/Backup/temp.general.backup
mv -f $HOME/Misc/Backup/temp.general.backup 
$HOME/Misc/Backup/mail.general.backup
rm -f $HOME/Misc/Backup/lock.mail.backup.general

The backup script in the procmailex man page is much nicer because it
uses existing facilities to a larger extent. If you want mbox format,
you need to do the following: 

  * Find out how many messages are in the mbox file
  * Subtract 1000 (or however many you want to keep)
  * formail +number < file > newfile

Alternatively, as you infer, you could somehow write to the beginning
of the file each time, but that's verrry wasteful. 

I can't come up with anything truly elegant, but the following ideas
come to mind: 

  * When you save a message to backup, also echo an empty line to a
    "counter" file. That way, finding out how many message you have
    on file is simple. (You could also run it through formail twice, 
    the first time to count how many messages you have :-)
  * If you can be confident your software will quote any extra From_
    lines, grep -c '^From ' mboxfile will tell you how many messages
    you have. 

Doing arithmetic in the shell is often very awkward. You might want to
rewrite part of this in Perl or something just to avoid the ugly expr
call. 
  The following will assume the grep -c thing will work for you.
  This is, of course, untested and with NO WARRANTY for anything,
including MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, or
READABILITY (that's why they use uppercase for these statements, I'm
sure). In other words, test it.

  #!/bin/sh

  lockfile mail.general.backup     # see comment below!!

  temp=/tmp/backup.$$

  msgs=`grep -c mail.general.backup`
  keep=`expr $many - 1000`

  mv mail.general.backup $temp
  formail +$keep -s < $temp >mail.general.backup

  lockfile -u mail.general.backup
  rm $temp

You should be consistent about what you call your file, and let
Procmail figure out what to call the lock file, otherwise Procmail
might gladly overwrite the backup file while you're doing things to
it, even if you think you have it locked.

:0Wc:Misc/Backup/lock.mail.backup.general
* ! ^X-Backup: Disable
$BACKGFILE

So BACKGFILE should be set to (where-ever)/mail.general.backup, and
don't say anything after the second colon -- also, is the :W flag
accomplishing anything here?

/* era */

-- 
Defin-i-t-e-ly. Sep-a-r-a-te. Gram-m-a-r.  <http://www.iki.fi/~era/>
 * Enjoy receiving spam? Register at <http://www.iki.fi/~era/spam.html>

<Prev in Thread] Current Thread [Next in Thread>