#!/usr/bin/perl use warnings; use POSIX qw(strftime); use vars qw( $now_string @backup_dirs $dir $command_tar $dest $filename); @backup_dirs = ( "/home/justin" , "/usr/src" ); foreach $dir ( @backup_dirs ) { unless ( -d $dir ) { die "The directory $dir does not exist!\n$!"; } } foreach ( @backup_dirs ) { print "$_\n"; } while (1) { print "Are you sure you want to backup these directories?\n"; print "Please select yes/no.\n"; my $input = <>; chomp($input); if ( $input eq 'n' ) { die "Program is shutting down.\n"; } if ( $input eq 'y' ) { print "Backup is beginning......\n"; last; } if ( $input eq 'yes' ) { print "Backup is beginning......\n"; last; } if ( $input eq 'no' ) { die "Program is shutting down.\n"; } } $now_string = strftime("%Y%m%d_%H%M", localtime); $filename = "bkp-".$now_string."tar.gz"; $command_tar = "tar cfvz $filename @backup_dirs"; system($command_tar); unless ( -e $filename ) { die "This file did not archive correctly.\n$!"; } print "Where do you want to back this up to?\n"; $dest = <>; chomp($dest); unless ( -d $dest ) { die "This is not a valid directory.\n$!"; } print "Backing up data to $dest now.........\n"; $command_copy = system( "mv -v $filename $dest" ); system("$command_copy"); print "Backup complete!\n";