Backup-Duplicity-YADW
view release on metacpan or search on metacpan
lib/Backup/Duplicity/YADW.pm view on Meta::CPAN
sub backup {
args_pos
my $self,
my $type => 'Str';
$type = $type eq 'inc' ? 'incremental' : $type;
confess "invalid type: $type"
if $type ne 'full' and $type ne 'incremental';
my @cmd = ( 'duplicity', $type );
$self->_get_verbosity( \@cmd );
$self->_get_exclude_device_files( \@cmd );
$self->_get_incl_excl_list( \@cmd );
$self->_get_encrypt_key( \@cmd );
$self->_get_log_file( \@cmd );
$self->_get_async_upload( \@cmd );
$self->_get_s3_new( \@cmd );
$self->_get_sourcedir( \@cmd );
$self->_get_targetdir( \@cmd );
$self->_system(@cmd);
return 1;
}
sub _get_sourcedir {
args_pos
my $self,
my $cmds;
push @$cmds, $self->_conf->get('sourcedir');
}
sub _get_targetdir {
args_pos
# required
my $self, my $cmds,
# optional
my $locaction => { isa => 'Str', optional => 1 };
my $str = $self->_conf->get('targeturl');
$str .= "/$locaction" if $locaction;
push( @$cmds, $str );
}
sub _get_async_upload {
args_pos
my $self,
my $cmds;
if ( $self->_conf()->get('asyncupload') ) {
push @$cmds, '--asynchronous-upload';
}
}
sub _get_incl_excl_list {
args_pos
my $self,
my $cmds;
my $conf = $self->_conf;
my $block = $conf->block('inclexcl');
my @list = $block->get('list');
for ( my $i = 0; $i < @list; $i += 2 ) {
my $key = trim $list[$i];
my $val = trim $list[ $i + 1 ];
if ( $key eq '-' ) {
$key = '--exclude';
}
elsif ( $key eq '+' ) {
$key = '--include';
}
else {
confess "malformed InclExcl section";
}
push @$cmds, $key, $val;
}
}
sub _write_pidfile {
args_pos my $self;
my $conf = $self->_conf;
my $pidfile = $conf->get('pidfile');
$self->_log( 'info', "pidfile=$pidfile" );
my $pid = PID::File->new( file => $pidfile);
if ( -e $pid->file ) {
if ( $pid->running ) {
$ErrCode = PID_EXISTS;
$ErrStr = "yadw is already running";
confess $ErrStr;
}
else {
$self->_log( 'notice', "removing stale pidfile $pidfile" );
unlink $pid->file or confess "failed to remove pidfile: $!";
}
}
$pid->create or confess "failed to write pidfile: $!";
$pid->guard; # remove pidfile automatically when it goes out of scope
$self->_pid($pid);
}
( run in 0.747 second using v1.01-cache-2.11-cpan-9581c071862 )