App-Yabsm

 view release on metacpan or  search on metacpan

bin/yabsm  view on Meta::CPAN


    # apt install cpanminus
    # cpanm App::Yabsm

=head1 The Yabsm Daemon

    usage: yabsm <daemon|d> [--help] [start] [stop] [restart] [status] [init]

Snapshots and backups are performed by the Yabsm daemon. The Yabsm daemon must be
started as root so it can initialize its runtime environment, which includes
creating a locked user named I<yabsm> (and a group named I<yabsm>) that the
daemon will run as. You can initialize the daemon's runtime environment without
actually starting the daemon by running C<yabsm daemon init>.

When the daemon starts, it reads the C</etc/yabsm.conf> file that specifies its
L<configuration|/"Configuration"> to determine when to schedule the snapshots and
backups and how to perform them. If the Yabsm daemon is already running and you
make a configuration change, you must run C<yabsm daemon restart> to apply the
changes.

=head3 Initialize Daemon Runtime Environment

lib/App/Yabsm/Backup/Generic.pm  view on Meta::CPAN

    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;

lib/App/Yabsm/Command/Daemon.pm  view on Meta::CPAN

        print $fh $sudoer_rule;

        close $fh
    }

    return $file;
}

sub create_yabsm_user_and_group {

    # Create a locked-user and group named 'yabsm' if they do not already exist.

    arg_count_or_die(1, 1, @_);

    my $config_ref = shift;

    i_am_root_or_die();

    unless (yabsm_user_exists()) {
        system_or_die('useradd', '-m', '-d', yabsm_user_home($config_ref), '-s', '/bin/sh', '-k', '/dev/null', 'yabsm');
        system_or_die('passwd', '--lock', 'yabsm');

lib/App/Yabsm/Command/Daemon.pm  view on Meta::CPAN

    system_or_die('usermod', '-m', '-d', yabsm_user_home($config_ref), 'yabsm');

    my $yabsm_uid = getpwnam('yabsm');
    my $yabsm_gid = getgrnam('yabsm');

    return wantarray ? ($yabsm_uid, $yabsm_gid) : 1;
}

sub yabsm_user_exists {

    # Return 1 if there exists a locked user on the system named 'yabsm'.

    arg_count_or_die(0, 0, @_);

    i_am_root_or_die();

    unless (0 == system('getent passwd yabsm >/dev/null 2>&1')) {
        return 0;
    }

    unless ('L' eq (split ' ', `passwd -S yabsm`)[1]) {
        die q(yabsm: error: found non-locked user named 'yabsm')."\n";
    }

    return 1;
}

sub yabsm_group_exists {

    # Return 1 if there exists on the system a user and group named 'yabsm' and
    # return 0 otherwise.

t/GenericBackup.t  view on Meta::CPAN

    $f = \&App::Yabsm::Backup::Generic::bootstrap_lock_file;

    lives_and { is $f->('foo_local_backup', 'local', \%TEST_CONFIG), undef } "$n - returns undef in no lock file exists";

    $n = 'create_bootstrap_lock_file';
    $f = \&App::Yabsm::Backup::Generic::create_bootstrap_lock_file;

    lives_and {
        my $lock_fh = $f->('foo_local_backup', 'local', \%TEST_CONFIG);
        ok $lock_fh->filename =~ /BOOTSTRAP-LOCK/;
        throws_ok { $f->('foo_local_backup', 'local', \%TEST_CONFIG) } qr/local_backup 'foo_local_backup' is already locked out of performing a bootstrap/, "$n - dies if bootstrap lock already exists";
        $n = 'bootstrap_lock_file';
        $f = \&App::Yabsm::Backup::Generic::bootstrap_lock_file;
        lives_and { ok $f->('foo_local_backup', 'local', \%TEST_CONFIG) =~ /BOOTSTRAP-LOCK/ } "$n - returns correct lock file";
    } "$n - bootstrap lock file functions";
}

# TMP SNAPSHOT TESTS
{
    my $n;
    my $f;



( run in 0.861 second using v1.01-cache-2.11-cpan-49f99fa48dc )