remove directories also
[BackupPC.git] / bin / BackupPC_tarIncCreate
index f9ac5cb..0dc5c21 100755 (executable)
@@ -199,7 +199,6 @@ my(%HardLinkExtraFiles, @HardLinks);
 #
 
 my $max_file_size = $Conf{'MaxArchiveFileSize'} || die "problem with MaxArchiveFileSize parametar";
-$max_file_size *= 1024;
 
 my $tar_dir = $Conf{InstallDir}.'/'.$Conf{GzipTempDir};
 die "problem with $tar_dir, check GzipTempDir in configuration\n" unless (-d $tar_dir && -w $tar_dir);
@@ -223,6 +222,15 @@ $sth->execute($Host, $ShareName, $Num);
 my ($backup_id) = $sth->fetchrow_array;
 $sth->finish;
 
+
+# delete exising backup_parts
+my $sth_delete_backup_parts = $dbh->prepare(qq{
+       delete from backup_parts
+       where backup_id = ?
+});
+$sth_delete_backup_parts->execute($backup_id);
+
+
 print STDERR "backup_id: $backup_id working dir: $tar_dir, max uncompressed size $max_file_size bytes, tar $tar_file\n" if ($opts{d});
 
 if (-e $tar_path_final) {
@@ -244,7 +252,7 @@ sub new_tar_part {
        if ($fh) {
                return if ($current_tar_size == 0);
 
-               print STDERR " $part" if ($opts{v});
+               print STDERR "\n\t+ $part:";
 
                #
                # Finish with two null 512 byte headers,
@@ -263,6 +271,8 @@ sub new_tar_part {
 
                my $size = (stat( $file . '.tar.gz' ))[7] || die "can't stat ${file}.tar.gz";
 
+               print "$file, $size bytes, $items_in_part items";
+
                $sth_backup_parts->execute(
                        $backup_id,
                        $part,
@@ -272,7 +282,6 @@ sub new_tar_part {
                        $items_in_part,
                );
 
-               #$total_increment_size += int( ( $size + 1023 ) / 1024 ) * 1024;
                $total_increment_size += $size;
 
                if ($arg->{close}) {
@@ -284,13 +293,19 @@ sub new_tar_part {
                        }
 
                        if ($part == 1) {
-                               print STDERR " single";
+                               print STDERR " single" if ($opts{v});
                                move("${tar_path}/1.tar.gz", "${tar_path_final}.tar.gz");
                                move("${tar_path}/1.md5", "${tar_path_final}.md5");
                                rmtree $tar_path or die "can't remove temporary dir $tar_path: $!";
                        } else {
-                               print STDERR " [last]";
+                               print STDERR " [last]" if ($opts{v});
                                move("${tar_path}", "${tar_path_final}");
+
+                               # if this archive was single part, remove it
+                               foreach my $suffix (qw/.tar.gz .md5/) {
+                                       my $path = $tar_path_final . $suffix;
+                                       unlink $path if (-e $path);
+                               }
                        }
 
                        $sth_inc_size->execute(
@@ -299,7 +314,7 @@ sub new_tar_part {
                                $backup_id
                        );
 
-                       print STDERR ", $total_increment_size bytes\n" if ($opts{v});
+                       print "\n\ttotal $total_increment_size bytes";
 
                        return;
                }
@@ -318,7 +333,7 @@ sub new_tar_part {
                mkdir($tar_path) || die "can't create directory $tar_path: $!";
 
                sub abort_cleanup {
-                       print STDERR "ABORTED: cleanup temp dir";
+                       print STDERR "ABORTED: cleanup temp dir ";
                        rmtree($tar_path);
                        $dbh->rollback;
                        exit 1;
@@ -361,6 +376,13 @@ if (seedCache($Host, $ShareName, $Num)) {
        print STDERR "NOTE: no files found for $Host:$ShareName, increment $Num\n" if ($opts{v});
        # remove temporary files if there are no files
        rmtree($tar_path);
+
+       my $sth = $dbh->prepare(qq{
+               update backups set inc_size = 0, parts = 0, inc_deleted = true
+               where id = ?
+       });
+       $sth->execute($backup_id);
+
 }
 
 #