Commit ff6c8836 authored by Nigel Kukard's avatar Nigel Kukard

Don't clobber backups if we're not successful

We only clobber old backups now if we're successful in doing the
new backup. In the past if we failed half way through a new backup
we would of already removed our old backups and lost that data.
parent ccf1d99d
......@@ -792,6 +792,7 @@ sub backup
}
# If we don't have a sequence, this is a new backup?
my $removeOldFiles = 0;
if (!defined($newPathAttribs{$path}->{'sequence'} = $origPathAttribs{$path}->{'sequence'})) {
$newPathAttribs{$path}->{'sequence'} = 0;
@manifestList = keys %{$curFileList};
......@@ -804,12 +805,7 @@ sub backup
} else {
$newPathAttribs{$path}->{'sequence'} = 0;
# Remove old files
removeBackups(
"$dest/$path",
$origPathAttribs{$path}->{'format'},
$origPathAttribs{$path}->{'compression'},
$origPathAttribs{$path}->{'sequence'}
);
$removeOldFiles = 1;
@manifestList = keys %{$curFileList};
}
}
......@@ -863,11 +859,11 @@ sub backup
# Setup manifest delim & tar options
if ($newPathAttribs{$path}->{'manifest.format'} eq "null") {
push(@tarArgs,"--null");
push(@tarArgs,"--files-from", "$dest/$path/dbackup$seq.manifest");
push(@tarArgs,"--files-from", "$dest/$path/dbackup$seq.manifest.tmp");
push(@tarArgs,"--no-unquote");
$manifestDelim = "\0";
} elsif ($newPathAttribs{$path}->{'manifest.format'} eq "newline") {
push(@tarArgs,"--files-from", "$dest/$path/dbackup$seq.manifest");
push(@tarArgs,"--files-from", "$dest/$path/dbackup$seq.manifest.tmp");
$manifestDelim = "\n";
} else {
printLog(LOG_ERROR,"Invalid manifest.format '".$newPathAttribs{$path}->{'manifest.format'}."'\n");
......@@ -875,8 +871,8 @@ sub backup
}
# File list to backup
open(my $fh,">","$dest/$path/dbackup$seq.manifest")
or die "Failed to open '[$dest]/($path)/dbackup$seq.manifest': $!";
open(my $fh,">","$dest/$path/dbackup$seq.manifest.tmp")
or die "Failed to open '[$dest]/($path)/dbackup$seq.manifest.tmp': $!";
foreach my $item (@manifestList) {
# Sanity check to see if this filename is going to work
if ($manifestDelim eq "\n" && $item =~ /[\n"'\\]/) {
......@@ -911,13 +907,13 @@ sub backup
"--create",
"--verbose",
# Output file
"--file", "$dest/$path/dbackup$seq.tar$tarExt",
"--file", "$dest/$path/dbackup$seq.tar$tarExt.tmp",
# cd into here first...
"--directory", "$source",
# Do not recurse
"--no-recursion",
# Output to this file
"--index-file", "$dest/$path/dbackup$seq.index",
"--index-file", "$dest/$path/dbackup$seq.index.tmp",
# Incremental options
# "--listed-incremental", "$dest/$path/dbackup.snar",
# "--no-check-device",
......@@ -936,15 +932,40 @@ sub backup
printLog(LOG_ERROR,"tar died with error code $retcode\n");
# exit 1;
}
# Check if we need to blow away all old backup files
if ($removeOldFiles) {
removeBackups(
"$dest/$path",
$origPathAttribs{$path}->{'format'},
$origPathAttribs{$path}->{'compression'},
$origPathAttribs{$path}->{'sequence'}
);
}
# Move temp files in place now
if (!rename("$dest/$path/dbackup$seq.tar$tarExt.tmp","$dest/$path/dbackup$seq.tar$tarExt")) {
printLog(LOG_ERROR,"Failed to move '$dest/$path/dbackup$seq.tar$tarExt' in place: $!\n");
exit 1;
}
if (!rename("$dest/$path/dbackup$seq.index.tmp","$dest/$path/dbackup$seq.index")) {
printLog(LOG_ERROR,"Failed to move '$dest/$path/dbackup$seq.index' in place: $!\n");
exit 1;
}
if (!rename("$dest/$path/dbackup$seq.manifest.tmp","$dest/$path/dbackup$seq.manifest")) {
printLog(LOG_ERROR,"Failed to move '$dest/$path/dbackup$seq.manifest' in place: $!\n");
exit 1;
}
}
} else { # if (($doBackup{$path} & ST_DIR_SYS) != ST_DIR_SYS) {
# Remove old files
removeBackups(
"$dest/$path",
$origPathAttribs{$path}->{'format'},
$origPathAttribs{$path}->{'compression'},
$origPathAttribs{$path}->{'sequence'}
);
# Remove old files
removeBackups(
"$dest/$path",
$origPathAttribs{$path}->{'format'},
$origPathAttribs{$path}->{'compression'},
$origPathAttribs{$path}->{'sequence'}
);
}
} # if (($doBackup{$path} & ST_FILE_CHANGED) == ST_FILE_CHANGED) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment