zzspectrez has asked for the wisdom of the Perl Monks concerning the following question:
Hello, fellow perl monks. I have a question for the wise ones! I have a small mail server I use to supply email for familly, friends and myself. Nothing serious, so I have never really had any true backups. The server I can setup quickly since it is bare bones setup just to do mail and act as a firewall. Only thing important on it is the email messages and some webpages.
I want to write a perl script to automate the process. I have written a preliminary script to backup selected mail accounts to a zip drive.
Questions I have:
#!/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";
Thanks for any suggestions!!
zzspectrez
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using perl to automate mail backup
by AgentM (Curate) on Nov 12, 2000 at 09:40 UTC | |
by zzspectrez (Hermit) on Nov 13, 2000 at 01:36 UTC | |
by AgentM (Curate) on Nov 13, 2000 at 01:40 UTC | |
|
Re: Using perl to automate mail backup
by Fastolfe (Vicar) on Nov 12, 2000 at 09:48 UTC | |
by zzspectrez (Hermit) on Nov 12, 2000 at 12:29 UTC | |
by Fastolfe (Vicar) on Nov 12, 2000 at 13:23 UTC | |
by zzspectrez (Hermit) on Nov 12, 2000 at 23:34 UTC | |
by Fastolfe (Vicar) on Nov 13, 2000 at 08:55 UTC |