in reply to Using perl to automate mail backup

a quick root crontab is the best solution for making backups. I'm used to tarred files on tape drives- on random access units such as the zip drive, you need to either adopt a naming convention or simply cat to the tar (which is insanely easy with tar) to end up with one file which is most efficient. For a timed daemon, this program is unusually verbose. That's not necessary but for debugging. You might also want to confirm at least the Zip diskette's title before you add files to it, since at 12:00am, you might be writing your english essay when the backup kicks in and deletes it! Because of how tar magic works, you will be able to extract certain sections with no problem, especially if you switch from system() to Archive::Tar which will simplify the interface. The module actually has add_files() and add_data() functions! Also, mounting and unmounting your diskette is not necessary if the drive is all that the backup is used for.

I also noticed that you are not checking for many errors. While you are checking for errors, you will never be notified of such errors if this is a daemon job. if the backup is unsuccessful, I would hope that it would at least mail you or add a syslog(). Also, you will never know when the drive is full. If it is full, it should notify you immediately so that it can continue with the backup.

You should quickly check to see if the diskette is the correct one for backup. Perhaps a small file with the title "Email Backup Disk 1" would do the trick.

In short, daemons should definitely be equipped with an emergency mechanism for failure, such as syslog or wall for more important things.

flock: flock does not implement mandatory locking. If your mail spooler doesn't use flock, then you can't either. If your system supports mandatory file locking, then by all means use it- unless it screws with the spooler....but you're just reading files, whether incomplete or not. A ten second suspension of sendmail is probably out of the question :-) the next backup would catch the next round of data....It's apparent to me that this is not incredibly important so your workarounds would be OK...

AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.

Replies are listed 'Best First'.
RE: Re: Using perl to automate mail backup
by zzspectrez (Hermit) on Nov 13, 2000 at 01:36 UTC

    Im not sure I gather what you mean a naming convention or simply cat to the tar. The tar files are created using a naming convention username-month-date-year.tar. I know it would be better to just tar /usr/spool/mail but I have a few mailboxes that are quite large (IMAP SERVER) and dont want to backup as frequently. Im going to modify the script to backup a few additional things (a few user directories, etc) so will probably have it tar something like:(PSEUDOCODE)

    cd /var/spool/;tar -cvf /tmp/mail-bkup.tar $name1 $name2 .. cd /home; tar -cvf /tmp/user-bkup.tar $user1 $user2 .. cd /tmp; tar -cvf backup-$todays_date.tar mail-bkup.tar user-bkup.tar

    Good point about checking the zip disk, I didnt think about that. The backup has been done, Just dont know on which disk!

    Im not using modules such Archive::Tar because I am trying to better understand using perl as a glue language. I come from windows background and need the experience playing with the unix tools.

    Currently the err checking is laughable, I know. This is just a test script that Im using from the command line and want to see whats going on. I think Ill take your sugestion and have it mail me any errors. How could I grab errors reported by tar and gzip? Can I grab standerr somehow?


    Thanks!
    zzspectrez

      If you open tar and gzip with IPC::Open3 or IPC::Run, then you'll be able to capture and use ALL 3 STD* pipes. I might reconsider using the Perl modules, though. While you might be able to mail yourself the STDERR from the failed tar, it might not always be obvious what happened. With the perl modules, this is less so. You should at least pick up on $? and turn on verbose mode on the tar and gzip.
      AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.