line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sys::Bprsync::Cmd::Command::configcheck; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Sys::Bprsync::Cmd::Command::configcheck::VERSION = '0.25'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
BEGIN { |
6
|
1
|
|
|
1
|
|
27575
|
$Sys::Bprsync::Cmd::Command::configcheck::AUTHORITY = 'cpan:TEX'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
# ABSTRACT: verify the bprsync configuration |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
28
|
use 5.010_000; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
47
|
|
11
|
1
|
|
|
1
|
|
2474
|
use mro 'c3'; |
|
1
|
|
|
|
|
939
|
|
|
1
|
|
|
|
|
6
|
|
12
|
1
|
|
|
1
|
|
40
|
use feature ':5.10'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
92
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
372
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use namespace::autoclean; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# use IO::Handle; |
18
|
|
|
|
|
|
|
# use autodie; |
19
|
|
|
|
|
|
|
# use MooseX::Params::Validate; |
20
|
|
|
|
|
|
|
# use Carp; |
21
|
|
|
|
|
|
|
# use English qw( -no_match_vars ); |
22
|
|
|
|
|
|
|
# use Try::Tiny; |
23
|
|
|
|
|
|
|
use Sys::Bprsync; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# extends ... |
26
|
|
|
|
|
|
|
extends 'Sys::Bprsync::Cmd::Command'; |
27
|
|
|
|
|
|
|
# has ... |
28
|
|
|
|
|
|
|
has '_bp' => ( |
29
|
|
|
|
|
|
|
'is' => 'ro', |
30
|
|
|
|
|
|
|
'isa' => 'Sys::Bprsync', |
31
|
|
|
|
|
|
|
'lazy' => 1, |
32
|
|
|
|
|
|
|
'builder' => '_init_bp', |
33
|
|
|
|
|
|
|
'reader' => 'bp', |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has 'verbose' => ( |
37
|
|
|
|
|
|
|
'is' => 'ro', |
38
|
|
|
|
|
|
|
'isa' => 'Bool', |
39
|
|
|
|
|
|
|
'required' => 0, |
40
|
|
|
|
|
|
|
'traits' => [qw(Getopt)], |
41
|
|
|
|
|
|
|
'cmd_aliases' => 'v', |
42
|
|
|
|
|
|
|
'documentation' => 'Be more verbose', |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
# with ... |
45
|
|
|
|
|
|
|
# initializers ... |
46
|
|
|
|
|
|
|
sub _init_bp { |
47
|
|
|
|
|
|
|
my $self = shift; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $BP = Sys::Bprsync::->new({ |
50
|
|
|
|
|
|
|
'config' => $self->config(), |
51
|
|
|
|
|
|
|
'logger' => $self->logger(), |
52
|
|
|
|
|
|
|
'logfile' => $self->config()->get( 'Sys::Bprsync::Logfile', { Default => '/tmp/bprsync.log', } ), |
53
|
|
|
|
|
|
|
'concurrency' => 1, |
54
|
|
|
|
|
|
|
}); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
return $BP; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# your code here ... |
60
|
|
|
|
|
|
|
sub execute { |
61
|
|
|
|
|
|
|
my $self = shift; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $status = 1; |
64
|
|
|
|
|
|
|
# do we have at least one job? |
65
|
|
|
|
|
|
|
my $jobs = $self->bp()->vaults(); |
66
|
|
|
|
|
|
|
if($jobs && ref($jobs) eq 'ARRAY') { |
67
|
|
|
|
|
|
|
# check each vault if it is accessible |
68
|
|
|
|
|
|
|
foreach my $job_name (sort @{$jobs}) { |
69
|
|
|
|
|
|
|
my $job = $self->bp()->config()->get($self->bp()->config_prefix().'::Jobs::'.$job_name); |
70
|
|
|
|
|
|
|
say 'Job: '.$job_name; |
71
|
|
|
|
|
|
|
if($self->verbose()) { |
72
|
|
|
|
|
|
|
say "\t".$job->{'source'}.' => '.$job->{'destination'}; |
73
|
|
|
|
|
|
|
say "\tBwlimit: ".$job->{'bwlimit'} if $job->{'bwlimit'}; |
74
|
|
|
|
|
|
|
say "\tCompression: ".$job->{'compression'} if $job->{'compression'}; |
75
|
|
|
|
|
|
|
say "\tDelete: ".$job->{'delete'} if $job->{'delete'}; |
76
|
|
|
|
|
|
|
say "\tDescription: ".$job->{'description'} if $job->{'description'}; |
77
|
|
|
|
|
|
|
say "\tExclude: ".$job->{'exclude'} if $job->{'exclude'}; |
78
|
|
|
|
|
|
|
say "\tExcludefrom: ".$job->{'excludefrom'} if $job->{'excludefrom'}; |
79
|
|
|
|
|
|
|
say "\tHardlink: ".$job->{'hardlink'} if $job->{'hardlink'}; |
80
|
|
|
|
|
|
|
say "\tWill cross FS boundaries: ".($job->{'nocrossfs'} ? 'No' : 'Yes'); |
81
|
|
|
|
|
|
|
say "\tNumeric-IDs: ".$job->{'numericids'} if $job->{'numericids'}; |
82
|
|
|
|
|
|
|
say "\tRemote-Shell: ".$job->{'rsh'} if $job->{'rsh'}; |
83
|
|
|
|
|
|
|
say "\tRemote-Shell Options: ".$job->{'rshopts'} if $job->{'rshopts'}; |
84
|
|
|
|
|
|
|
say "\tTimeframe: ".$job->{'timeframe'} if $job->{'timeframe'}; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# check access ... |
88
|
|
|
|
|
|
|
## for local dirs: check existence and rw |
89
|
|
|
|
|
|
|
## for remotes: check ssh access |
90
|
|
|
|
|
|
|
# source |
91
|
|
|
|
|
|
|
if($job->{'source'} =~ m/:/) { |
92
|
|
|
|
|
|
|
# remote |
93
|
|
|
|
|
|
|
if(!$self->_check_remote($job->{'source'},$job->{'rshopts'})) { |
94
|
|
|
|
|
|
|
$status = 0; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} else { |
97
|
|
|
|
|
|
|
# local |
98
|
|
|
|
|
|
|
if(!$self->_check_local($job->{'source'})) { |
99
|
|
|
|
|
|
|
$status = 0; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
# destination |
103
|
|
|
|
|
|
|
if($job->{'destination'} =~ m/:/) { |
104
|
|
|
|
|
|
|
# remote |
105
|
|
|
|
|
|
|
if(!$self->_check_remote($job->{'destination'},$job->{'rshopts'})) { |
106
|
|
|
|
|
|
|
$status = 0; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} else { |
109
|
|
|
|
|
|
|
# local |
110
|
|
|
|
|
|
|
if(!$self->_check_local($job->{'destination'})) { |
111
|
|
|
|
|
|
|
$status = 0; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} else { |
116
|
|
|
|
|
|
|
my @files_read = @{$self->bp()->config()->files_read()}; |
117
|
|
|
|
|
|
|
if(@files_read) { |
118
|
|
|
|
|
|
|
say 'ERROR - No jobs defined in: '.join(q{:},@files_read); |
119
|
|
|
|
|
|
|
} else { |
120
|
|
|
|
|
|
|
say 'ERROR - No config files found in '.join(q{:},@{$self->bp()->config()->locations()}); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
$status = 0; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
return $status; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub _check_remote { |
129
|
|
|
|
|
|
|
my $self = shift; |
130
|
|
|
|
|
|
|
my $location = shift; |
131
|
|
|
|
|
|
|
my $rshopts = shift || ''; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
my ($host, $path) = split /:/, $location, 2; |
134
|
|
|
|
|
|
|
if($self->bp()->sys()->check_ssh_login($host, { SSHOpts => $rshopts, })) { |
135
|
|
|
|
|
|
|
say ' OK - SSH access to '.$host.' works'; |
136
|
|
|
|
|
|
|
if($self->bp()->sys()->run_remote_cmd($host,'ls '.$path,, { SSHOpts => $rshopts, })) { |
137
|
|
|
|
|
|
|
say ' OK - Remote location '.$path.' is a directory'; |
138
|
|
|
|
|
|
|
return 1; |
139
|
|
|
|
|
|
|
} else { |
140
|
|
|
|
|
|
|
say ' ERROR - Remote location '.$path.' not found on host '.$host; |
141
|
|
|
|
|
|
|
return; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
} else { |
144
|
|
|
|
|
|
|
say ' ERROR - SSH access to '.$host.' failed!'; |
145
|
|
|
|
|
|
|
return; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub _check_local { |
150
|
|
|
|
|
|
|
my $self = shift; |
151
|
|
|
|
|
|
|
my $location = shift; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
if(-d $location) { |
154
|
|
|
|
|
|
|
say ' OK - Location '.$location.' is a directory'; |
155
|
|
|
|
|
|
|
if(-w $location) { |
156
|
|
|
|
|
|
|
say ' OK - Location '.$location.' is writeable'; |
157
|
|
|
|
|
|
|
return 1; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} else { |
160
|
|
|
|
|
|
|
say ' ERROR - Location '.$location.' is no directory'; |
161
|
|
|
|
|
|
|
return; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub abstract { |
166
|
|
|
|
|
|
|
return 'Check integrity of the configuration'; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
no Moose; |
170
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
1; |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
__END__ |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=pod |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=encoding UTF-8 |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 NAME |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Sys::Bprsync::Cmd::Command::configcheck - verify the bprsync configuration |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 METHODS |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 abstract |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Workaround. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head2 execute |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Extensive configuration test. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 NAME |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Sys::Bprsync::Cmd::Command::configcheck - verify the bprsync configuration |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 AUTHOR |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Dominik Schulz <dominik.schulz@gauner.org> |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Dominik Schulz. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
207
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=cut |