btrbk: cleanup

pull/30/head
Axel Burri 2014-12-14 22:45:23 +01:00
parent c99a69a31c
commit 8930c0a87f
1 changed files with 9 additions and 13 deletions

22
btrbk
View File

@ -149,7 +149,7 @@ sub btr_subvolume_detail($)
my $ret = run_cmd("/sbin/btrfs subvolume show $vol 2>/dev/null", 1); my $ret = run_cmd("/sbin/btrfs subvolume show $vol 2>/dev/null", 1);
if($ret eq "$vol is btrfs root") { if($ret eq "$vol is btrfs root") {
TRACE "btr_detail: found btrfs root: $vol"; TRACE "btr_detail: found btrfs root: $vol";
return { ID => 5, is_root => 1 }; return { id => 5, is_root => 1 };
} }
elsif($ret =~ /^$vol/) { elsif($ret =~ /^$vol/) {
TRACE "btr_detail: found btrfs subvolume: $vol"; TRACE "btr_detail: found btrfs subvolume: $vol";
@ -158,7 +158,7 @@ sub btr_subvolume_detail($)
uuid => "uuid", uuid => "uuid",
parent_uuid => "Parent uuid", parent_uuid => "Parent uuid",
creation_time => "Creation time", creation_time => "Creation time",
ID => "Object ID", id => "Object ID",
gen => "Generation \\(Gen\\)", gen => "Generation \\(Gen\\)",
cgen => "Gen at creation", cgen => "Gen at creation",
parent_id => "Parent", parent_id => "Parent",
@ -397,7 +397,6 @@ sub btrfs_send_receive($$;$$)
$receive_option = "-v -v" if($parent && $changelog); $receive_option = "-v -v" if($parent && $changelog);
my $cmd = "/sbin/btrfs send $parent_option $src | /sbin/btrfs receive $receive_option $dst/ 2>&1"; my $cmd = "/sbin/btrfs send $parent_option $src | /sbin/btrfs receive $receive_option $dst/ 2>&1";
my $ret = run_cmd($cmd); my $ret = run_cmd($cmd);
# run_cmd("/bin/sync");
if($changelog && (not $dryrun)) if($changelog && (not $dryrun))
{ {
INFO "Writing btrfs-diff changelog: $changelog"; INFO "Writing btrfs-diff changelog: $changelog";
@ -430,7 +429,6 @@ sub get_children($$)
DEBUG "Found snapshot child: $_->{SUBVOL_PATH}"; DEBUG "Found snapshot child: $_->{SUBVOL_PATH}";
push(@ret, $_); push(@ret, $_);
} }
# DEBUG "Found " . scalar(@ret) . " snapshot children of: $sroot/$svol";
return @ret; return @ret;
} }
@ -443,13 +441,11 @@ sub get_receive_targets_by_uuid($$)
die("subvolume info not present: $uuid") unless(exists($uuid_info{$uuid})); die("subvolume info not present: $uuid") unless(exists($uuid_info{$uuid}));
DEBUG "Getting receive targets in \"$droot/\" for: $uuid_info{$uuid}->{FS_PATH}"; DEBUG "Getting receive targets in \"$droot/\" for: $uuid_info{$uuid}->{FS_PATH}";
my @ret; my @ret;
# foreach (values %{$vol_info{$droot}->{SUBVOLUME}}) { # this is for btr_tree, not btr_subtree!
foreach (values %{$vol_info{$droot}}) { foreach (values %{$vol_info{$droot}}) {
next unless($_->{received_uuid} eq $uuid); next unless($_->{received_uuid} eq $uuid);
DEBUG "Found receive target: $_->{SUBVOL_PATH}"; DEBUG "Found receive target: $_->{SUBVOL_PATH}";
push(@ret, $_); push(@ret, $_);
} }
# DEBUG "Found " . scalar(@ret) . " receive targets of: $uuid_info{$uuid}->{FS_PATH}";
return @ret; return @ret;
} }
@ -489,7 +485,7 @@ MAIN:
my $command = shift @ARGV; my $command = shift @ARGV;
# assign command line options # assign command line options
$loglevel = $opts{l} || 0; $loglevel = $opts{l} || "";
if (lc($loglevel) eq "warn") { $loglevel = 1; } if (lc($loglevel) eq "warn") { $loglevel = 1; }
elsif(lc($loglevel) eq "info") { $loglevel = 2; } elsif(lc($loglevel) eq "info") { $loglevel = 2; }
elsif(lc($loglevel) eq "debug") { $loglevel = 3; } elsif(lc($loglevel) eq "debug") { $loglevel = 3; }
@ -498,9 +494,9 @@ MAIN:
else { else {
$loglevel = $opts{v} ? 2 : 0; $loglevel = $opts{v} ? 2 : 0;
} }
my $config = $opts{c} || $default_config; my $config = $opts{c} || $default_config;
my $time_format = $opts{t} || $default_time_format; my $time_format = $opts{t} || $default_time_format;
my $snapdir = $opts{s} || $default_snapdir; my $snapdir = $opts{s} || $default_snapdir;
$snapdir =~ s/\/+$//; # remove trailing slash $snapdir =~ s/\/+$//; # remove trailing slash
$snapdir =~ s/^\/+//; # remove leading slash $snapdir =~ s/^\/+//; # remove leading slash
$snapdir .= '/'; # add trailing slash $snapdir .= '/'; # add trailing slash
@ -769,10 +765,8 @@ MAIN:
btrfs_send_receive($snapshot, $droot, $parent_snap, $changelog); btrfs_send_receive($snapshot, $droot, $parent_snap, $changelog);
} }
elsif($job_opts->{init}) { elsif($job_opts->{init}) {
# if(check_vol($droot, $dvol)) { # TODO: perform checks INFO "No common parent snapshots found, creating initial backup (option=init)";
INFO "No common parent snapshots found, creating initial backup (option=init)"; btrfs_send_receive($snapshot, $droot, undef, $changelog);
btrfs_send_receive($snapshot, $droot, undef, $changelog);
# }
} }
else { else {
WARN "Backup to $droot failed: no common parent subvolume found, and job option \"create\" is not set"; WARN "Backup to $droot failed: no common parent subvolume found, and job option \"create\" is not set";
@ -786,4 +780,6 @@ MAIN:
} }
} }
} }
1; 1;