Jump to content

Looking for a good way to use Perl (or any other language I guess) to recursively archive some fi...


G+_Dan Sarauer (N3m1sys)
 Share

Recommended Posts

Looking for a good way to use Perl (or any other language I guess) to recursively archive some files/folders based on date modified while keeping the folder structure in-tact.  I've looked at File::Copy::Recursive in CPAN and it looks promising, but I haven't wrapped my head around getting it to check the files date modified before just copying the whole lot. Ideas code monkeys?

Link to comment
Share on other sites

Two ways to tackle this problem come to my mind:

 

1. Just use rsync.

 

2. Use File::Find. Here's a snippet of what that might look like:

 

#!/usr/bin/perl

 

use warnings;

use File::Find;

 

my @dirs_to_search= qw{/usr/local/bin /usr/share /etc /var/www};

 

use constant TIME_THRESHHOLD => 7;

 

find(\&wanted,@dirs_to_search);

 

sub wanted {

(($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($)) && int(-M _) > TIME_THRESHHOLD && archive_this($);

}

 

sub archive_this {

# Archiving logic goes here

}

Link to comment
Share on other sites

  • 3 weeks later...
 Share

×
×
  • Create New...