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,
69 join shares on backups.hostid = shares.hostid
70 and shares.id = backups.shareid
71 join hosts on shares.hostid = hosts.id
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'});
87 # this will return -1 if file doesn't exist
88 my $size = BackupPC::SearchLib::get_tgz_size_by_name($tar_file);
90 print curr_time, " ", $row->{'host'}, ":", $row->{'share'}, " #", $row->{'num'}, " -> $tar_file";
95 if ($row->{'inc_size'} == -1 || $size == -1 || $row->{'inc_size'} != $size) {
96 my $cmd = qq{$tarIncCreate -h "$row->{'host'}" -s "$row->{'share'}" -n $row->{'num'} | gzip -9 > $tar_dir/$tar_file};
97 print STDERR "## $cmd\n" if ($debug);
99 system($cmd) == 0 or die "failed: $?";
101 $size = (stat( "$tar_dir/$tar_file" ))[7];
106 my $max_size = $Conf{'MaxArchiveSize'} || die "problem with MaxArchieSize parametar";
108 if ($size > $max_size && ! -d "$tar_dir/$tar_file") {
110 my $in = my $out = "$tar_dir/$tar_file";
112 rename $in, $out || die "can't rename $in: $!";
113 mkdir $in || die "can't mkdir $in: $!";
114 system("split -d -b $max_size $out $in/part") == 0 or die "can't split $out: $!";
115 unlink $out || die "can't unlink $out: $!";
118 $sth_inc_size->execute($size, $row->{'backup_id'});
119 $sth_inc_deleted->execute(0, $row->{'backup_id'});
121 printf(" %1.2f MB", ($size / 1024 / 1024));
124 $sth_inc_deleted->execute(1, $row->{'backup_id'});
125 unlink "$tar_dir/$tar_file" || die "can't delete $tar_dir/$tar_file: $!\n";
128 print ", dur: ",fmt_time(time() - $t), "\n";