From: Martin Pitt Date: Sun, 5 Aug 2007 19:11:12 +0000 (+0200) Subject: add backup-getfiles (part of old pibackup) X-Git-Url: https://piware.de/gitweb/?a=commitdiff_plain;h=a42ea4186273d71f71a670d99b2c29abffb8692e;p=bin.git add backup-getfiles (part of old pibackup) --- diff --git a/backup-getfiles b/backup-getfiles new file mode 100755 index 0000000..e577e28 --- /dev/null +++ b/backup-getfiles @@ -0,0 +1,64 @@ +#!/usr/bin/perl + +# (c) 2002 Martin Pitt (martin@piware.de) +# This software is protected by the terms and conditions of the GNU +# General Public License (see http://www.gnu.org/copyleft/gpl.html for +# details). + +use Getopt::Std; + +# filelist( $d ) +# generate a recursive list of files in $d; honors per-directory +# configuration files .pibackuprc +sub filelist { + my $d = shift; + $d .= '/' if ( substr( $d, -1 ) ne '/' ); + + # look for exclude file + my @excl; + if( -r $d.'.pibackuprc' ) { + open( EXCL, $d.'.pibackuprc' ) or die "Error: could not open $d.pibackuprc"; + while( ) { + chomp; + push @excl, glob $d.$_; + } + close EXCL; + } + + # open and traverse dir + local *DIR; + opendir( DIR, $d ) or print STDERR "Could not open directory $d\n" && return; + +FILE: + while( defined( $f = readdir DIR ) ) { + next if $f eq '.' || $f eq '..'; + + foreach ( @excl ) { next FILE if $d.$f eq $_; } + + if( !( -l $d.$f ) && -d _ ) { + filelist( $d.$f ); + } else { + if( !$newer || ( ( lstat _ )[9] >= $newer ) ) { + print "$d$f$term"; + } + } + } + closedir DIR; +} + +getopts( '0n:' ); + +if( $opt_n ) { + $newer = ( lstat $opt_n )[9]; # mtime +} + +$term = $opt_0 ? "\0" : "\n"; + +$dir = $ARGV[0] || '/'; +foreach (glob $dir) { + if (-d $_) { + filelist $_; + } else { + print "$_$term"; + } +}