bin/amdumpext
changeset 13 4e072a6ae1f3
parent 12 9e30f40ffb34
child 14 d9b06b08b28d
equal deleted inserted replaced
12:9e30f40ffb34 13:4e072a6ae1f3
    21 use Pod::Usage;
    21 use Pod::Usage;
    22 use Getopt::Long;
    22 use Getopt::Long;
    23 use File::Basename;
    23 use File::Basename;
    24 use POSIX;
    24 use POSIX;
    25 
    25 
    26 #use Readonly;
       
    27 
       
    28 our $VERSION = '0.01';
    26 our $VERSION = '0.01';
    29 my $ME = basename $0;
    27 my $ME = basename $0;
    30 
    28 
    31 # to avoid stupid "not found"
    29 # to avoid stupid "not found"
    32 $ENV{PATH} .= ':/usr/local/sbin:/usr/sbin:/sbin';
    30 $ENV{PATH} .= ':/usr/local/sbin:/usr/sbin:/sbin';
    52     CLIENT_ESTIMATE => YES,    # estimate
    50     CLIENT_ESTIMATE => YES,    # estimate
    53     MULTI_ESTIMATE  => YES,    # estimate for multiple levels
    51     MULTI_ESTIMATE  => YES,    # estimate for multiple levels
    54     CALCSIZE        => NO,     # estimate --calcsize
    52     CALCSIZE        => NO,     # estimate --calcsize
    55                                #
    53                                #
    56     RECORD          => YES,    # --record
    54     RECORD          => YES,    # --record
       
    55     COLLECTION	    => NO,
    57 );
    56 );
    58 
    57 
    59 sub exec_support;
    58 sub exec_support;
    60 sub exec_selfcheck;
    59 sub exec_selfcheck;
    61 sub exec_estimate;
    60 sub exec_estimate;
    62 sub exec_backup;
    61 sub exec_backup;
    63 sub exec_validate;
    62 sub exec_validate;
       
    63 sub exec_restore;
    64 
    64 
    65 # some helper functions
    65 # some helper functions
    66 
    66 
    67 sub device;
    67 sub device;
    68 sub OK;
    68 sub OK;
    78 my @opt_level;      # 0…99
    78 my @opt_level;      # 0…99
    79 
    79 
    80 my $opt_dumpdates;
    80 my $opt_dumpdates;
    81 
    81 
    82 MAIN: {
    82 MAIN: {
    83     my @argv = @ARGV;
       
    84     my $command = shift // pod2usage;
    83     my $command = shift // pod2usage;
       
    84     #warn "<<< $command | @ARGV >>>\n";
    85     GetOptions(
    85     GetOptions(
    86         'config=s'    => \$opt_config,
    86         'config=s'    => \$opt_config,
    87         'device=s'    => \$opt_device,       # --device $device
    87         'device=s'    => \$opt_device,       # --device $device
    88         'message=s'   => \$opt_message,      # --message line|xml
    88         'message=s'   => \$opt_message,      # --message line|xml
    89         'index=s'     => \$opt_index,        # --index line
    89         'index=s'     => \$opt_index,        # --index line
    93         'host=s'      => sub { },            # ignore
    93         'host=s'      => sub { },            # ignore
    94         'disk=s'      => sub { },            # ignore
    94         'disk=s'      => sub { },            # ignore
    95     ) or pod2usage;
    95     ) or pod2usage;
    96 
    96 
    97     given ($command) {
    97     given ($command) {
    98         when ('support') { exec_support }
    98         when ('support')  { exec_support }
       
    99         when ('validate') { exec_validate }
       
   100         when ('restore')  { exec_restore @ARGV }
    99         when ('selfcheck') {
   101         when ('selfcheck') {
   100             pod2usage if undef ~~ $opt_device;
   102             pod2usage if undef ~~ $opt_device;
   101             exec_selfcheck
   103             exec_selfcheck;
   102         }
   104         }
   103         when ('estimate') {
   105         when ('estimate') {
   104             pod2usage if undef ~~ [$opt_device, $opt_level[0]];
   106             pod2usage if undef ~~ [$opt_device, $opt_level[0]];
   105             exec_estimate
   107             exec_estimate;
   106         }
   108         }
   107         when ('backup') {
   109         when ('backup') {
   108             pod2usage if undef ~~ [$opt_device, $opt_level[0]];
   110             pod2usage if undef ~~ [$opt_device, $opt_level[0]];
   109             exec_backup
   111             exec_backup;
   110         }
       
   111         when ('validate') {
       
   112             exec_validate
       
   113         }
   112         }
   114 
   113 
   115         default { pod2usage }
   114         default { pod2usage }
   116     }
   115     }
   117 }
   116 }
   423 
   422 
   424 sub exec_validate {
   423 sub exec_validate {
   425 
   424 
   426     my $pid = fork // die "Can't fork: $!\n";
   425     my $pid = fork // die "Can't fork: $!\n";
   427     open(STDOUT, '>', '/dev/null')
   426     open(STDOUT, '>', '/dev/null')
   428 	or die "Can't redirect STDOUT to /dev/null: $!\n";
   427       or die "Can't redirect STDOUT to /dev/null: $!\n";
   429 
   428 
   430     # the first part goes into restore
   429     # the first part goes into restore
   431     # but restore stops reading after the directory
   430     # but restore stops reading after the directory
   432     if (not $pid) {
   431     if (not $pid) {
   433         exec 'restore', '-tf', '-';
   432         exec 'restore', '-tf', '-';
   440     # nobody is fast than cat
   439     # nobody is fast than cat
   441     exec 'cat';
   440     exec 'cat';
   442     die "Can't exec `cat': $!\n";
   441     die "Can't exec `cat': $!\n";
   443 }
   442 }
   444 
   443 
       
   444 sub exec_restore {
       
   445     if (not @_ or $_[0] eq '.') {
       
   446 	# complete file system restore
       
   447 	exec 'restore', '-yrf', '-';
       
   448     }
       
   449 
       
   450     # just some files - in this mode
       
   451     # no true incremental restore can be done
       
   452     # (it will just add new files or do updates, but it
       
   453     # won't remove any files!)
       
   454     exec 'restore', '-yxf', '-', @_;
       
   455 }
       
   456 
   445 sub device {
   457 sub device {
   446     my $_ = shift;
   458     my $_ = shift;
   447     return $_ if /^\//;
   459     return $_ if /^\//;
   448     return "/dev/$_";
   460     return "/dev/$_";
   449 }
   461 }
   461 
   473 
   462   amdumpext - the amanda dump application
   474   amdumpext - the amanda dump application
   463 
   475 
   464 =head1 SYNOPSIS
   476 =head1 SYNOPSIS
   465 
   477 
   466   amdumpext support
   478   amdumpext support   [options]
   467   amdumpext selfcheck [options] [--level <level>] --device <device> 
   479   amdumpext selfcheck [options] [--level <level>] --device <device> 
   468   amdumpext backup    [options] [--level <level>] --device <device> 
   480   amdumpext backup    [options] [--level <level>] --device <device> 
   469   amdumpext estimate  [options] [--level <level>]... --device <device> 
   481   amdumpext estimate  [options] [--level <level>]... --device <device> 
   470   amdumpext validate 
   482   amdumpext validate  [options]
       
   483   amdumpext restore   [options]
   471 
   484 
   472 =head1 DESCRIPTION
   485 =head1 DESCRIPTION
   473 
   486 
   474 The B<amdumpext> is an application plugin for amanda. It drives the
   487 The B<amdumpext> is an application plugin for amanda. It drives the
   475 native ext2/3/4 dump/restore programs found on most Linux systems. See L<dump(8)>
   488 native ext2/3/4 dump/restore programs found on most Linux systems. See L<dump(8)>
   476 and L<restore(8)> for more information on these tools.
   489 and L<restore(8)> for more information on these tools.
   477 
   490 
       
   491 =head1 OPTIONS
       
   492 
       
   493 The commands may need some options. These options are noted per command.
       
   494 Unsupported options are silently ignored. Unknown options are not
       
   495 allowed.
       
   496 
       
   497 =over
       
   498 
       
   499 =item B<--device> I<device>
       
   500 
       
   501 The disk device from the disklist.
       
   502 
       
   503 =item B<--disk> I<disk>
       
   504 
       
   505 The diskname from the disklist. Currently ignored.
       
   506 
       
   507 =item B<--host> I<host>
       
   508 
       
   509 The hostname from the disklist. Currently ignored.
       
   510 
       
   511 =item B<--config> I<config>
       
   512 
       
   513 The name of the configuration.
       
   514 
       
   515 =item B<--level> I<level>
       
   516 
       
   517 The level of the backup. 0 means full backup.
       
   518 
       
   519 =item B<--index> I<xml|line>
       
   520 
       
   521 Create an index of the files backed up. XML is not supported yet.
       
   522 (Default: not set, means no index at all)
       
   523 
       
   524 =item B<--message> I<xml|line>
       
   525 
       
   526 The format used for messages. XML is not supported yet.
       
   527 (Default: line)
       
   528 
       
   529 =back
       
   530 
       
   531 =head1 PROPERTIES
       
   532 
       
   533 The properties may be set on the server side to tune the behaviour
       
   534 of the application. Currently property setting on the client side is
       
   535 not supported.
       
   536 
       
   537 =over 4
       
   538 
       
   539 =item B<--dumpdates> I<dumpdates>
       
   540 
       
   541 The location of the dumpdates file. Placeholder "${c}" is allowed and
       
   542 replaced by the name of the current config.
       
   543 
       
   544 =back
       
   545 
       
   546 
   478 =head1 COMMANDS
   547 =head1 COMMANDS
   479 
   548 
   480 The B<amdumpext> supports the commands from the API description found on 
   549 The B<amdumpext> supports the commands from the API description found on 
   481 L<http://wiki.zmanda.com/index.php/Application_API/Operations>.
   550 L<http://wiki.zmanda.com/index.php/Application_API/Operations>.
   482 
       
   483 =head1 COMMON OPTIONS
       
   484 
       
   485 =over
       
   486 
       
   487 =item B<--device> I<device>
       
   488 
       
   489 The disk device from the disklist.
       
   490 
       
   491 =item B<--disk> I<disk>
       
   492 
       
   493 The diskname from the disklist. Currently ignored.
       
   494 
       
   495 =item B<--host> I<host>
       
   496 
       
   497 The hostname from the disklist. Currently ignored.
       
   498 
       
   499 =item B<--config> I<config>
       
   500 
       
   501 The name of the configuration.
       
   502 
       
   503 =item B<--level> I<level>
       
   504 
       
   505 The level of the backup. 0 means full backup.
       
   506 
       
   507 =item B<--index> I<xml|line>
       
   508 
       
   509 Create an index of the files backed up. XML is not supported yet.
       
   510 (Default: not set, means no index at all)
       
   511 
       
   512 =item B<--message> I<xml|line>
       
   513 
       
   514 The format used for messages. XML is not supported yet.
       
   515 (Default: line)
       
   516 
       
   517 =back
       
   518 
       
   519 =head1 COMMANDS
       
   520 
   551 
   521 =head2 support
   552 =head2 support
   522 
   553 
   523 This command returns the list of supported features.
   554 This command returns the list of supported features.
   524 
   555 
   540 
   571 
   541 This checks if the data stream is readable and looks like a dump.
   572 This checks if the data stream is readable and looks like a dump.
   542 Actually it does not try to completly validate the stream, as B<restore>
   573 Actually it does not try to completly validate the stream, as B<restore>
   543 does not have such an option.
   574 does not have such an option.
   544 
   575 
   545 =head1 PROPERTIES
   576 =head2 restore
   546 
   577 
   547 The properties may be set on the server side to tune the behaviour
   578 Restore from a single dump.
   548 of the application. Currently property setting on the client side is
       
   549 not supported.
       
   550 
       
   551 =over 4
       
   552 
       
   553 =item B<--dumpdates> I<dumpdates>
       
   554 
       
   555 The location of the dumpdates file. Placeholder "${c}" is allowed and
       
   556 replaced by the name of the current config.
       
   557 
       
   558 =back
       
   559 
   579 
   560 =head1 TESTING
   580 =head1 TESTING
   561 
   581 
   562 The B<amdumpext> may be tested on the command line. The following output
   582 The B<amdumpext> may be tested on the command line. The following output
   563 file descriptors are used:
   583 file descriptors are used: