in reply to Is this the most elegant way to code directory lookup?
#!/usr/bin/perl use warnings; use strict; use File::Copy; # change source backup dir, modification time, and destination backup +dir here my $srcdir = '/var/local/somedir'; my $mtime = '1'; my $destdir = '/backup/somedir'; die "Error:$!" unless (-d $srcdir && -d $destdir ); print "Beginning backup...\n"; chdir $srcdir; opendir(INDIR,$srcdir) || die "Can't open directory: $!"; while ($_ = readdir(INDIR)) { next if (-d || $_ eq "." || $_ eq ".."); if (-M > $mtime) { print "$_ : Older than one day.\n"; } else { system("tar -cz $_ -f $_.tar.gz"); move(<*.gz>, $destdir) && print "$_ archived in $destd +ir\n"; } } closedir(INDIR); print "Backup complete.\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is this the most elegant way to code directory lookup?
by davorg (Chancellor) on Sep 29, 2006 at 15:20 UTC | |
by hv (Prior) on Oct 02, 2006 at 10:18 UTC |