btrbk: logging prints "..." on consecutive lines

pull/334/head
Axel Burri 2019-12-15 18:01:16 +01:00
parent 1f7773dddc
commit 67d24695f1
1 changed files with 32 additions and 34 deletions

66
btrbk
View File

@ -374,17 +374,17 @@ END_HELP
#80-----------------------------------------------------------------------------
}
sub TRACE { if($loglevel >= 4) { print STDERR "... $_\n" foreach(@_) } }
sub DEBUG { if($loglevel >= 3) { print STDERR "$_\n" foreach(@_) } }
sub INFO { if($loglevel >= 2) { print STDERR "$_\n" foreach(@_) } }
sub WARN { if($loglevel >= 1) { print STDERR "WARNING: $_\n" foreach(@_) } }
sub ERROR { print STDERR "ERROR: $_\n" foreach(@_) ; }
sub _log_cont { my $p = shift; print STDERR $p . join("\n${p}... ", @_) . "\n"; }
sub TRACE { print STDERR map { "___ $_\n" } @_ if($loglevel >= 4) }
sub DEBUG { _log_cont("", @_) if($loglevel >= 3) }
sub INFO { _log_cont("", @_) if($loglevel >= 2) }
sub WARN { _log_cont("WARNING: ", @_) if($loglevel >= 1) }
sub ERROR { _log_cont("ERROR: ", @_) }
sub WARN_ONCE {
my $t = shift;
if($warn_once{$t}) { TRACE("WARNING(again): $t"); }
else { $warn_once{$t} = 1; WARN($t); }
if($warn_once{$t}) { TRACE("WARNING(again): $t", @_); return 0; }
else { $warn_once{$t} = 1; WARN($t, @_); return 1; }
}
sub VINFO {
@ -918,7 +918,7 @@ sub btrfs_filesystem_usage($)
filter_stderr => \&_btrfs_filter_stderr,
);
unless(defined($ret)) {
ERROR "Failed to fetch btrfs filesystem usage for: $vol->{PRINT}", map("... $_", @stderr);
ERROR "Failed to fetch btrfs filesystem usage for: $vol->{PRINT}", @stderr;
return undef;
}
@ -1225,7 +1225,7 @@ sub btrfs_subvolume_find_new($$;$)
filter_stderr => \&_btrfs_filter_stderr,
);
unless(defined($ret)) {
ERROR "Failed to fetch modified files for: $vol->{PRINT}", map("... $_", @stderr);
ERROR "Failed to fetch modified files for: $vol->{PRINT}", @stderr;
return undef;
}
@ -1293,7 +1293,7 @@ sub btrfs_subvolume_snapshot($$)
);
end_transaction("snapshot", defined($ret));
unless(defined($ret)) {
ERROR "Failed to create snapshot: $svol->{PRINT} -> $target_path", map("... $_", @stderr);
ERROR "Failed to create snapshot: $svol->{PRINT} -> $target_path", @stderr;
return undef;
}
return $target_vol;
@ -1393,7 +1393,7 @@ sub btrfs_subvolume_delete($@)
@deleted = () if($catch_count != (scalar keys %err_catch));
}
unless(scalar(@deleted)) {
ERROR "Failed to match error messages from delete command, assuming nothing deleted", map("... $_", @stderr);
ERROR "Failed to match error messages from delete command, assuming nothing deleted", @stderr;
ERROR map("Possibly not deleted subvolume: $_->{PRINT}", @$targets);
ERROR "Consider running 'btrbk prune -n'";
}
@ -1425,7 +1425,7 @@ sub btrfs_qgroup_destroy($@)
);
end_transaction($opts{type} // "qgroup_destroy", defined($ret));
unless(defined($ret)) {
ERROR "Failed to destroy qgroup \"$qgroup_id\" for subvolume: $vol->{PRINT}", map("... $_", @stderr);
ERROR "Failed to destroy qgroup \"$qgroup_id\" for subvolume: $vol->{PRINT}", @stderr;
return undef;
}
return $vol;
@ -1544,8 +1544,7 @@ sub btrfs_send_receive($$;$$$)
end_transaction("send-receive", not $send_receive_error);
if($send_receive_error) {
ERROR "Failed to send/receive subvolume: $snapshot->{PRINT} " . ($parent_path ? "[$parent_path]" : "") . " -> $vol_received->{PRINT}";
ERROR map("... $_", @cmd_err);
ERROR "Failed to send/receive subvolume: $snapshot->{PRINT} " . ($parent_path ? "[$parent_path]" : "") . " -> $vol_received->{PRINT}", @cmd_err;
}
if($is_garbled) {
@ -1696,7 +1695,7 @@ sub btrfs_send_to_file($$$;$$)
name => $kdf_backend_name
);
unless(defined($kdf_values)) {
ERROR "Failed to generate session key for $key_target_text", map("... $_", @stderr);
ERROR "Failed to generate session key for $key_target_text", @stderr;
return undef;
}
@ -1828,8 +1827,7 @@ sub btrfs_send_to_file($$$;$$)
}
end_transaction("send-to-raw", defined($ret));
unless(defined($ret)) {
ERROR "Failed to send btrfs subvolume to raw file: $source->{PRINT} " . ($parent_path ? "[$parent_path]" : "") . " -> $vol_received->{PRINT}";
ERROR map("... $_", @cmd_err);
ERROR "Failed to send btrfs subvolume to raw file: $source->{PRINT} " . ($parent_path ? "[$parent_path]" : "") . " -> $vol_received->{PRINT}", @cmd_err;
return undef;
}
return 1;
@ -5211,11 +5209,11 @@ MAIN:
# NOTE: ssh://{src,target} uses default config
my $src_vol = vinfo($src_url, $config);
unless(vinfo_init_root($src_vol)) { ERROR "Failed to fetch subvolume detail for '$src_vol->{PRINT}'", map("... $_", @stderr); exit 1; }
unless(vinfo_init_root($src_vol)) { ERROR "Failed to fetch subvolume detail for '$src_vol->{PRINT}'", @stderr; exit 1; }
if($src_vol->{node}{is_root}) { ERROR "Subvolume is btrfs root: $src_vol->{PRINT}"; exit 1; }
my $target_vol = vinfo($target_url, $config);
unless(vinfo_init_root($target_vol)) { ERROR "Failed to fetch subvolume detail for '$target_vol->{PRINT}'", map("... $_", @stderr); exit 1; }
unless(vinfo_init_root($target_vol)) { ERROR "Failed to fetch subvolume detail for '$target_vol->{PRINT}'", @stderr; exit 1; }
if($target_vol->{node}{is_root}) { ERROR "Subvolume is btrfs root: $target_vol->{PRINT}"; exit 1; }
unless(_is_same_fs_tree($src_vol->{node}, $target_vol->{node})) {
@ -5296,7 +5294,7 @@ MAIN:
# map url to real path (we need to match against mount points below)
my $root_path = system_realpath($root_vol);
unless($root_path) {
ERROR "Cannot find real path for: $root_vol->{PATH}";
ERROR "Cannot find real path for: $root_vol->{PATH}", @stderr;
exit 1;
}
$root_vol = vinfo($root_path, $config);
@ -5317,7 +5315,7 @@ MAIN:
$realpath_cache{$mnt->{mount_point}} = $mnt->{mount_point}; # we know those are real paths, prevents calling readlink in btrfs_mountpoint
my $vol = vinfo($mnt->{mount_point}, $config);
unless(vinfo_init_root($vol)) {
ERROR "Failed to fetch subvolume detail for: $vol->{PRINT}", map("... $_", @stderr);
ERROR "Failed to fetch subvolume detail for: $vol->{PRINT}", @stderr;
exit 1;
}
@ -5397,12 +5395,12 @@ MAIN:
my $src_root = vinfo($src_url, $config);
unless(vinfo_init_root($src_root)) {
ERROR "Failed to fetch subvolume detail for '$src_root->{PRINT}'", map("... $_", @stderr);
ERROR "Failed to fetch subvolume detail for '$src_root->{PRINT}'", @stderr;
exit 1;
}
my $archive_root = vinfo($archive_url, $config);
unless($archive_raw ? vinfo_init_raw_root($archive_root) : vinfo_init_root($archive_root)) {
ERROR "Failed to fetch " . ($archive_raw ? "raw target metadata" : "subvolume detail") . " for '$archive_root->{PRINT}'", map("... $_", @stderr);
ERROR "Failed to fetch " . ($archive_raw ? "raw target metadata" : "subvolume detail") . " for '$archive_root->{PRINT}'", @stderr;
exit 1;
}
@ -5438,7 +5436,7 @@ MAIN:
vinfo_assign_config($sroot);
unless(vinfo_init_root($sroot)) {
ABORTED($sroot, "Failed to fetch subvolume detail");
WARN "Skipping archive source \"$sroot->{PRINT}\": " . ABORTED_TEXT($sroot), map("... $_", @stderr);
WARN "Skipping archive source \"$sroot->{PRINT}\": " . ABORTED_TEXT($sroot), @stderr;
next;
}
@ -5448,7 +5446,7 @@ MAIN:
DEBUG "Failed to fetch " . ($archive_raw ? "raw target metadata" : "subvolume detail") . " for '$droot->{PRINT}'";
unless(system_mkdir($droot)) {
ABORTED($droot, "Failed to create directory: $droot->{PRINT}/");
WARN "Skipping archive target \"$droot->{PRINT}\": " . ABORTED_TEXT($droot), map("... $_", @stderr);
WARN "Skipping archive target \"$droot->{PRINT}\": " . ABORTED_TEXT($droot), @stderr;
next;
}
$droot->{SUBDIR_CREATED} = 1;
@ -5462,7 +5460,7 @@ MAIN:
# after directory is created, try to init again
unless($archive_raw ? vinfo_init_raw_root($droot) : vinfo_init_root($droot)) {
ABORTED($droot, "Failed to fetch subvolume detail");
WARN "Skipping archive target \"$droot->{PRINT}\": " . ABORTED_TEXT($droot), map("... $_", @stderr);
WARN "Skipping archive target \"$droot->{PRINT}\": " . ABORTED_TEXT($droot), @stderr;
next;
}
}
@ -5642,7 +5640,7 @@ MAIN:
$sroot_glob = vinfo($config_vol->{url}, $config_vol);
unless(vinfo_init_root($sroot_glob)) {
ABORTED($sroot_glob, "Failed to fetch subvolume detail");
WARN "Skipping subvolume (wildcards) \"$sroot_glob->{PRINT}/$globs\": " . ABORTED_TEXT($sroot_glob), map("... $_", @stderr);
WARN "Skipping subvolume (wildcards) \"$sroot_glob->{PRINT}/$globs\": " . ABORTED_TEXT($sroot_glob), @stderr;
last;
}
}
@ -5975,14 +5973,14 @@ MAIN:
DEBUG "Initializing volume section: $sroot->{PRINT}";
unless(vinfo_init_root($sroot)) {
ABORTED($sroot, "Failed to fetch subvolume detail");
WARN "Skipping volume \"$sroot->{PRINT}\": " . ABORTED_TEXT($sroot), map("... $_", @stderr);
WARN "Skipping volume \"$sroot->{PRINT}\": " . ABORTED_TEXT($sroot), @stderr;
next;
}
foreach my $svol (vinfo_subsection($sroot, 'subvolume')) {
DEBUG "Initializing subvolume section: $svol->{PRINT}";
unless(vinfo_init_root($svol)) {
ABORTED($svol, "Failed to fetch subvolume detail");
WARN "Skipping subvolume \"$svol->{PRINT}\": " . ABORTED_TEXT($svol), map("... $_", @stderr);
WARN "Skipping subvolume \"$svol->{PRINT}\": " . ABORTED_TEXT($svol), @stderr;
next;
}
if((not $svol->{node}{uuid}) || ($svol->{node}{uuid} eq '-')) {
@ -6013,7 +6011,7 @@ MAIN:
my $snaproot = vinfo_snapshot_root($svol);
unless(vinfo_init_root($snaproot)) {
ABORTED($svol, "Failed to fetch subvolume detail for snapshot_dir");
WARN "Skipping subvolume \"$svol->{PRINT}\": " . ABORTED_TEXT($svol), map("... $_", @stderr);
WARN "Skipping subvolume \"$svol->{PRINT}\": " . ABORTED_TEXT($svol), @stderr;
next;
}
unless(_is_same_fs_tree($snaproot->{node}, $svol->{node})) {
@ -6040,7 +6038,7 @@ MAIN:
{
unless(vinfo_init_root($droot)) {
ABORTED($droot, "Failed to fetch subvolume detail");
WARN "Skipping target \"$droot->{PRINT}\": " . ABORTED_TEXT($droot), map("... $_", @stderr);
WARN "Skipping target \"$droot->{PRINT}\": " . ABORTED_TEXT($droot), @stderr;
next;
}
}
@ -6048,7 +6046,7 @@ MAIN:
{
unless(vinfo_init_raw_root($droot)) {
ABORTED($droot, "Failed to fetch raw target metadata");
WARN "Skipping target \"$droot->{PRINT}\": " . ABORTED_TEXT($droot), map("... $_", @stderr);
WARN "Skipping target \"$droot->{PRINT}\": " . ABORTED_TEXT($droot), @stderr;
next;
}
}
@ -6098,7 +6096,7 @@ MAIN:
my $url = $subvol_args[0] || die;
my $vol = vinfo($url, $config);
unless(vinfo_init_root($vol)) {
ERROR "Failed to fetch subvolume detail for: $url", map("... $_", @stderr);
ERROR "Failed to fetch subvolume detail for: $url", @stderr;
exit 1;
}
if($vol->{node}{is_root}) {