From 251c2fb2a11fd69032d23c074771bf758aac1cae Mon Sep 17 00:00:00 2001 From: Axel Burri Date: Tue, 26 Sep 2017 12:28:18 +0200 Subject: [PATCH] btrbk: re-enable parsing of deprecated raw file format (uuid suffix) --- btrbk | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/btrbk b/btrbk index f113267..e1cc9d3 100755 --- a/btrbk +++ b/btrbk @@ -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/\.(?[0-9]{4})(?[0-9]{2})(?
[0-9]{2})(T(?[0-9]{2})(?[0-9]{2})((?[0-9]{2})(?(Z|[+-][0-9]{4})))?)?(_(?[0-9]+))?/; # matches "YYYYMMDD[Thhmm[ss+0000]][_NN]" +my $raw_postfix_match_DEPRECATED = qr/--(?$uuid_match)(\@(?$uuid_match))?\.btrfs?(\.(?($compress_format_alt)))?(\.(?gpg))?(\.(?split))?(\.(?part))?/; # matches ".btrfs_[@][.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 =~ /^(?$file_match)(?$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 =~ /^(?$file_match)$timestamp_postfix_match$raw_postfix_match$/)) { ; } + elsif($raw_info && $name =~ /^(?$file_match)$timestamp_postfix_match$raw_postfix_match_DEPRECATED$/) { ; } # DEPRECATED raw format elsif((not $raw_info) && ($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}) &&