stasis

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

{
   "abstract" : "an encrypting archive tool using tar, gpg and perl",
   "author" : [
      "David Farrell"
   ],
   "dynamic_config" : 1,
   "generated_by" : "ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010",
   "license" : [
      "freebsd"
   ],
   "meta-spec" : {
      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",

META.yml  view on Meta::CPAN

---
abstract: 'an encrypting archive tool using tar, gpg and perl'
author:
  - 'David Farrell'
build_requires:
  ExtUtils::MakeMaker: '0'
configure_requires:
  ExtUtils::MakeMaker: '0'
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010'
license: open_source
meta-spec:

README.pod  view on Meta::CPAN

=head1 NAME

stasis - an encrypting archive tool using tar, gpg and perl

=head1 SYNOPSIS

  stasis [options]

  Options:

      --destination -de destination directory to save the encrypted archive to
      --days        -da only create an archive if one doesn't exist within this many days (optional)
      --files       -f  filepath to a text file of filepaths to backup
      --ignore      -i  filepath to a text file of glob patterns to ignore (optional)
      --limit       -l  limit number of stasis backups to keep in destination directory (optional)
      --passphrase      passphrase to use
      --passfile        filepath to a textfile containing the password to use
      --referrer    -r  name of the gpg key to use (instead of a passphrase or passfile)
      --temp        -t  temp directory path, uses /tmp by default
      --verbose     -v  verbose, print progress statements (optional)
      --help        -h  print this documentation (optional)

=head1 OPTIONS

=head2 Examples

Save all the files listed in C<files_to_backup.txt> (one per line) to Dropbox:

README.pod  view on Meta::CPAN

Use referrer GPG key to encrypt

  $ stasis -de ~/Dropbox -f files_to_backup.txt -r keyname@example.com

Ignore the files matching patterns in C<.stasisignore>

  $ stasis -de ~/Dropbox -f files_to_backup.txt -r keyname@example.com -i .stasisignore

Verbose mode

  $ stasis -de ~/Dropbox -f files_to_backup.txt -r mygpgkey@email.com -v

Only keep the last 4 backups

  $ stasis -de ~/Dropbox -f files_to_backup.txt --passphrase mysecretkey -l 4

Only make weekly backups

  $ stasis -de ~/Dropbox -f files_to_backup.txt --passphrase mysecretkey --days 7

=head1 REQUIREMENTS/DEPENDENCIES

stasis  view on Meta::CPAN

  my $ignore_text = $ignore ? "-X $ignore" : "";
  my $file_list = join(' ', @$files);

  log_msg("Compressing files");
  system("tar $args $destination $ignore_text $file_list");
}

sub gen_archive_name
{
  my $dt = localtime;
  my $name = 'stasis-' . $dt->datetime . '.tar.gz.gpg';
  # replace fat32 illegal characters in timestamp
  $name =~ s/:/_/g;
  return $name;
}

sub encrypt
{
  my ($source, $passphrase, $referrer, $passfile, $final_destination) = @_;
  log_msg("Encrypting archive");

  if ($passphrase || $passfile)
  {
    my $pass_arg = $passphrase
      ? "--passphrase $passphrase"
      : "--passphrase-file $passfile";

    system("gpg --no-tty -c -o $final_destination --cipher-algo AES256 $pass_arg $source");
  }
  else
  {
    system("gpg --no-tty -e -o $final_destination -R $referrer $source");
  }
}

sub clean
{
  my ($tmp_file, $destination, $limit, $verbose) = @_;

  log_msg("Cleaning files");

  if (defined $limit)

stasis  view on Meta::CPAN

    # always keep the latest backup
    $limit = 1 if $limit == 0;

    log_verbose("Cleaning backups, limit $limit");
    my @backups = ();
    opendir(my $dir, $destination);

    while (readdir $dir)
    {
      push @backups, "$destination/$_"
        if /^stasis-\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.tar\.gz\.gpg$/;
    }
    my @sorted_backups = sort { $b cmp $a } @backups;
    my @keep_me = splice(@sorted_backups, 0, $limit);

    # delete remaining backups
    log_verbose("Deleting @sorted_backups") if @sorted_backups;
    unlink @sorted_backups;
  }
  unlink $tmp_file;
}

sub need_backup
{
  my $backup_horizon = $start_time - ONE_DAY * $days;
  log_verbose("backup horizon: $backup_horizon");

  opendir(my $dir, $destination);
  while (readdir $dir)
  {
    next unless /^stasis-.+?\.gpg$/;
    my @stat = stat "$destination/$_";
    my $backup_dt = Time::Piece->strptime($stat[9], '%s');
    log_verbose("$destination/$_: $backup_dt");

    return 0 if $backup_dt > $backup_horizon;
  }
  return 1;
}

sub log_msg { print STDERR join("\n", @_, '') }
sub log_verbose { log_msg(@_) if $verbose }

1;
__END__
=head1 NAME

stasis - an encrypting archive tool using tar, gpg and perl

=head1 SYNOPSIS

  stasis [options]

  Options:

      --destination -de destination directory to save the encrypted archive to
      --days        -da only create an archive if one doesn't exist within this many days (optional)
      --files       -f  filepath to a text file of filepaths to backup
      --ignore      -i  filepath to a text file of glob patterns to ignore (optional)
      --limit       -l  limit number of stasis backups to keep in destination directory (optional)
      --passphrase      passphrase to use
      --passfile        filepath to a textfile containing the password to use
      --referrer    -r  name of the gpg key to use (instead of a passphrase or passfile)
      --temp        -t  temp directory path, uses /tmp by default
      --verbose     -v  verbose, print progress statements (optional)
      --help        -h  print this documentation (optional)

=head1 OPTIONS

=head2 Examples

Save all the files listed in C<files_to_backup.txt> (one per line) to Dropbox:

stasis  view on Meta::CPAN

Use referrer GPG key to encrypt

  $ stasis -de ~/Dropbox -f files_to_backup.txt -r keyname@example.com

Ignore the files matching patterns in C<.stasisignore>

  $ stasis -de ~/Dropbox -f files_to_backup.txt -r keyname@example.com -i .stasisignore

Verbose mode

  $ stasis -de ~/Dropbox -f files_to_backup.txt -r mygpgkey@email.com -v

Only keep the last 4 backups

  $ stasis -de ~/Dropbox -f files_to_backup.txt --passphrase mysecretkey -l 4

Only make weekly backups

  $ stasis -de ~/Dropbox -f files_to_backup.txt --passphrase mysecretkey --days 7

=head1 REQUIREMENTS/DEPENDENCIES



( run in 1.107 second using v1.01-cache-2.11-cpan-df04353d9ac )