Skip to content

Instantly share code, notes, and snippets.

@vasi
Created January 4, 2015 18:27
Show Gist options
  • Select an option

  • Save vasi/e475262d517bedfcf136 to your computer and use it in GitHub Desktop.

Select an option

Save vasi/e475262d517bedfcf136 to your computer and use it in GitHub Desktop.
BackupPC_tarCreate wrapper
#!/usr/bin/perl
use warnings;
use v5.12;
use File::Basename qw(dirname);
use Data::Dumper;
sub usage {
print <<USAGE;
bpc-tar HOST DIR
Output a tarball corresponding to the most recent BackupPC backup of a
directory for a host.
USAGE
exit 2;
}
my $host = shift;
usage if $host eq '-h' || $host eq '--help';
my $path = shift;
# Try to get directory from SSH_ORIGINAL_COMMAND
unless (defined $path) {
my @orig = split ' ', $ENV{SSH_ORIGINAL_COMMAND};
splice @orig, 0, 2; # Don't allow to override command or host
$path = shift @orig;
}
usage unless defined $path;
my $prefix = dirname($path);
my $cmd = '/usr/share/backuppc/bin/BackupPC_tarCreate';
my @args = ($cmd,
'-n', '-1', # Last backup
'-s', '/', # Share name is /
'-h', $host,
'-r', $prefix, # Prune the prefix
$path);
#print STDERR Dumper \@args;
exec @args or die "Failed to run BackupPC_tarCreate: $!\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment