#!/usr/bin/perl # # Written by Scott Noble -- May 22, 2003 # # Level-0 (complete) backup of : # head (/ /opt /home) and store (/ /var /home2) # # This script only FINDS the files that need to be backed up. # #################################################################### @machines = qw( head store ); $dirname{head} = '/home'; $dirname{store} = '/home2'; $backdir{head} = '/home/backups'; $backdir{store} = '/home2/backups'; $tarscript = '/home/backups/scripts/Start_tar'; $tape = 'head:/dev/tape'; $tar_stderrfile_pref{head} = '/home/backups/tar_stderr.out'; $tar_stderrfile_pref{store} = '/home2/backups/tar_stderr.out'; $tar_stdoutfile_pref{head} = '/home/backups/tar_stdout.out'; $tar_stdoutfile_pref{store} = '/home2/backups/tar_stdout.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 = 'scn@physics.ubc.ca'; ##################################################################### # Master regular expression of 'find' : ##################################################################### $findlist = '! \( \( -user inaki -and \( -name "*std_out*" -o -name "l=*_data" -o -name "l=*_mass" -o -name "l=*_r0" -o -name "gg" -o -name "hh" \) \) -o -name "*.sdf" -o -name "*.sdf.gz" -o -name "*.hdf" -o -name "*.dat" -o -name "*.DAT" -o -name "*.dat.gz" -o -name "*.segdat" -o -name "*.rgb" -o -name "*.o" -o -name core -o -type d \) -mount | grep -v .netscape/cache | grep -v home/daub |grep -v /backups/ |grep -v /home/vnfe2-tmp'; ##################################################################### # Do backup for primary /home partitions: ##################################################################### foreach $mach ( @machines ) { #### Make and tar title of backup to tape: # $tar_stderrfile = join '', "$tar_stderrfile_pref{$mach}", '.', "$mach", '-level-0'; # $tar_stdoutfile = join '', "$tar_stdoutfile_pref{$mach}", '.', "$mach", '-level-0'; # $tfile = join '', '/backups/machines/',"$month",'-',"$mday",'-',"$mach",'-level-0'; # @touchargs = ('touch', $tfile ); # system( @touchargs ); # # $itries = 0; # while( (system("tar cvf $tape $tfile") != 0) && ($itries<$max_tries) ) # { # $itries++; # sleep 1; # } # if( $itries >= $max_tries ) # { # $message = "Script $0 failed 1st tar loop for machine $mach on `hostname`!!"; # system( "echo $message | /bin/mail $email"); # } #### Find all files to be backed up: $backuplist = join '', "$backdir{$mach}", '/', "$mach-level-0-index"; $findcmd = join '', 'find ', "$dirname{$mach}", " $findlist > $backuplist"; $findcmd = join '', "rsh $mach ", "'", "$findcmd", "'"; system($findcmd); #### Tar files to tape: # ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, # $atime,$mtime,$ctime,$blksize,$blocks) = stat $backuplist; # # $itries = 0; # $fail = 1; # $tarcmd = join '', "rsh $mach ", "'", "$tarscript ", "$backuplist ", "$tar_stderrfile ", "$tar_stdoutfile ", "'"; # while( ($fail != 0) && ($itries<$max_tries) ) # { # $tar_errnum = system($tarcmd); # # 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_stderrfile for machine $mach"; # open(TARFID, "<$tar_stderrfile") 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 machine $mach on `hostname`!!"; # system( "echo $message | /bin/mail $email"); # } # # system("rm -f $tfile"); }