1 |
#!/usr/local/bin/perl -w |
2 |
|
3 |
use strict; |
4 |
use lib "__INSTALLDIR__/lib"; |
5 |
|
6 |
use DBI; |
7 |
use BackupPC::Lib; |
8 |
use BackupPC::View; |
9 |
use Data::Dumper; |
10 |
use Time::HiRes qw/time/; |
11 |
use File::Pid; |
12 |
use POSIX qw/strftime/; |
13 |
use BackupPC::SearchLib; |
14 |
use Cwd qw/abs_path/; |
15 |
|
16 |
my $path = abs_path($0); |
17 |
$path =~ s#/[^/]+$#/#; |
18 |
my $tarIncCreate = $path .= 'BackupPC_tarIncCreate'; |
19 |
|
20 |
die "can't find $tarIncCreate: $!\n" unless (-x $tarIncCreate); |
21 |
|
22 |
my $debug = 0; |
23 |
$|=1; |
24 |
|
25 |
my $start_t = time(); |
26 |
|
27 |
my $t_fmt = '%Y-%m-%d %H:%M:%S'; |
28 |
|
29 |
my $hosts; |
30 |
my $bpc = BackupPC::Lib->new || die; |
31 |
my %Conf = $bpc->Conf(); |
32 |
my $TopDir = $bpc->TopDir(); |
33 |
my $beenThere = {}; |
34 |
|
35 |
my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n"; |
36 |
my $user = $Conf{SearchUser} || ''; |
37 |
|
38 |
my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 }); |
39 |
|
40 |
my $tar_dir = $Conf{InstallDir}.'/'.$Conf{GzipTempDir}; |
41 |
|
42 |
die "problem with $tar_dir, check GzipTempDir in configuration\n" unless (-d $tar_dir && -w $tar_dir); |
43 |
|
44 |
#---- subs ---- |
45 |
|
46 |
sub fmt_time { |
47 |
my $t = shift || return; |
48 |
my $out = ""; |
49 |
my ($ss,$mm,$hh) = gmtime($t); |
50 |
$out .= "${hh}h" if ($hh); |
51 |
$out .= sprintf("%02d:%02d", $mm,$ss); |
52 |
return $out; |
53 |
} |
54 |
|
55 |
sub curr_time { |
56 |
return strftime($t_fmt,localtime()); |
57 |
} |
58 |
|
59 |
#----- main |
60 |
|
61 |
my $sth = $dbh->prepare( qq{ |
62 |
|
63 |
select |
64 |
backups.id as backup_id, |
65 |
hosts.name as host, |
66 |
shares.name as share, |
67 |
backups.num as num |
68 |
from backups |
69 |
join shares on backups.hostid = shares.hostid |
70 |
and shares.id = backups.shareid |
71 |
join hosts on shares.hostid = hosts.id |
72 |
where inc_size < 0 and not inc_deleted |
73 |
order by backups.date |
74 |
|
75 |
} ); |
76 |
|
77 |
$sth->execute(); |
78 |
|
79 |
my $sth_inc_size = $dbh->prepare(qq{ update backups set inc_size = ? where id = ? }); |
80 |
|
81 |
%BackupPC::SearchLib::Conf = %Conf; |
82 |
|
83 |
while (my $row = $sth->fetchrow_hashref) { |
84 |
my $tar_file = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'}); |
85 |
print curr_time, sprintf(" %s:%s %-3d ", $row->{'host'}, $row->{'share'}, $row->{'num'}), " -> $tar_file "; |
86 |
|
87 |
my $t = time(); |
88 |
|
89 |
my $cmd = qq{$tarIncCreate -h "$row->{'host'}" -s "$row->{'share'}" -n $row->{'num'} | gzip -9 > $tar_dir/$tar_file}; |
90 |
print STDERR "## $cmd\n" if ($debug); |
91 |
|
92 |
system($cmd) == 0 or die "failed: $?"; |
93 |
|
94 |
my $size = (stat( "$tar_dir/$tar_file" ))[7]; |
95 |
|
96 |
print " dur: ",fmt_time(time() - $t)," $size bytes\n"; |
97 |
|
98 |
$sth_inc_size->execute($size, $row->{'backup_id'}); |
99 |
|
100 |
$dbh->commit; |
101 |
|
102 |
} |
103 |
|
104 |
undef $sth; |
105 |
$dbh->disconnect; |