r11667@llin: dpavlin | 2005-12-13 19:50:27 +0100
authordpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Tue, 13 Dec 2005 18:08:48 +0000 (18:08 +0000)
committerdpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Tue, 13 Dec 2005 18:08:48 +0000 (18:08 +0000)
 re-order checks for performance improvement

git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/BackupPC/trunk@269 8392b6e1-25fa-0310-8288-cc32f8e212ea

bin/BackupPC_incPartsUpdate

index 2e3d576..2d536aa 100755 (executable)
@@ -168,21 +168,15 @@ sub tar_check($$$$) {
 
                print STDERR " $tarfilename" if ($debug);
 
-               my $path = "$tar_dir/$tarfilename";
-               my $md5_path = $path;
-               $md5_path =~ s/\.tar\.gz$/.md5/ || die "can't create md5 filename from $md5_path";
-               if (! -e $md5_path || -z $md5_path) {
-                       print ", creating md5";
-                       system( $bin->{md5sum} . " $path > $md5_path") == 0 or die "can't create md5 $path: $!";
-               }
-
-               my $md5 = read_file( $md5_path ) || die "can't read md5sum file $md5_path: $!";
-               $md5 =~ s#\s.*$##;
+               my $size = (stat( "$tar_dir/$tarfilename" ))[7] || die "can't stat $tar_dir/$tarfilename";
 
-               my $part_nr = 1;
-               $part_nr = $1 if ($tarfilename =~ m#/(\d+)\.tar\.gz#);
+               if ($size > $Conf{MaxArchiveSize}) {
+                       print STDERR " part bigger than media $size > $Conf{MaxArchiveSize} }}" if ($debug);
+                       $same = 0;
+                       last;
+               }
 
-               my $size = (stat( "$tar_dir/$tarfilename" ))[7] || die "can't stat $tar_dir/$tarfilename";
+               my $path = "$tar_dir/$tarfilename";
 
                open(my $fh, "gzip -cd $tar_dir/$tarfilename |") or die "can't open $tar_dir/$tarfilename: $!";
                binmode($fh);
@@ -195,18 +189,37 @@ sub tar_check($$$$) {
                        push @tar_files, $entry->name;
                        $items++;
                        $tar_size += $entry->size;
+
+                       if ($tar_size > $Conf{MaxArchiveFileSize}) {
+                               print STDERR " part too big $tar_size > $Conf{MaxArchiveFileSize} }}" if ($debug);
+                               $same = 0;
+                               last;
+                       }
+
                }
 
-               if ($tar_size > $Conf{MaxArchiveFileSize}) {
-                       print STDERR " part too big $tar_size > $Conf{MaxArchiveFileSize} }}" if ($debug);
-                       $same = 0;
-                       last;
-               } elsif ($size > $Conf{MaxArchiveSize}) {
-                       print STDERR " part bigger than media $size > $Conf{MaxArchiveSize} }}" if ($debug);
-                       $same = 0;
-                       last;
+               #
+               # check if md5 exists, and if not, create one
+               #
+
+               my $md5_path = $path;
+               $md5_path =~ s/\.tar\.gz$/.md5/ || die "can't create md5 filename from $md5_path";
+               if (! -e $md5_path || -z $md5_path) {
+                       print ", creating md5";
+                       system( $bin->{md5sum} . " $path > $md5_path") == 0 or die "can't create md5 $path: $!";
                }
 
+               my $md5 = read_file( $md5_path ) || die "can't read md5sum file $md5_path: $!";
+               $md5 =~ s#\s.*$##;
+
+               # extract part number from filename
+               my $part_nr = 1;
+               $part_nr = $1 if ($tarfilename =~ m#/(\d+)\.tar\.gz#);
+
+               #
+               # finally, check if backup_parts table in database is valid
+               #
+
                check_part($host, $share, $num, $part_nr, $tar_size, $size, $md5, $items);
        }