Created
January 4, 2015 18:27
-
-
Save vasi/e475262d517bedfcf136 to your computer and use it in GitHub Desktop.
BackupPC_tarCreate wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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