restore command works too
authorHeiko Schlittermann (JUMPER) <hs@schlittermann.de>
Tue, 17 Dec 2013 11:43:25 +0100
changeset 13 4e072a6ae1f3
parent 12 9e30f40ffb34
child 14 d9b06b08b28d
restore command works too
bin/amdumpext
--- a/bin/amdumpext	Mon Dec 16 21:19:41 2013 +0100
+++ b/bin/amdumpext	Tue Dec 17 11:43:25 2013 +0100
@@ -23,8 +23,6 @@
 use File::Basename;
 use POSIX;
 
-#use Readonly;
-
 our $VERSION = '0.01';
 my $ME = basename $0;
 
@@ -54,6 +52,7 @@
     CALCSIZE        => NO,     # estimate --calcsize
                                #
     RECORD          => YES,    # --record
+    COLLECTION	    => NO,
 );
 
 sub exec_support;
@@ -61,6 +60,7 @@
 sub exec_estimate;
 sub exec_backup;
 sub exec_validate;
+sub exec_restore;
 
 # some helper functions
 
@@ -80,8 +80,8 @@
 my $opt_dumpdates;
 
 MAIN: {
-    my @argv = @ARGV;
     my $command = shift // pod2usage;
+    #warn "<<< $command | @ARGV >>>\n";
     GetOptions(
         'config=s'    => \$opt_config,
         'device=s'    => \$opt_device,       # --device $device
@@ -95,21 +95,20 @@
     ) or pod2usage;
 
     given ($command) {
-        when ('support') { exec_support }
+        when ('support')  { exec_support }
+        when ('validate') { exec_validate }
+        when ('restore')  { exec_restore @ARGV }
         when ('selfcheck') {
             pod2usage if undef ~~ $opt_device;
-            exec_selfcheck
+            exec_selfcheck;
         }
         when ('estimate') {
             pod2usage if undef ~~ [$opt_device, $opt_level[0]];
-            exec_estimate
+            exec_estimate;
         }
         when ('backup') {
             pod2usage if undef ~~ [$opt_device, $opt_level[0]];
-            exec_backup
-        }
-        when ('validate') {
-            exec_validate
+            exec_backup;
         }
 
         default { pod2usage }
@@ -425,7 +424,7 @@
 
     my $pid = fork // die "Can't fork: $!\n";
     open(STDOUT, '>', '/dev/null')
-	or die "Can't redirect STDOUT to /dev/null: $!\n";
+      or die "Can't redirect STDOUT to /dev/null: $!\n";
 
     # the first part goes into restore
     # but restore stops reading after the directory
@@ -442,6 +441,19 @@
     die "Can't exec `cat': $!\n";
 }
 
+sub exec_restore {
+    if (not @_ or $_[0] eq '.') {
+	# complete file system restore
+	exec 'restore', '-yrf', '-';
+    }
+
+    # just some files - in this mode
+    # no true incremental restore can be done
+    # (it will just add new files or do updates, but it
+    # won't remove any files!)
+    exec 'restore', '-yxf', '-', @_;
+}
+
 sub device {
     my $_ = shift;
     return $_ if /^\//;
@@ -463,11 +475,12 @@
 
 =head1 SYNOPSIS
 
-  amdumpext support
+  amdumpext support   [options]
   amdumpext selfcheck [options] [--level <level>] --device <device> 
   amdumpext backup    [options] [--level <level>] --device <device> 
   amdumpext estimate  [options] [--level <level>]... --device <device> 
-  amdumpext validate 
+  amdumpext validate  [options]
+  amdumpext restore   [options]
 
 =head1 DESCRIPTION
 
@@ -475,12 +488,11 @@
 native ext2/3/4 dump/restore programs found on most Linux systems. See L<dump(8)>
 and L<restore(8)> for more information on these tools.
 
-=head1 COMMANDS
+=head1 OPTIONS
 
-The B<amdumpext> supports the commands from the API description found on 
-L<http://wiki.zmanda.com/index.php/Application_API/Operations>.
-
-=head1 COMMON OPTIONS
+The commands may need some options. These options are noted per command.
+Unsupported options are silently ignored. Unknown options are not
+allowed.
 
 =over
 
@@ -516,8 +528,27 @@
 
 =back
 
+=head1 PROPERTIES
+
+The properties may be set on the server side to tune the behaviour
+of the application. Currently property setting on the client side is
+not supported.
+
+=over 4
+
+=item B<--dumpdates> I<dumpdates>
+
+The location of the dumpdates file. Placeholder "${c}" is allowed and
+replaced by the name of the current config.
+
+=back
+
+
 =head1 COMMANDS
 
+The B<amdumpext> supports the commands from the API description found on 
+L<http://wiki.zmanda.com/index.php/Application_API/Operations>.
+
 =head2 support
 
 This command returns the list of supported features.
@@ -542,20 +573,9 @@
 Actually it does not try to completly validate the stream, as B<restore>
 does not have such an option.
 
-=head1 PROPERTIES
-
-The properties may be set on the server side to tune the behaviour
-of the application. Currently property setting on the client side is
-not supported.
+=head2 restore
 
-=over 4
-
-=item B<--dumpdates> I<dumpdates>
-
-The location of the dumpdates file. Placeholder "${c}" is allowed and
-replaced by the name of the current config.
-
-=back
+Restore from a single dump.
 
 =head1 TESTING