1 #!/usr/local/bin/perl -w
4 use lib "__INSTALLDIR__/lib";
10 use Time::HiRes qw/time/;
11 use POSIX qw/strftime/;
12 use BackupPC::SearchLib;
15 my $path = abs_path($0);
16 $path =~ s#/[^/]+$#/#;
17 my $tarIncCreate = $path .= 'BackupPC_tarIncCreate';
19 die "can't find $tarIncCreate: $!\n" unless (-x $tarIncCreate);
26 my $t_fmt = '%Y-%m-%d %H:%M:%S';
29 my $bpc = BackupPC::Lib->new || die;
30 my %Conf = $bpc->Conf();
31 my $TopDir = $bpc->TopDir();
34 my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";
35 my $user = $Conf{SearchUser} || '';
37 my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });
39 my $tar_dir = $Conf{InstallDir}.'/'.$Conf{GzipTempDir};
41 die "problem with $tar_dir, check GzipTempDir in configuration\n" unless (-d $tar_dir && -w $tar_dir);
46 my $t = shift || return;
48 my ($ss,$mm,$hh) = gmtime($t);
49 $out .= "${hh}h" if ($hh);
50 $out .= sprintf("%02d:%02d", $mm,$ss);
55 return strftime($t_fmt,localtime());
60 my $sth = $dbh->prepare( qq{
63 backups.id as backup_id,
68 join shares on backups.hostid = shares.hostid
69 and shares.id = backups.shareid
70 join hosts on shares.hostid = hosts.id
71 where inc_size < 0 and not inc_deleted
78 my $sth_inc_size = $dbh->prepare(qq{ update backups set inc_size = ? where id = ? });
79 my $sth_inc_deleted = $dbh->prepare(qq{ update backups set inc_deleted = ? where id = ? });
81 %BackupPC::SearchLib::Conf = %Conf;
83 while (my $row = $sth->fetchrow_hashref) {
84 my $tar_file = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'});
85 print curr_time, " ", $row->{'host'}, ":", $row->{'share'}, " #", $row->{'num'}, " -> $tar_file";
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);
92 system($cmd) == 0 or die "failed: $?";
94 my $size = (stat( "$tar_dir/$tar_file" ))[7];
96 printf(" %1.2f MB, dur: %s", ($size / 1024 / 1024), fmt_time(time() - $t));
99 $sth_inc_size->execute($size, $row->{'backup_id'});
100 $sth_inc_deleted->execute(0, $row->{'backup_id'});
102 $sth_inc_deleted->execute(1, $row->{'backup_id'});
103 unlink "$tar_dir/$tar_file" || die "can't delete $tar_dir/$tar_file: $!\n";