btrbk: re-enable parsing of deprecated raw file format (uuid suffix)

pull/204/head
Axel Burri 2017-09-26 12:28:18 +02:00
parent e804930b5e
commit 251c2fb2a1
1 changed files with 56 additions and 2 deletions

58
btrbk
View File

@ -61,6 +61,7 @@ my $file_match = qr/[0-9a-zA-Z_@\+\-\.\/]+/; # note: ubuntu uses '@' in the sub
my $glob_match = qr/[0-9a-zA-Z_@\+\-\.\/\*]+/; # file_match plus '*'
my $uuid_match = qr/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/;
my $timestamp_postfix_match = qr/\.(?<YYYY>[0-9]{4})(?<MM>[0-9]{2})(?<DD>[0-9]{2})(T(?<hh>[0-9]{2})(?<mm>[0-9]{2})((?<ss>[0-9]{2})(?<zz>(Z|[+-][0-9]{4})))?)?(_(?<NN>[0-9]+))?/; # matches "YYYYMMDD[Thhmm[ss+0000]][_NN]"
my $raw_postfix_match_DEPRECATED = qr/--(?<received_uuid>$uuid_match)(\@(?<parent_uuid>$uuid_match))?\.btrfs?(\.(?<compress>($compress_format_alt)))?(\.(?<encrypt>gpg))?(\.(?<split>split))?(\.(?<incomplete>part))?/; # matches ".btrfs_<received_uuid>[@<parent_uuid>][.gz|bz2|xz][.gpg][.split][.part]"
my $raw_postfix_match = qr/\.btrfs(\.($compress_format_alt))?(\.gpg)?/; # matches ".btrfs[.gz|bz2|xz][.gpg]"
my $group_match = qr/[a-zA-Z0-9_:-]+/;
@ -1163,7 +1164,10 @@ sub btrfs_subvolume_delete($@)
} else {
push @cmd_target_paths, { unsafe => $_->{PATH} };
}
push @cmd_target_paths, { unsafe => "$_->{PATH}.info" };
if($_->{node}{BTRBK_RAW}{INFO_FILE}) {
# DEPRECATED raw format: no info file in deprecated format
push @cmd_target_paths, { unsafe => "$_->{PATH}.info" };
}
}
$ret = run_cmd(cmd => ['rm', @cmd_target_paths ],
rsh => vinfo_rsh($targets->[0]),
@ -1704,6 +1708,50 @@ sub system_read_raw_info_dir($)
DEBUG("Parsed " . @raw_targets . " raw info files in path: $droot->{PATH}");
TRACE(Data::Dumper->Dump([\@raw_targets], ["system_read_raw_info_dir($droot->{URL})"])) if($do_dumper);
#
# read DEPRECATED raw format (btrbk < v0.26.0)
#
$ret = run_cmd(
cmd => [ 'find', { unsafe => $droot->{PATH} . '/' }, '-maxdepth', '1', '-type', 'f' ],
rsh => vinfo_rsh($droot),
non_destructive => 1,
);
unless(defined($ret)) {
ABORTED($droot, "Failed to list files from: $droot->{PATH}");
return undef;
}
my $deprecated_found = 0;
foreach (split("\n", $ret))
{
unless(/^($file_match)$/) {
DEBUG "Skipping non-parseable file: \"$_\"";
next;
}
my $file = $1; # untaint argument
unless($file =~ s/^\Q$droot->{PATH}\E\///) {
ABORTED($droot, "Unexpected result from 'find': file \"$file\" is not under \"$droot->{PATH}\"");
last;
}
if($file =~ /^(?<name>$file_match)(?<timestamp>$timestamp_postfix_match)$raw_postfix_match_DEPRECATED$/) {
push @raw_targets, {
# NOTE: if INFO_FILE is not present, this raw target is treated as deprecated format
TYPE => 'raw',
FILE => $file,
RECEIVED_UUID => $+{received_uuid} // die,
RECEIVED_PARENT_UUID => $+{parent_uuid} // '-',
INCOMPLETE => $+{incomplete} ? 1 : 0,
encrypt => $+{encrypt} // "",
compress => $+{compress} // "",
};
$deprecated_found++;
}
}
DEBUG("Parsed $deprecated_found deprecated raw backup files in path: $droot->{PATH}");
if($deprecated_found) {
WARN("Found $deprecated_found raw backup files with deprecated file format in: $droot->{PRINT}");
WARN("Please convert the raw backup files using the `raw_suffix2sidecar` utility.");
}
return \@raw_targets;
}
@ -2054,6 +2102,7 @@ sub add_btrbk_filename_info($;$)
$name =~ s/^(.*)\///;
if($raw_info && ($name =~ /^(?<name>$file_match)$timestamp_postfix_match$raw_postfix_match$/)) { ; }
elsif($raw_info && $name =~ /^(?<name>$file_match)$timestamp_postfix_match$raw_postfix_match_DEPRECATED$/) { ; } # DEPRECATED raw format
elsif((not $raw_info) && ($name =~ /^(?<name>$file_match)$timestamp_postfix_match$/)) { ; }
else {
return undef;
@ -4803,7 +4852,12 @@ MAIN:
readonly => ($raw_info->{INCOMPLETE} ? 0 : 1),
}, $raw_info))
{
ABORTED($droot, "Ambiguous file in .info: \"$raw_info->{INFO_FILE}\"");
if($raw_info->{INFO_FILE}) {
ABORTED($droot, "Ambiguous file in .info: \"$raw_info->{INFO_FILE}\"");
} else {
# DEPRECATED raw format
ABORTED($droot, "Ambiguous file: \"$raw_info->{FILE}\"");
}
last;
}
unless(defined($subvol->{node}{BTRBK_RAW}) &&