r11636@llin: dpavlin | 2005-12-12 14:53:13 +0100
authordpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Mon, 12 Dec 2005 13:41:04 +0000 (13:41 +0000)
committerdpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Mon, 12 Dec 2005 13:41:04 +0000 (13:41 +0000)
 fixes

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

Makefile
bin/BackupPC_tarIncCreate

index c040dcd..e59522c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -75,7 +75,7 @@ profile: test
 
 tar: test
        psql -c "delete from backup_parts" backuppc
-       sudo -u backuppc /data/backuppc/bin/BackupPC_tarIncCreate -h llin -s /etc -n 10 -v
+       sudo -u backuppc /data/backuppc/bin/BackupPC_tarIncCreate -h llin -s /etc -n 10 -v -f -d
 
 inc: test
        sudo -u backuppc /data/backuppc/bin/BackupPC_incPartsUpdate -c -d
index 94027f2..9354b86 100755 (executable)
@@ -86,7 +86,7 @@ my %opts;
 my $in_backup_increment;
 
 
-if ( !getopts("th:n:p:r:s:b:w:vd", \%opts) ) {
+if ( !getopts("th:n:p:r:s:b:w:vdf", \%opts) ) {
     print STDERR <<EOF;
 usage: $0 [options]
   Required options:
@@ -102,6 +102,7 @@ usage: $0 [options]
      -p pathAdd      new path prefix
      -b BLOCKS       BLOCKS x 512 bytes per record (default 20; same as tar)
      -w writeBufSz   write buffer size (default 1048576 = 1MB)
+     -f              overwrite existing parts
      -v              verbose output
      -d              debug output
 EOF
@@ -224,6 +225,13 @@ $sth->finish;
 
 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) {
+       if ($opts{f}) {
+               rmtree $tar_path_final || die "can't remove $tar_path_final: $!";
+       } else {
+               die "$tar_path_final allready exists\n";
+       }
+}
 
 my $fh;
 my $part = 0;
@@ -268,13 +276,20 @@ sub new_tar_part {
 
                if ($arg->{close}) {
 
+                       sub move($$) {
+                               my ($from,$to) = @_;
+                               print STDERR "# rename $from -> $to\n" if ($opts{d});
+                               rename $from, $to || die "can't move $from -> $to: $!\n";
+                       }
+
                        if ($part == 1) {
                                print STDERR " single";
-                               rename "${tar_path}/1.tar.gz", "${tar_path_final}/.tar.gz" || die "can't move tar ${tar_path}: $! ";
-                               rename "${tar_path}/1.md5", "${tar_path_final}/.md5" || die "can't move md5 ${tar_path}: $! ";
+                               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]";
-                               rename "${tar_path}", "${tar_path_final}" || die "can't move tar ${tar_path}: $! ";
+                               move("${tar_path}", "${tar_path_final}");
                        }
 
                        $sth_inc_size->execute(
@@ -340,18 +355,11 @@ new_tar_part();
 if (seedCache($Host, $ShareName, $Num)) {
        archiveWrite($fh, '/');
        archiveWriteHardLinks($fh);
+       new_tar_part( close => 1 );
 } else {
        print STDERR "NOTE: no files found for $Host:$ShareName, increment $Num\n" if ($opts{v});
-       $no_files = 1;
-}
-
-new_tar_part( close => 1 );
-
-# remove temporary files if there are no files
-if ($no_files) {
+       # remove temporary files if there are no files
        rmtree($tar_path);
-} elsif ($part == 1) {
-       warn "FIXME: if there is only one part move to parent directory and rename";
 }
 
 #