App-Yabsm
view release on metacpan or search on metacpan
lib/App/Yabsm/Backup/Generic.pm view on Meta::CPAN
my $config_ref = shift;
my $bootstrap_dir = bootstrap_snapshot_dir(
$backup,
$backup_type,
$config_ref,
DIE_UNLESS_EXISTS => 1
);
opendir my $dh, $bootstrap_dir or confess "yabsm: internal error: cannot opendir '$bootstrap_dir'";
my @boot_snaps = grep { is_snapshot_name($_, ONLY_BOOTSTRAP => 1) } readdir($dh);
map { $_ = "$bootstrap_dir/$_" } @boot_snaps;
close $dh;
if (0 == @boot_snaps) {
return undef;
}
elsif (1 == @boot_snaps) {
return $boot_snaps[0];
}
else {
die "yabsm: error: found multiple local bootstrap snapshots for ${backup_type}_backup '$backup' in '$bootstrap_dir'\n";
}
}
sub bootstrap_lock_file {
# Return the path to the BOOTSTRAP-LOCK for $backup if it exists and return
# undef otherwise.
arg_count_or_die(3, 3, @_);
my $backup = shift;
my $backup_type = shift;
my $config_ref = shift;
my $rx = qr/yabsm-${backup_type}_backup_${backup}_BOOTSTRAP-LOCK/;
my $lock_file = [ grep /$rx/, glob('/tmp/*') ]->[0];
return $lock_file;
}
sub create_bootstrap_lock_file {
# Create the bootstrap lock file for $backup. This function should be called
# when performing the bootstrap phase of an incremental backup after checking
# to make sure a lock file doesn't already exist. If a lock file already
# exists we die, so check beforehand!
arg_count_or_die(3, 3, @_);
my $backup = shift;
my $backup_type = shift;
my $config_ref = shift;
backup_exists_or_die($backup, $config_ref);
is_backup_type_or_die($backup_type);
if (my $existing_lock_file = bootstrap_lock_file($backup, $backup_type, $config_ref)) {
die "yabsm: error: ${backup_type}_backup '$backup' is already locked out of performing a bootstrap. This was determined by the existence of '$existing_lock_file'\n";
}
# The file will be deleted when $tmp_fh is destroyed.
my $tmp_fh = File::Temp->new(
TEMPLATE => "yabsm-${backup_type}_backup_${backup}_BOOTSTRAP-LOCKXXXX",
DIR => '/tmp',
UNLINK => 1
);
return $tmp_fh;
}
sub is_backup_type_or_die {
# Logdie unless $backup_type equals 'ssh' or 'local'.
arg_count_or_die(1, 1, @_);
my $backup_type = shift;
unless ( $backup_type =~ /^(ssh|local)$/ ) {
confess("yabsm: internal error: '$backup_type' is not 'ssh' or 'local'");
}
return 1;
}
1;
( run in 2.031 seconds using v1.01-cache-2.11-cpan-40ba7b3775d )