#!/usr/bin/perl -w # simple script to backup specified mail accounts # to a zip disk. use strict; my $zip_drive = "/dev/hdc4"; my $mnt_dir = "/mnt"; my $tmp_dir = "/tmp/"; my $bkup_root = "/var/spool/mail/"; my @bkups = ( 'kirk', 'spock', 'mrmister', 'you' ); my $todays_date = join '-', (('jan','feb','mar','apr','may','jun', 'jul','aug','sep','oct','nov','dec')[(localtime)[4]]), ((localtime)[3]), ((localtime)[5]+1900); $ENV{PATH} = "/bin:/usr/bin"; print "Mounting zip drive for backup...\n"; die "Couldn't mount zip drive: $?\n" if system ("mount","-t","vfat",$zip_drive,$mnt_dir); my $old_dir = `pwd`; chomp $old_dir; chdir "$bkup_root" or die "Can't change working directory to [$bkup_root]: $!\n"; foreach my $bkup (@bkups){ my $arch = "$tmp_dir$bkup-$todays_date.tar"; if (system("tar","-cvvf",$arch,$bkup)){ warn "Could not tar file [$bkup]:$!\n"; next; }else { print "File has been tarred.\n"; if (system("gzip","-9",$arch)){ warn "Could not gzip file [$arch]:$!\n"; }else { print "File has been gziped.\n"; if (system("mv","$arch.gz","$mnt_dir/mail/")){ warn "Could not move file from temp directory", " to zip drive: $!\n"; }else{ print "File has been moved to zip drive for" " backup\n"; } } } } chdir $old_dir or die "Can't restore working directory to [$old_dir].\n"; print "Unmounting zip drive...\n"; die "Couldn't unmount zip drive: $?\n" if system ("umount",$mnt_dir); print "\nZip disk can be removed.\n";