#!/usr/bin/perl $CONF_FILE="backup.conf"; $MOUNT_BACKUP_HD=""; # PLEASE set this HD up in your fstab if you use it if($MOUNT_BACKUP_HD) { system("mount $MOUNT_BACKUP_HD"); } open(CONF, "< $CONF_FILE") || die "no config file found!\n"; $i=0; while() { # Parse out comments. if(substr($_, 0,1) eq '#') { next; } my @tmp = split(/\#/,$_); $_ = $tmp[0]; chomp; # Alright, ready to split. @line = split / /; $tarfile = shift @line; $array_tar[$i] = $tarfile; $i++; $dir = shift @line; $lref = \@line; backup($tarfile,$dir,$lref); } $tref = \@array_tar; gzip($tref); if($MOUNT_BACKUP_HD) { system("umount $MOUNT_BACKUP_HD"); } sub backup { $tarfile = $_[0]; $dir = $_[1]; $exc = $_[2]; print "****: ",$tarfile, " ", $dir; foreach $file (@$exc) { print " ",$file; } print "\n"; $checkfile = $dir . '.tar'; if(-e $tarfile && -e $tarfile) { open(LIST, "ls -1 $dir|"); while(){ chomp; split / /; $_ = $_[0]; $skip = 0; foreach $file (@$exc) { if($_ eq $file) { $skip = 'yes'; } } if(!$skip) { $tarit = "tar -rf $tarfile " . $dir . $_; print $tarit . "\n"; system($tarit); } } } elsif(-e $checkfile){ $tarthis = "tar -cf $tarfile $checkfile"; print $tarthis,"\n"; system $tarthis; backup($tarfile, $dir, $exc); } } sub gzip { $dir = $_[0]; $i=0; foreach $tar (@$dir) { $skip=0; foreach $check (@blah) { if( $tar eq $check ) { $skip = 1;} } if(!$skip) { $blah[$i] = $tar; $i++;} } foreach $tarfile (@blah) { $gzipit = 'gzip -f ' . $tarfile . '.gz ' . $tarfile; print $gzipit,"\n"; system($gzipit); } } #End backup.pl Example conf file. ############################################# # Config file example: backup.conf # # /tar/file.tar /directory/path/ excluded_file excluded_directory # # You can have as many files/dir excluded as you wish.. /tmp/web.tar /www/htdocs/ spark realms noc doc /tmp/web.tar /www/htdocs/spark/ noc /tmp/web.tar /www/htdocs/realms/ /tmp/trilex.tar /home/trilex/code/ /tmp/talker.tar /home/trilex/public_html/