/[BackupPC]/trunk/bin/BackupPC_incPartsUpdate
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/bin/BackupPC_incPartsUpdate

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 214 by dpavlin, Sun Oct 16 12:33:05 2005 UTC revision 230 by dpavlin, Tue Oct 25 09:30:52 2005 UTC
# Line 10  use BackupPC::Attrib qw/:all/; Line 10  use BackupPC::Attrib qw/:all/;
10  use Data::Dumper;  use Data::Dumper;
11  use Time::HiRes qw/time/;  use Time::HiRes qw/time/;
12  use POSIX qw/strftime/;  use POSIX qw/strftime/;
 use BackupPC::SearchLib;  
13  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
14  use File::Which;  use File::Which;
15  use Archive::Tar;  use Archive::Tar::Streamed;
16  use Algorithm::Diff;  use Algorithm::Diff;
17  use Getopt::Std;  use Getopt::Std;
18    
19    my $bpc = BackupPC::Lib->new || die "can't create BackupPC::Lib";
20    my %Conf = $bpc->Conf();
21    
22    use BackupPC::SearchLib;
23    %BackupPC::SearchLib::Conf = %Conf;
24    
25    # cludge: minimum .tar.gz size
26    my $MIN_TAR_SIZE = 80;
27    
28  my $path = abs_path($0);  my $path = abs_path($0);
29  $path =~ s#/[^/]+$#/#;  $path =~ s#/[^/]+$#/#;
30  my $tarIncCreate = $path .= 'BackupPC_tarIncCreate';  my $tarIncCreate = $path .= 'BackupPC_tarIncCreate';
# Line 40  my $start_t = time(); Line 48  my $start_t = time();
48    
49  my $t_fmt = '%Y-%m-%d %H:%M:%S';  my $t_fmt = '%Y-%m-%d %H:%M:%S';
50    
 my $hosts;  
 my $bpc = BackupPC::Lib->new || die;  
 my %Conf = $bpc->Conf();  
 my $TopDir = $bpc->TopDir();  
 my $beenThere = {};  
   
51  my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";  my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";
52  my $user = $Conf{SearchUser} || '';  my $user = $Conf{SearchUser} || '';
53    
# Line 95  sub tar_check($$$$) { Line 97  sub tar_check($$$$) {
97                  tar_join($filename);                  tar_join($filename);
98          }          }
99    
         my $tar = Archive::Tar->new;  
         my $comp = 0;  
         $comp = 1 if ($filename =~ m/\.(gz|tgz)$/);  
100          print STDERR ", opening" if ($debug);          print STDERR ", opening" if ($debug);
101          $tar->read($filename, $comp) or die "can't open $filename: $!";          open(my $fh, "gzip -cd $filename |") or die "can't open $filename: $!";
102            binmode($fh);
103            my $tar = Archive::Tar::Streamed->new($fh);
104    
105          print STDERR ", tar" if ($debug);          print STDERR ", tar" if ($debug);
106          my @tar_files = sort $tar->list_files();          my @tar_files;
107            while(my $entry = $tar->next) {
108                    push @tar_files, $entry->name;
109            }
110            @tar_files = sort @tar_files;
111          print STDERR " ",($#tar_files + 1), " files" if ($debug);          print STDERR " ",($#tar_files + 1), " files" if ($debug);
112    
113          print STDERR ", database" if ($debug);          print STDERR ", database" if ($debug);
# Line 142  sub tar_check($$$$) { Line 147  sub tar_check($$$$) {
147                  }                  }
148          }          }
149    
150          print STDERR " ",($same ? 'ok' : 'DIFFERENT');          print " ",($same ? 'ok' : 'DIFFERENT');
151          print STDERR " }} " if ($debug);          print STDERR " }} " if ($debug);
152    
153          return $same;          return $same;
# Line 172  order by backups.date Line 177  order by backups.date
177  my $sth_inc_size = $dbh->prepare(qq{ update backups set inc_size = ?, parts = ? where id = ? });  my $sth_inc_size = $dbh->prepare(qq{ update backups set inc_size = ?, parts = ? where id = ? });
178  my $sth_inc_deleted = $dbh->prepare(qq{ update backups set inc_deleted = ? where id = ? });  my $sth_inc_deleted = $dbh->prepare(qq{ update backups set inc_deleted = ? where id = ? });
179    
 %BackupPC::SearchLib::Conf = %Conf;  
180    
181  $sth->execute();  $sth->execute();
182  my $num_backups = $sth->rows;  my $num_backups = $sth->rows;
# Line 204  while (my $row = $sth->fetchrow_hashref) Line 208  while (my $row = $sth->fetchrow_hashref)
208                  $size = (stat( "$tar_dir/$tar_file" ))[7];                  $size = (stat( "$tar_dir/$tar_file" ))[7];
209          }          }
210    
211          if ($size > 45) {          if ($size > $MIN_TAR_SIZE) {
212    
213                  my $max_size = $Conf{'MaxArchiveSize'} || die "problem with MaxArchieSize parametar";                  my $max_size = $Conf{'MaxArchiveSize'} || die "problem with MaxArchiveSize parametar";
214                  $max_size *= 1024;      # convert to bytes                  $max_size *= 1024;      # convert to bytes
215    
216                    my $max_file_size = $Conf{'MaxArchiveFileSize'} || die "problem with MaxArchiveFileSize parametar";
217                    $max_file_size *= 1024; # bytes
218    
219                    if ($max_file_size > $max_size) {
220                            warn "MaxArchiveFileSize ($max_file_size) is bigger than MaxArchiveSize ($max_size)\n";
221                            $max_file_size = $max_size;
222                    }
223    
224                    # maximum file size on ISO image is 4Gb
225                    # this will require Linux kernel 2.6.8 or newer
226                    if ( $max_size > $max_file_size ) {
227                            $max_size = $max_file_size;
228                    }
229    
230                  my $parts = int( ($size + $max_size - 1) / $max_size );                  my $parts = int( ($size + $max_size - 1) / $max_size );
231    
232                  if (-d "$tar_dir/$tar_file" && $parts != $row->{'parts'}) {                  if (-d "$tar_dir/$tar_file" && $parts != $row->{'parts'}) {

Legend:
Removed from v.214  
changed lines
  Added in v.230

  ViewVC Help
Powered by ViewVC 1.1.26