I've got a script that runs on several servers, FTPing tarballs to one central one. The central server then tars up all the stuff in the FTP dropbox and puts it on tape.

Thing is, tar and mt don't report errors as they ought. I tried letting the script run without a tape in the drive, and the script ran fine. The logs reported success and return codes of 0 all around. So what I want to know is, is there a better way to do what I am trying to that will yield proper error processing? Ideally, I'd like as perlish a solution as possible, but I haven't found anything useful on CPAN. The Mt module is just a wrapper around the mt command, and if mt doesn't return errors...

By the way: I use a bleeding-edge, not-yet-updated-on-CPAN version of Parse::PlainConfig, but there's nothing in there to do with anything. If you want to take a look anyway, here's a copy of what I use. The (trimmed) script in question follows:

#!/usr/bin/perl use warnings; use strict; # OMIT: initialize some useful variables... # Here everything gets called. These subroutines are defined below. _log _begin; $settings = read_config("/etc/backup.conf"); create_archive($settings->{archive}); upload_archive($settings->{FTP}); tape_archive($settings->{tape}); delete_temp_files(); _log _end; # # send the files to tape. We use the rewinding device, because we # don't really care about putting several archives on the same tape. # We also eject the tape because we want a different tape for each # day of the week. sub tape_archive { my $conf = shift or return; # are we configured to tape stuff? my ($rdev, @tapeables) = ($conf->{'rdev'}, @{$conf->{'tapeables'}}); push @tapeables, $tarball if ($settings->{'archive'}); # With the tape out, the following ought to _barf. But it doesn't. undef $!; system("tar --ignore-failed-read -cf $rdev @tapeables") and _barf "couldn't write to tape. Error $? : $! "; # Even if the previous line doesn't _barf, surely this one must, # right? Wrong. undef $!; system("mt -f $rdev offline") and _barf "couldn't eject tape. Error $? : $! "; push @deleteables, @tapeables; } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Below this point are housekeeping and logging subs, so # # feel free to skip to the bottom # # logging subs sub _begin { chomp (my $now = `date`); return "-----\nstarting backup on $hostname at $now \n"; } sub _log { # OMIT: log stuff to file and return what was logged } sub _barf { my $msg = _log shift() .$/. _end(); _mail( $settings->{mail}, $msg); die $msg; } sub _mail { my $conf = shift or return; # are we configured to mail stuff? use Net::SMTP; # OMIT: mail errors to the admin } sub _end { chomp (my $now = `date`); return "ended at $now \n-----\n"; } # Read in the config file using Parse::PlainConfig sub read_config { use Parse::PlainConfig; # OMIT: read settings from file and return a hashref } sub is_true($) { # used by read_config return defined $_[0] && $_[0] !~ /^(false|no|0)$/; } sub create_archive { # The first step is to create a temporary archive + in /tmp/. # OMIT: we're writing to file. No problem here. } sub dump_into_file { # OMIT: turn the list of sources into an array we can send to tar } sub upload_archive { # OMIT: irrelevant } sub delete_temp_files { # clean up our temp directory. # OMIT: housekeeping code } __END__

LAI

__END__

In reply to Backup script: how can I force this to report errors? by LAI

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.