#!/usr/bin/perl # Copyright 2000 - 2004 George Shaffer # Anyone may use or modify this code for any purpose PROVIDED # that as long as it is recognizably derived from this code, # that this copyright notice, remains intact and unchanged. # No warrantees of any kind are expressed or implied. # Copy backup and log files to CDR # Set drives and directories based on host names my $fr = "d:"; #from drive my $to = "e:"; # to drive # List the hostnames to be backed up. Each host dumps it's backup # files in a directory matching its name under a common backup # directory. my @hosts = qw(bsdhost firewall linuxone linuxtwo aixmachine); my ($yymmdd1, $yymmdd2, $mmdd1); get_dates(); # If e:\ exists, i.e. the CD-R is in the drive, be sure its # writable and if so then copy the backup and other files. open(OUT,">$to\\bkuptest.txt"); close(OUT); if (-e "$to\\bkuptest.txt") { unlink "$to\\bkuptest.txt"; print "writeable\n"; foreach $hostname (@hosts) { do_host($hostname); } } else { print "$to not writeable\n"; exit; } # For each host, create the neccessary subdirectories on f:. # The ipf subdirectory exists only for firewalls and is created only # if the host has an ipf subdirectory on d:. Change to each # d: subdirectory and copy or manipulate the files as appropriate to # the subdirectory. (Individual WPS logs are combined into a tar # then moved.) sub do_host { my $host = shift; my $fw = shift; mkdir "$to\\$host","666" if (! (-e "$to\\$host") and (-e "$fr\\backups\\$host")); mkdir "$to\\$host\\cksums","666" if (! (-e "$to\\$host\\cksums") and (-e "$fr\\backups\\$host\\cksums")); mkdir "$to\\$host\\wps","666" if (! (-e "$to\\$host\\wps") and (-e "$fr\\backups\\$host\\wps")); mkdir "$to\\$host\\ipf","666" if (-e "$fr\\backups\\$host\\ipf" and (! (-e "$to\\$host\\ipf"))); if (chdir("$fr\\backups\\$host")) { if (-e "$yymmdd2.log") { system("copy $yymmdd2.log $to\\$host") } if (-e "$yymmdd2.tar.gz") { system("copy $yymmdd2.tar.gz $to\\$host") } } if (chdir("$fr\\backups\\$host\\cksums")) { if (-e "ck$yymmdd2.log") { system("copy ck$yymmdd2.log $to\\$host\\cksums"); } if (-e "df$yymmdd1.txt") { system("copy df$yymmdd1.txt $to\\$host\\cksums") } } if (chdir("$fr\\backups\\$host\\wps")) { my $files = <$mmdd1*.log>; if ($files) { print "files = $files\n"; system("tar -cvf wp$yymmdd1.tar $mmdd1*.log"); system("tar -tvf wp$yymmdd1.tar > wp$yymmdd1.log"); system("copy wp$yymmdd1.tar $to\\$host\\wps"); system("copy wp$yymmdd1.log $to\\$host\\wps"); system("mv $mmdd1*.log hold") if (-d "hold"); } } if (chdir("$fr\\backups\\$host\\ipf")) { if (-e "ipf$yymmdd2.gz") { system("copy ipf$yymmdd2.gz $to\\$host\\ipf") } if (-e "ipf$yymmdd2.log.gz") { system("copy ipf$yymmdd2.log.gz $to\\$host\\ipf") } } } # Format three date strings, yymmdd for today and yesterday and # a mmdd for today. sub get_dates { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time()); #print "year = $year\n"; $year += 1900; $year = substr($year,2,2); $yymmdd2 = (sprintf "%02.2d", $year) . (sprintf "%02.2d", $mon+1) . (sprintf "%02.2d", $mday); if ($mday > 1) { $mday--; $yymmdd1 = (sprintf "%02.2d", $year) . (sprintf "%02.2d", $mon+1) . (sprintf "%02.2d", $mday); } else { if ($mon > 0) { my @lday = (31,28,31,30,31,30,31,31,30,31,30,31); # Put 29 days in Feb. in leap years. Wrong for 2100 ;-) $lday[1] = 29 if ($year % 4 == 0); $mon--; $mday = $lday[$mon]; $yymmdd1 = (sprintf "%02.2d", $year) . (sprintf "%02.2d", $mon+1) . (sprintf "%02.2d", $mday); } else { $year--; $mday = 31; $mon = 11; $yymmdd1 = (sprintf "%02.2d",$year) . "1231"; } } $mmdd1 = (sprintf "%02.2d", $mon+1) . (sprintf "%02.2d", $mday); }