#!/usr/bin/perl # # Written by Scott Noble -- Nov. 12, 2002 # # level-0 (complete) backup of : # bh[0,4-6]:/home, bh0:/d/wh0/c # #################################################################### @machines = qw( bh0 bh2 bh3 bh4 bh5 bh6 bh7 bh8 bh9 bh10 bh11 bh12 bh13 bh14 bh15 lnx1 lnx2 lnx3); # bh1 and bh16 omitted since they are not on the network anymore # this will be fixed in the future and thus so must the script $tape = '/d/vnfe4/home/backups/level0/'; $tar_outfile_pref = '/backups/taroutput.out'; $max_tries = 100; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $month = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$mon]; $email = 'ajpenner@physics.ubc.ca'; ##################################################################### # Do backup for primary /home partitions: ##################################################################### foreach $mach ( @machines ) { #### Make and tar title of backup to tape: $tar_outfile = join '', "$tar_outfile_pref", '.', "$mach"; $tfile = join '', $tape,"$month",'-',"$mday",'-',"$mach",'-level-0'; @touchargs = ('touch', $tfile ); system( @touchargs ); $backuplist = "/d/$mach/home/$mach.physics.ubc.ca-find-files"; #### Tar files to tape: ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat $backuplist; $itries = 0; $fail = 1; $tar_file=join('',$tfile,".tar"); while( ($fail != 0) && ($itries<$max_tries) ) { $tar_errnum = system("tar cvf $tar_file --totals -T $backuplist 2> $tar_outfile"); if( $tar_errnum == 0 ) { $fail = 0; } if( $tar_errnum != 0 ) { ###### By default, assume a failure: $fail = 1; ###### Do not keep trying if there are no files to archive: if( $size == 0 ) { $fail = 0; } ###### Check to see if the 'tar' actually wrote to the tape: if( $size != 0 ) { $message_tarout = "Could not open file $tar_outfile for partition 1 of machine $mach"; open(TARFID, "<$tar_outfile") or system( "echo $message_tarout | /bin/mail $email"); while( $line = ) { ($str1, $bytes) = split( ': ', $line); if( $str1 eq 'Total bytes written' ) { if( $bytes != 0 ) { $fail = 0; print "bytes = $bytes \n"; } } } close(TARFID); } } $itries++; sleep 1; } if( $itries >= $max_tries ) { $message = "Script $0 failed 2nd tar loop for 1st partition machine $mach on `hostname`!!"; system( "echo $message | /bin/mail $email"); } }