#!/usr/local/bin/perl -w use strict; use lib "__INSTALLDIR__/lib"; use DBI; use BackupPC::Lib; use BackupPC::View; use Data::Dumper; use Time::HiRes qw/time/; use POSIX qw/strftime/; use BackupPC::SearchLib; use Cwd qw/abs_path/; my $path = abs_path($0); $path =~ s#/[^/]+$#/#; my $tarIncCreate = $path .= 'BackupPC_tarIncCreate'; die "can't find $tarIncCreate: $!\n" unless (-x $tarIncCreate); my $debug = 0; $|=1; my $start_t = time(); my $t_fmt = '%Y-%m-%d %H:%M:%S'; my $hosts; my $bpc = BackupPC::Lib->new || die; my %Conf = $bpc->Conf(); my $TopDir = $bpc->TopDir(); my $beenThere = {}; my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n"; my $user = $Conf{SearchUser} || ''; my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 }); my $tar_dir = $Conf{InstallDir}.'/'.$Conf{GzipTempDir}; die "problem with $tar_dir, check GzipTempDir in configuration\n" unless (-d $tar_dir && -w $tar_dir); #---- subs ---- sub fmt_time { my $t = shift || return; my $out = ""; my ($ss,$mm,$hh) = gmtime($t); $out .= "${hh}h" if ($hh); $out .= sprintf("%02d:%02d", $mm,$ss); return $out; } sub curr_time { return strftime($t_fmt,localtime()); } #----- main my $sth = $dbh->prepare( qq{ select backups.id as backup_id, hosts.name as host, shares.name as share, backups.num as num from backups join shares on backups.hostid = shares.hostid and shares.id = backups.shareid join hosts on shares.hostid = hosts.id where inc_size < 0 and not inc_deleted order by backups.date } ); $sth->execute(); my $sth_inc_size = $dbh->prepare(qq{ update backups set inc_size = ? where id = ? }); my $sth_inc_deleted = $dbh->prepare(qq{ update backups set inc_deleted = ? where id = ? }); %BackupPC::SearchLib::Conf = %Conf; while (my $row = $sth->fetchrow_hashref) { my $tar_file = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'}); print curr_time, sprintf(" %s:%s %-3d ", $row->{'host'}, $row->{'share'}, $row->{'num'}), " -> $tar_file "; my $t = time(); my $cmd = qq{$tarIncCreate -h "$row->{'host'}" -s "$row->{'share'}" -n $row->{'num'} | gzip -9 > $tar_dir/$tar_file}; print STDERR "## $cmd\n" if ($debug); system($cmd) == 0 or die "failed: $?"; my $size = (stat( "$tar_dir/$tar_file" ))[7]; print " dur: ",fmt_time(time() - $t)," $size bytes"; if ($size > 45) { $sth_inc_size->execute($size, $row->{'backup_id'}); $sth_inc_deleted->execute(0, $row->{'backup_id'}); } else { $sth_inc_deleted->execute(1, $row->{'backup_id'}); unlink "$tar_dir/$tar_file" || die "can't delete $tar_dir/$tar_file: $!\n"; print " EMPTY"; } print "\n"; $dbh->commit; } undef $sth; $dbh->disconnect;