diff -ruN e-smith-backup-2.2.0.old/root/etc/e-smith/events/actions/workstation-backup-dar e-smith-backup-2.2.0/root/etc/e-smith/events/actions/workstation-backup-dar --- e-smith-backup-2.2.0.old/root/etc/e-smith/events/actions/workstation-backup-dar 2013-07-06 19:50:52.000000000 -0700 +++ e-smith-backup-2.2.0/root/etc/e-smith/events/actions/workstation-backup-dar 2013-07-06 20:10:43.000000000 -0700 @@ -83,6 +83,7 @@ my $mntdir = ($VFSType eq 'usb') ? "\/$smbshare" : $backupwk->prop('Mount') || '/mnt/smb'; my $frommail = $backupwk->prop('FromMail') || 'admin-backup'; my $tomail = $backupwk->prop('ToMail') || 'admin'; +my $deleteearly = $backupwk->prop('DeleteEarly') || 'false'; my $ether = $internalinterface->prop('Name'); my $tmpdir; @@ -127,14 +127,6 @@ Verify availability of your backup volume. Stopping the backup now.\n"); } -$tmpdir = $mntdir . '/tmp_dir'; - -&removeTree ("$tmpdir/$id"); -&createTree ("$tmpdir/$id"); - -# we know right backup directory is in line and we can write on it. -$report .= "Backup temp directory $tmpdir/$id is mounted and is writable \n"; - # rotating backup indicators ++$incnum; @@ -160,6 +152,19 @@ my $setname = "set" . $setnum; my $setdirname = $mntdir . "/$id/" . $setname; &createTree ($setdirname); + +if ($deleteearly ne 'true') +{ + $tmpdir = $mntdir . '/tmp_dir'; + + &removeTree ("$tmpdir/$id"); + &createTree ("$tmpdir/$id"); + $report .= "Backup temp directory $tmpdir/$id is mounted and is writable \n"; +} +else +{ + $report .= "Backup directory $setdirname is mounted \n"; +} if ( $incnum == 0 ) { @@ -203,7 +209,6 @@ } $report .= "Backup to $bkname in $id/$setname\n"; -$report .= "Making backup in temp directory\n"; # calculate real timeout if we timeout incrementals only. # timeout of 88500 is a security for aborting backup within 24h @@ -212,7 +213,7 @@ { $timeout = 88500; } -$report .= "Using a backup session timeout of : $timeout seconds\n"; +$report .= "Starting the backup with a timeout of $timeout seconds\n"; # expanding backup configuration file template @@ -221,30 +226,37 @@ }); # launching dar backup - -my $rc = run_backup(); -if ($rc != 0 && $rc != 11) +if (($deleteearly eq 'true') && (($incnum == 0))) # Allow delete before backup { - ldie("Error while running dar: $rc"); -} - -if ($incnum == 0) -{ - $report .= "Rotating backups in a new set $setdirname. \n"; &removeTree ($setdirname); &createTree ($setdirname); } -$report .= "Moving backup files to target directory $setdirname \n"; +my $destination = ($deleteearly ne 'true') ? "$tmpdir/$id/$bkname" : "$setdirname/$bkname"; -foreach (bsd_glob("$tmpdir/$id/$bkname*")) -{ - ldie("Error while moving backup file $_ from temporary dir $tmpdir/$id to $setdirname : $!") - unless move($_, $setdirname); +# Perform the actual backup +my $rc = run_backup($destination); + +if ($rc != 0 && $rc != 11) +{ + ldie("Error while running dar: $rc"); } -# Remove temporary directory as no longer needed -&removeTree ("$tmpdir/$id"); +if ($deleteearly ne 'true') # Not DeleteEarly so move backup to $setdirname +{ + $report .= "Moving backup files to target directory $setdirname \n"; + if ($incnum == 0) + { + &removeTree ($setdirname); + &createTree ($setdirname); + } + foreach (bsd_glob("$tmpdir/$id/$bkname*")) + { + ldie("Error while moving backup file $_ from temporary dir $tmpdir/$id to $setdirname : $!") + unless move($_, $setdirname); + } + &removeTree ("$tmpdir/$id"); +} # update dar_manager catalog $report .= "Updating catalog\n"; @@ -425,12 +431,13 @@ sub run_backup { + my $dest = shift; my $data = undef; my $pid = undef; my $killerpid = undef; eval { - ($pid = open INPUT, "-|", "/usr/bin/dar", "-Q", "--create", "$tmpdir/$id/$bkname", split(/\|/,$ref), "-B", "/etc/dar/$job.dcf") or ldie("cannot start : $!" ); + ($pid = open INPUT, "-|", "/usr/bin/dar", "-Q", "--create", "$dest", split(/\|/,$ref), "-B", "/etc/dar/$job.dcf") or ldie("cannot start : $!" ); if ($pid) { $killerpid = start_dar_killer($pid, $timeout); }