18 |
use File::Slurp; |
use File::Slurp; |
19 |
use File::Pid; |
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); |
my $pid_path = abs_path($0); |
56 |
$pid_path =~ s/\W+/_/g; |
$pid_path =~ s/\W+/_/g; |
57 |
|
|
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(); |
378 |
hosts.name as host, |
hosts.name as host, |
379 |
shares.name as share, |
shares.name as share, |
380 |
backups.num as num, |
backups.num as num, |
381 |
|
backups.date, |
382 |
inc_size, |
inc_size, |
383 |
parts |
parts, |
384 |
|
count(backup_parts.backup_id) as backup_parts |
385 |
from backups |
from backups |
386 |
join shares on backups.hostid = shares.hostid |
join shares on backups.hostid = shares.hostid |
387 |
and shares.id = backups.shareid |
and shares.id = backups.shareid |
388 |
join hosts on shares.hostid = hosts.id |
join hosts on shares.hostid = hosts.id |
389 |
|
full outer join backup_parts on backups.id = backup_parts.backup_id |
390 |
where not inc_deleted |
where not inc_deleted |
391 |
|
group by backups.id, hosts.name, shares.name, backups.num, backups.date, inc_size, parts, backup_parts.backup_id |
392 |
order by backups.date |
order by backups.date |
393 |
|
|
394 |
} ); |
} ); |
397 |
my $num_backups = $sth->rows; |
my $num_backups = $sth->rows; |
398 |
my $curr_backup = 1; |
my $curr_backup = 1; |
399 |
|
|
400 |
|
if ($opt{h}) { |
401 |
|
warn "making increments just for host $opt{h}\n"; |
402 |
|
} |
403 |
|
|
404 |
while (my $row = $sth->fetchrow_hashref) { |
while (my $row = $sth->fetchrow_hashref) { |
405 |
|
|
406 |
|
if ($opt{h} && $row->{host} ne $opt{h}) { |
407 |
|
warn "skipped $row->{host}\n" if ($debug); |
408 |
|
next; |
409 |
|
} |
410 |
|
|
411 |
$curr_backup++; |
$curr_backup++; |
412 |
|
|
413 |
my $tar_file = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'}); |
my $tar_file = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'}); |
417 |
|
|
418 |
print "# size: $size backup.size: ", $row->{inc_size},"\n" if ($opt{d}); |
print "# size: $size backup.size: ", $row->{inc_size},"\n" if ($opt{d}); |
419 |
|
|
420 |
if ( $row->{'inc_size'} != -1 && $size != -1 && $row->{'inc_size'} >= $size) { |
if ( $row->{'inc_size'} != -1 && $size != -1 && $row->{'inc_size'} >= $size && $row->{parts} == $row->{backup_parts}) { |
421 |
if ($check) { |
if ($check) { |
422 |
tar_check($row->{'host'}, $row->{'share'}, $row->{'num'}, $tar_file) && next; |
tar_check($row->{'host'}, $row->{'share'}, $row->{'num'}, $tar_file) && next; |
423 |
} else { |
} else { |
425 |
} |
} |
426 |
} |
} |
427 |
|
|
428 |
print curr_time, " creating $curr_backup/$num_backups ", $row->{'host'}, ":", $row->{'share'}, " #", $row->{'num'}, " -> $tar_file"; |
print curr_time, " creating $curr_backup/$num_backups ", $row->{host}, ":", $row->{share}, " #", $row->{num}, |
429 |
|
" ", strftime('%Y-%m-%d', localtime($row->{date})), " -> $tar_file"; |
430 |
|
|
431 |
my $t = time(); |
my $t = time(); |
432 |
|
|