mirror of https://github.com/digint/btrbk
btrbk: adapted backup creation for refactored configuration
parent
ef5658c1b0
commit
a269231cf9
81
btrbk
81
btrbk
|
@ -63,11 +63,9 @@ my $loglevel = 1;
|
||||||
|
|
||||||
my %config_defaults = (
|
my %config_defaults = (
|
||||||
snapshot_dir => "_btrbk_snap",
|
snapshot_dir => "_btrbk_snap",
|
||||||
incremental => undef,
|
incremental => 1,
|
||||||
init => undef,
|
receive_log => undef,
|
||||||
create => undef,
|
snapshot_create_always => 0,
|
||||||
log => undef,
|
|
||||||
snapshot_create_always => 0, # TODO: honor this
|
|
||||||
snapshot_preserve_all => 1, # TODO: honor this
|
snapshot_preserve_all => 1, # TODO: honor this
|
||||||
snapshot_preserve_days => undef,
|
snapshot_preserve_days => undef,
|
||||||
snapshot_preserve_weekly => undef,
|
snapshot_preserve_weekly => undef,
|
||||||
|
@ -1008,47 +1006,72 @@ MAIN:
|
||||||
#
|
#
|
||||||
# create backups
|
# create backups
|
||||||
#
|
#
|
||||||
foreach my $job (@$jobs)
|
foreach my $config_vol (@{$config->{VOLUME}})
|
||||||
{
|
{
|
||||||
next if($job->{ABORTED});
|
next if($config_vol->{ABORTED});
|
||||||
|
my $sroot = $config_vol->{sroot} || die;
|
||||||
|
foreach my $config_subvol (@{$config_vol->{SUBVOLUME}})
|
||||||
|
{
|
||||||
|
next if($config_subvol->{ABORTED});
|
||||||
|
my $svol = $config_subvol->{svol} || die;
|
||||||
|
my $snapshot = $config_subvol->{snapshot} || die;
|
||||||
|
my $snapshot_name = $config_subvol->{snapshot_name} || die;
|
||||||
|
|
||||||
my $sroot = $job->{sroot} || die;
|
foreach my $config_target (@{$config_subvol->{TARGET}})
|
||||||
my $svol = $job->{svol} || die;
|
{
|
||||||
my $droot = $job->{droot} || die;
|
next if($config_target->{ABORTED});
|
||||||
my $type = $job->{type} || die;
|
my $droot = $config_target->{droot} || die;
|
||||||
my $snapshot = $job->{snapshot} || die;
|
my $target_type = $config_target->{target_type} || die;
|
||||||
my $snapshot_name = $job->{snapshot_name} || die;
|
|
||||||
my $job_opts = $job->{options} || die;
|
|
||||||
|
|
||||||
|
if($target_type eq "send-receive")
|
||||||
|
{
|
||||||
DEBUG "***";
|
DEBUG "***";
|
||||||
DEBUG "*** $type\[" . join(',', map { "$_=$job_opts->{$_}" } keys(%$job_opts)) . "]";
|
# DEBUG "*** $type\[" . join(',', map { "$_=$job_opts->{$_}" } keys(%$job_opts)) . "]";
|
||||||
|
DEBUG "*** $target_type";
|
||||||
DEBUG "*** source: $sroot/$svol";
|
DEBUG "*** source: $sroot/$svol";
|
||||||
DEBUG "*** dest : $droot/";
|
DEBUG "*** dest : $droot/";
|
||||||
DEBUG "***";
|
DEBUG "***";
|
||||||
INFO "Creating subvolume backup for: $sroot/$svol";
|
INFO "Creating subvolume backup ($target_type) for: $sroot/$svol";
|
||||||
|
|
||||||
my $changelog = "";
|
my $receive_log = config_key($config_target, "receive_log");
|
||||||
if ($job_opts->{log}) {
|
if($receive_log)
|
||||||
|
{
|
||||||
|
if(lc($receive_log) eq "sidecar" ) {
|
||||||
# log defaults to sidecar of destination snapshot
|
# log defaults to sidecar of destination snapshot
|
||||||
$changelog = $job_opts->{logfile} || "$droot/$snapshot_name.btrbk.log";
|
$receive_log = "$droot/$snapshot_name.btrbk.log";
|
||||||
}
|
}
|
||||||
if ($job_opts->{incremental}) {
|
else {
|
||||||
|
$receive_log =~ s/\/+$//; # remove trailing slash
|
||||||
|
$receive_log =~ s/^\/+/\//; # sanitize leading slash
|
||||||
|
unless($receive_log =~ /^\//) {
|
||||||
|
WARN "Receive logfile is not absolute, ignoring: $receive_log";
|
||||||
|
$receive_log = undef;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(config_key($config_target, "incremental"))
|
||||||
|
{
|
||||||
INFO "Using previously created snapshot: $snapshot";
|
INFO "Using previously created snapshot: $snapshot";
|
||||||
# INFO "Attempting incremantal backup (option=incremental)";
|
|
||||||
my ($latest_common_src, $latest_common_dst) = get_latest_common($sroot, $svol, $droot);
|
my ($latest_common_src, $latest_common_dst) = get_latest_common($sroot, $svol, $droot);
|
||||||
if($latest_common_src && $latest_common_dst) {
|
if($latest_common_src && $latest_common_dst) {
|
||||||
my $parent_snap = $latest_common_src->{FS_PATH};
|
my $parent_snap = $latest_common_src->{FS_PATH};
|
||||||
INFO "Using parent snapshot: $parent_snap";
|
INFO "Using parent snapshot: $parent_snap";
|
||||||
btrfs_send_receive($snapshot, $droot, $parent_snap, $changelog);
|
btrfs_send_receive($snapshot, $droot, $parent_snap, $receive_log);
|
||||||
} elsif ($job_opts->{init}) {
|
} elsif (lc(config_key($config_target, "incremental")) ne "strict") {
|
||||||
INFO "No common parent snapshots found, creating initial backup (option=init)";
|
INFO "No common parent subvolume present, creating initial full backup";
|
||||||
btrfs_send_receive($snapshot, $droot, undef, $changelog);
|
btrfs_send_receive($snapshot, $droot, undef, $receive_log);
|
||||||
} 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 option \"incremental\" is set to \"strict\"";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
INFO "Creating full backup (option \"incremental\" is not set)";
|
||||||
|
btrfs_send_receive($snapshot, $droot, undef, $receive_log);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ERROR "Unknown target type \"$target_type\", skipping: $sroot/$svol";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} elsif ($job_opts->{create}) {
|
|
||||||
INFO "Creating new snapshot copy (option=create))";
|
|
||||||
btrfs_send_receive($snapshot, $droot, undef, $changelog);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@ snapshot_create_always yes
|
||||||
|
|
||||||
# TODO: incremental = {yes|no|strict}
|
# TODO: incremental = {yes|no|strict}
|
||||||
incremental strict
|
incremental strict
|
||||||
init yes
|
|
||||||
|
|
||||||
snapshot_preserve_days 14
|
snapshot_preserve_days 14
|
||||||
snapshot_preserve_weekly 0
|
snapshot_preserve_weekly 0
|
||||||
|
@ -37,7 +36,7 @@ volume /mnt/btr_system
|
||||||
subvolume root_gentoo
|
subvolume root_gentoo
|
||||||
target send-receive /mnt/btr_ext/_btrbk
|
target send-receive /mnt/btr_ext/_btrbk
|
||||||
target send-receive /mnt/btr_backup/_btrbk
|
target send-receive /mnt/btr_backup/_btrbk
|
||||||
log sidecar
|
receive_log sidecar
|
||||||
|
|
||||||
subvolume kvm
|
subvolume kvm
|
||||||
target_preserve_days 7
|
target_preserve_days 7
|
||||||
|
@ -47,7 +46,7 @@ volume /mnt/btr_system
|
||||||
target_preserve_weekly 0
|
target_preserve_weekly 0
|
||||||
|
|
||||||
target send-receive /mnt/btr_backup/_btrbk
|
target send-receive /mnt/btr_backup/_btrbk
|
||||||
log sidecar
|
receive_log sidecar
|
||||||
|
|
||||||
|
|
||||||
volume /mnt/btr_data
|
volume /mnt/btr_data
|
||||||
|
|
Loading…
Reference in New Issue