#!/usr/bin/perl  use strict;  use warnings;  use File::Find;  use Getopt::Long;  use Time::localtime;  my $backup_path = 'H:/Perl/BackupCheck/_backup';  my $report_file = 'backup.log';  my $max_file_age = 1;                 # in days  my $verbose = 0;                   # verbose output ( bool )  my $usage;  GetOptions( 'backup-path=s'   => \$backup_path,              'report-file=s'   => \$report_file,              'max-file-age=i'  => \$max_file_age,              'v|verbose'       => \$verbose,              'h|help|usage'    => \&print_usage );            my %projects = (    #   PROJEKTNAME     =>      DOMAINNAME      'Pheonix'         =>      'ZITA_PKM',      'ZITA_522'        =>      'ZITA_ATF',      'TLA'             =>      'ZITA_ATF',  );  printf( STDERR "Using backup path: %s\n", $backup_path )      if $verbose;  my @backup_dirs;  foreach my $pname ( keys %projects ) {      my $path = sprintf '%s/%s_%s_db',                         $backup_path, $projects{$pname}, $pname;      warn( "Skipped: '$path' ...: $!\n" )          && next              unless -e $path && -d $path;      push( @backup_dirs, $path );  }  my( %outdated_dirs ) = get_outdated_dirs( $max_file_age, @backup_dirs );  printf(STDERR "Outdated directories: %d\n", scalar keys %outdated_dirs )      if $verbose; # REPORTGENERATOR  open( REPORT, '>', $report_file ) or die "Can't open logfile: $!\n";  printf REPORT "Generiert um: %s\n", ctime();  print REPORT <<'EO_DIRS';  Backup-Verzeichnisse: ------------------------- EO_DIRS  print REPORT "\t$_\n" for @backup_dirs;  print REPORT <<'EO_FILES';  Veraltete Verzeichnisse/Dateien: ------------------------------------ EO_FILES  foreach my $dir ( sort keys %outdated_dirs ) {      print REPORT "\t$dir/\n";      foreach my $file ( sort @{$outdated_dirs{$dir}} ) {          print REPORT "\t\t$file\n";      }      print REPORT "\n";  }  close(REPORT); # SUBROUTINES  # get_outdated_dirs()  #     returns outdated dirs  #  # %outdated = get_outdated_dirs( $MAX_AGE, @DIRS )  #  sub get_outdated_dirs {      my( $max_age, @dirs ) = @_;      my %outdated;      find( sub {                   # weiter wenn keine Datei oder nicht alt genug                   return                       unless  -f $File::Find::name                            || -M $File::Find::name < $max_age;                   if( -M $File::Find::name >= $max_age ) {                       $outdated{$File::Find::dir} ||= [];                       push @{$outdated{$File::Find::dir}}, $_;                   }            }, @dirs );      return %outdated;  }  sub print_usage {      print <<"EOT"; usage: $0 [ OPTIONS ]    Options:             --backup-path=PATH         PATH to backup directory             --report-file=FILE         FILE where report goes to             --max-file-age=NUM         max file age ( NUM days )              -v | --verbose                  be verbose on output        -h | --help             --usage                    print this usage page EOT      exit;  }