cute, quick hack I did to backup some directories on my server. There's probly a nicer way to do this, but this one works :)
#!/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(<CONF>) { # 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(<LIST>){ 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/

In reply to backup.pl by reyjrar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.