1 #!/usr/local/bin/perl -w
4 use lib "__INSTALLDIR__/lib";
10 use Time::HiRes qw/time/;
12 use POSIX qw/strftime/;
13 use BackupPC::SearchLib;
16 my $path = abs_path($0);
17 $path =~ s#/[^/]+$#/#;
18 my $tarIncCreate = $path .= 'BackupPC_tarIncCreate';
20 die "can't find $tarIncCreate: $!\n" unless (-x $tarIncCreate);
27 my $t_fmt = '%Y-%m-%d %H:%M:%S';
30 my $bpc = BackupPC::Lib->new || die;
31 my %Conf = $bpc->Conf();
32 my $TopDir = $bpc->TopDir();
35 my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";
36 my $user = $Conf{SearchUser} || '';
38 my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });
40 my $tar_dir = $Conf{InstallDir}.'/'.$Conf{GzipTempDir};
42 die "problem with $tar_dir, check GzipTempDir in configuration\n" unless (-d $tar_dir && -w $tar_dir);
47 my $t = shift || return;
49 my ($ss,$mm,$hh) = gmtime($t);
50 $out .= "${hh}h" if ($hh);
51 $out .= sprintf("%02d:%02d", $mm,$ss);
56 return strftime($t_fmt,localtime());
61 my $sth = $dbh->prepare( qq{
64 backups.id as backup_id,
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
79 my $sth_inc_size = $dbh->prepare(qq{ update backups set inc_size = ? where id = ? });
80 my $sth_inc_deleted = $dbh->prepare(qq{ update backups set inc_deleted = ? where id = ? });
82 %BackupPC::SearchLib::Conf = %Conf;
84 while (my $row = $sth->fetchrow_hashref) {
85 my $tar_file = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'});
86 print curr_time, sprintf(" %s:%s %-3d ", $row->{'host'}, $row->{'share'}, $row->{'num'}), " -> $tar_file ";
90 my $cmd = qq{$tarIncCreate -h "$row->{'host'}" -s "$row->{'share'}" -n $row->{'num'} | gzip -9 > $tar_dir/$tar_file};
91 print STDERR "## $cmd\n" if ($debug);
93 system($cmd) == 0 or die "failed: $?";
95 my $size = (stat( "$tar_dir/$tar_file" ))[7];
97 print " dur: ",fmt_time(time() - $t)," $size bytes";
100 $sth_inc_size->execute($size, $row->{'backup_id'});
101 $sth_inc_deleted->execute(0, $row->{'backup_id'});
103 $sth_inc_deleted->execute(1, $row->{'backup_id'});
104 unlink "$tar_dir/$tar_file" || die "can't delete $tar_dir/$tar_file: $!\n";