![]() |
![]() |
8 Einträge, 1 Seite |
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
#!/usr/bin/perl
use strict;
use warnings;
use time::localtime;
use Data::Dumper;
my $ausgabe_Datei = "backupCheck.txt";
open(LogDatei, ">backupCheck.txt") or die "Kann Log Datei nicht anlegen : $!";
my $tm = localtime;
print LogDatei " $tm \n\n\n";
my $parameterFile = "input/Main.cfg";
open(IN, $parameterFile) || die "Paramterfile $parameterFile nicht gefunden!";
my @par = <IN>;
close(IN);
eval( join("\n", @par) );
#wird erst später aus DOMS.mdb ermittelt, vorerst wird mit Hardcodierten Werten gearbeitet
my (@pjDomain,@pjName);
$pjDomain[0] = "ZITA_PKM";
$pjName [0] = "Phoenix";
$pjDomain[1] = "ZITA_ATF";
$pjName [1] = "ZITA_522";
$pjDomain[2] = "ZITA_ATF";
$pjName [2] = "TLA";
my $numberProjects = $#pjName;
my $backupPath = 'H:\\Perl\\BackupCheck\\_backup';
for (my $i = 0; $i <= $numberProjects; $i++){
my $bkupDirectory = $backupPath . "\\" . $pjDomain[$i] . "_" . $pjName[$i] . "_db";
print LogDatei"\n \n Prüfe Existenz von " . $bkupDirectory . "\n";
if ( -e $bkupDirectory ) {
print LogDatei "Verzeichnis ist vorhanden!\n";
opendir(DIR,$bkupDirectory) or die "Kann $bkupDirectory nicht öffnen: $!\n";
my @verzeichnisse = grep{-f $bkupDirectory .'/'.$_}readdir(DIR);
my $bool = 0;
for my $file(@verzeichnisse){
$bool = 1;
if(existsActBackup($bkupDirectory.'/'.$file,1))
{
print LogDatei "\n +++++++++++Backup vorhanden++++++++++++++ \n" . $bool . " Backupdatei gefunden ";
print LogDatei $file . "\n \n" . @verzeichnisse . " Backupdateien im Verzeichnis " . $bkupDirectory . " vorhanden!";
print LogDatei "\n#############################################################\n";
}
else
{
print LogDatei "Aktuelle Datei ist nicht vorhanden!\n";
}
}
}
# Hier wird geprüft ob aktuelle Datei vorliegt oder nicht
sub existsActBackup {
my ($file,$max_age) = @_;
my $tmpValue = 0;
print LogDatei $tm;
my $age = (time - (stat($file))[10]) / (60 * 60 * 24);
if ($age < $max_age) {
$tmpValue = 1;
print LogDatei "Aktuelle Dateien vorhanden! \n";
print LogDatei "file stat($file)\n";
#print LogDatei "file2 $file \n";
} else {
$tmpValue = 0;
#print LogDatei "Keine aktuellen Dateien vorhanden! \n";
}
return $tmpValue;
}
}
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
#!/usr/bin/perl
use strict;
use warnings;
use time::localtime;
use Data::Dumper;
my $global_boolean = 1;
my $ausgabe_Datei = "backupCheck.txt";
open(LogDatei, ">backupCheck.txt") or die "Kann Log Datei nicht anlegen : $!";
my $tm = localtime;
print LogDatei " $tm \n\n\n";
my $parameterFile = "input/Main.cfg";
open(IN, $parameterFile) || die "Paramterfile $parameterFile nicht gefunden!";
my @par = <IN>;
close(IN);
eval( join("\n", @par) );
#wird erst später aus DOMS.mdb ermittelt, vorerst wird mit Hardcodierten Werten gearbeitet
my (@pjDomain,@pjName);
$pjDomain[0] = "ZITA_PKM";
$pjName [0] = "Phoenix";
$pjDomain[1] = "ZITA_ATF";
$pjName [1] = "ZITA_522";
$pjDomain[2] = "ZITA_ATF";
$pjName [2] = "TLA";
my $numberProjects = $#pjName;
my $backupPath = 'H:\\Perl\\BackupCheck\\_backup';
for (my $i = 0; $i <= $numberProjects; $i++){
my $bkupDirectory = $backupPath . "\\" . $pjDomain[$i] . "_" . $pjName[$i] . "_db";
print LogDatei"\n \n Prüfe Existenz von " . $bkupDirectory . "\n";
if ( -e $bkupDirectory ) {
print LogDatei "Verzeichnis ist vorhanden!\n";
opendir(DIR,$bkupDirectory) or die "Kann $bkupDirectory nicht öffnen: $!\n";
my @verzeichnisse = grep{-f $bkupDirectory .'/'.$_}readdir(DIR);
my $bool = 0;
for my $file(@verzeichnisse){
$bool = 1;
if(existsActBackup($bkupDirectory.'/'.$file,1))
{
print LogDatei "\n +++++++++++Backup vorhanden++++++++++++++ \n" . $bool . " Backupdatei gefunden ";
print LogDatei $file . "\n \n" . @verzeichnisse . " Backupdateien im Verzeichnis " . $bkupDirectory . " vorhanden!";
print LogDatei "\n#############################################################\n";
}
else
{
print LogDatei "Aktuelle Datei ist nicht vorhanden!\n";
$global_boolean = 0;
}
}
}
unless($global_boolean){
print "In mindestens einem Verzeichnis gab es kein aktuelles Backup\n";
}
# Hier wird geprüft ob aktuelle Datei vorliegt oder nicht
sub existsActBackup {
my ($file,$max_age) = @_;
my $tmpValue = 0;
print LogDatei $tm;
my $age = (time - (stat($file))[10]) / (60 * 60 * 24);
if ($age < $max_age) {
$tmpValue = 1;
print LogDatei "Aktuelle Dateien vorhanden! \n";
print LogDatei "file stat($file)\n";
#print LogDatei "file2 $file \n";
} else {
$tmpValue = 0;
#print LogDatei "Keine aktuellen Dateien vorhanden! \n";
}
return $tmpValue;
}
}
use time::localtime;
1
2
3
4
5
6
my $parameterFile = "input/Main.cfg";
open(IN, $parameterFile) || die "Paramterfile $parameterFile nicht gefunden!";
my @par = <IN>;
close(IN);
eval( join("\n", @par) );
1
2
3
4
5
6
7
8
9
10
my (@pjDomain,@pjName);
$pjDomain[0] = "ZITA_PKM";
$pjName [0] = "Phoenix";
$pjDomain[1] = "ZITA_ATF";
$pjName [1] = "ZITA_522";
$pjDomain[2] = "ZITA_ATF";
$pjName [2] = "TLA";
my $backupPath = 'H:\\Perl\\BackupCheck\\_backup';
1
2
3
if ( -e $bkupDirectory ) {
print LogDatei "Verzeichnis ist vorhanden!\n";
opendir(DIR,$bkupDirectory) or die "Kann $bkupDirectory nicht öffnen: $!\n";
my $age = (time - (stat($file))[10]) / (60 * 60 * 24);
my $age = -M $file; # file age in days
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;
}
use time::localtime;
![]() |
![]() |
8 Einträge, 1 Seite |