16 |
use Algorithm::Diff; |
use Algorithm::Diff; |
17 |
use Getopt::Std; |
use Getopt::Std; |
18 |
use File::Slurp; |
use File::Slurp; |
19 |
|
use File::Pid; |
20 |
|
|
21 |
|
=head1 NAME |
22 |
|
|
23 |
|
BackupPC_incPartsUpdate |
24 |
|
|
25 |
|
=head1 DESCRIPTION |
26 |
|
|
27 |
|
Create C<.tar.gz> increments on disk calling C<BackupPC_tarIncCreate>. |
28 |
|
|
29 |
|
Following options are supported (but all are optional): |
30 |
|
|
31 |
|
=over 4 |
32 |
|
|
33 |
|
=item -h hostname |
34 |
|
|
35 |
|
Update parts for just single C<hostname> |
36 |
|
|
37 |
|
=item -c |
38 |
|
|
39 |
|
Force check for tar archives which exist on disk |
40 |
|
|
41 |
|
=item -d |
42 |
|
|
43 |
|
Turn debugging output |
44 |
|
|
45 |
|
=back |
46 |
|
|
47 |
|
=cut |
48 |
|
|
49 |
|
my %opt; |
50 |
|
getopts("cdh:", \%opt ); |
51 |
|
|
52 |
|
my $debug = $opt{d}; |
53 |
|
my $check = $opt{c} && print STDERR "NOTICE: tar archive check forced\n"; |
54 |
|
|
55 |
|
my $pid_path = abs_path($0); |
56 |
|
$pid_path =~ s/\W+/_/g; |
57 |
|
|
58 |
|
my $pidfile = new File::Pid({ |
59 |
|
file => "/tmp/$pid_path", |
60 |
|
}); |
61 |
|
|
62 |
|
if (my $pid = $pidfile->running ) { |
63 |
|
die "$0 already running: $pid\n"; |
64 |
|
} elsif ($pidfile->pid ne $$) { |
65 |
|
$pidfile->remove; |
66 |
|
$pidfile = new File::Pid; |
67 |
|
} |
68 |
|
|
69 |
|
print STDERR "$0 using pid ",$pidfile->pid," file ",$pidfile->file,"\n"; |
70 |
|
$pidfile->write; |
71 |
|
|
72 |
my $bpc = BackupPC::Lib->new || die "can't create BackupPC::Lib"; |
my $bpc = BackupPC::Lib->new || die "can't create BackupPC::Lib"; |
73 |
my %Conf = $bpc->Conf(); |
my %Conf = $bpc->Conf(); |
86 |
$bin->{$c} = which($c) || die "$0 needs $c, install it\n"; |
$bin->{$c} = which($c) || die "$0 needs $c, install it\n"; |
87 |
} |
} |
88 |
|
|
|
my %opt; |
|
|
getopts("cd", \%opt ); |
|
|
|
|
|
my $debug = $opt{d}; |
|
|
my $check = $opt{c} && print STDERR "NOTICE: tar archive check forced\n"; |
|
|
|
|
89 |
$|=1; |
$|=1; |
90 |
|
|
91 |
my $start_t = time(); |
my $start_t = time(); |
393 |
my $num_backups = $sth->rows; |
my $num_backups = $sth->rows; |
394 |
my $curr_backup = 1; |
my $curr_backup = 1; |
395 |
|
|
396 |
|
if ($opt{h}) { |
397 |
|
warn "making increments just for host $opt{h}\n"; |
398 |
|
} |
399 |
|
|
400 |
while (my $row = $sth->fetchrow_hashref) { |
while (my $row = $sth->fetchrow_hashref) { |
401 |
|
|
402 |
|
if ($opt{h} && $row->{host} ne $opt{h}) { |
403 |
|
warn "skipped $row->{host}\n" if ($debug); |
404 |
|
next; |
405 |
|
} |
406 |
|
|
407 |
$curr_backup++; |
$curr_backup++; |
408 |
|
|
409 |
my $tar_file = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'}); |
my $tar_file = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'}); |