2

I need to write a procmail rule or rules that's a bit beyond the basics. I have Bacula installed and I want all mail where the subject begins with Bacula: Backup OK for to be moved into a folder named backups -- these are good backups so I don't need to regularly read these messages, but I want to keep them for posterity. This much is, of course, easy.

Now the harder part. I need to know that backups are indeed running (as opposed to failing with ERROR in the subject) and I don't trust myself to ensure that the unread mail count of my backups folder is increasing daily. So I see a couple of different options:

  1. Allow one specific OK message through to my in-box. For example, Bacula: Backup OK for FOO goes to my in-box (and ideally backups too so I can just delete the copy in my in-box while still having a copy also in backups for posterity reasons). Meanwhile Bacula: Backup OK for BAR (and anything other than FOO already mentioned) always goes to backups and never disturbs my in-box.
  2. Get more clever with a helper script that keeps track of the date/time for the last successful backups and if more than 24 hours has gone by without one inject a new mail message warning that something is awry.
  3. Or both of the above for the ultra paranoid/realist, 'cuz crap happens :-)

1 Answer 1

1

I would personally focus on #2. It doesn't have to be very complicated, but the solution probably does need to be tailored for your needs. Assuming you have a list of hosts and a folder in maildir format, you could review recent messages by something like

find $HOME/path/to/folder/backups -mtime 0 -print0 |
xargs -r0 awk '/^Subject: Bacula: Backup OK for / { a[$6] = FILENAME }
    END { split("FOO:BAR:BAZ:QUUX", t, /:/);
        for (h in t) host[t[h]]++;
        for (h in a) delete host[h];
        for (h in host) print "No backup for " host[h] }'

I like for this script to only send a report when something is missing, but then you have the new problem of making sure this job has been run recently. Perhaps you should make it print something always, and filter the "done" mails to a different folder ... and/or add a monitoring script to monitor this monitoring script. (Only half in jest. The key is abstraction -- in the end, one monitoring script to monitor all the other monitoring scripts should be all you need to actively monitor yourself.)

1
  • 1
    Hey, that's a great approach. I was thinking of calling my script from the procmailrc and having the script touch a sentinel file. However thinking about this more I realize I would still require an out-of-band script running via cron to check that sentinel file's age. If some of it has to be outside, might as well be all of it like you suggested.
    – JFlo
    Apr 8, 2015 at 23:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.