1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/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;
}
,,Das perlt aber heute wieder...'' -- Dittsche