Re: some fixes to Vault.pm (Amanda 3.4)

Jean-Louis Martineau <[email protected]> Fri, 22 Sep 2017 09:04:05 -0400
Newsgroups gmane.comp.archivers.amanda.devel
Message-ID <[email protected]>
Nathan,

Thanks for both patch.
I committed the attached patch, I made some more fix, can you try them?

On 21/09/17 03:06 PM, Nathan Stratton Treadway wrote:
> I was experimenting with "amvault" (Amanda 3.4.5), and noticed a few
> issues, which I have attempted to fix in the attached patch to 
> Vault.pm: 
> <http://Vault.pm:>
>
> * when run on a tty, the progress messages say "nnnnnn KB", but nnnnnn
> is actually in bytes; also, add the word "written" to make it clearer
> what the message means.
As it is expected to be read by a human, I think kbytes is better than 
bytes,I changed it to:
   return ($self->{'bytes_written'}/1024)." kbytes written";

Jean-Louis

>
> * the 5s time period mentioned in the comment about creating a timer
> callback seems to be obsolete.
>
> * The value of the $self->{'quiet'} parameter does not appear to be used
> anywhere in the Vault.pm 
> <http://Vault.pm> 
> code. For a quick fix, this patch makes --quiet
> suppress the interactive "bytes written" progress messages.
>
> Nathan
>
>
> ----------------------------------------------------------------------------
> Nathan Stratton Treadway - [email protected] - Mid-Atlantic region
> Ray Ontko & Co. - Software consulting services - http://www.ontko.com/ 
> <http://www.ontko.com/>
> GPG Key: http://www.ontko.com/~nathanst/gpg_key.txt 
> <http://www.ontko.com/~nathanst/gpg_key.txt> ID: 
> 1023D/ECFB6239
> Key fingerprint = 6AD8 485E 20B9 5C71 231C 0C32 15F3 ADCD ECFB 6239
This message is the property of CARBONITE, INC. and may contain confidential or privileged information.
If this message has been delivered to you by mistake, then do not copy or deliver this message to anyone.  Instead, destroy it and notify me by reply e-mail
amvault.diff (text/x-patch, 7.1 KB)
diff --git a/man/xml-source/amvault.8.xml b/man/xml-source/amvault.8.xml
index 87f5502..ab85dd7 100644
--- a/man/xml-source/amvault.8.xml
+++ b/man/xml-source/amvault.8.xml
@@ -89,7 +89,7 @@ timestamp <option>src-timestamp</option> onto volumes using the storage
 
 <para>The dumps to be read from secondary media can be specified by any
 combination of dump specifications, <option>--fulls-only</option>,
-<option>--incrs-only</option>, and
+<option>--latest-fulls</option>, <option>--incrs-only</option>, and
 <option>--src-timestamp</option>.  At least one must be specified, lest
 amvault attempt to vault all dumps in the catalog.  See <manref
     name="amanda-match" vol="7"/> for more information on dump
@@ -132,7 +132,12 @@ parameters there.  Then reference that tapetype in the amvault invocation:
   <varlistentry>
   <term><option>--dest-storage</option> <replaceable>dest-storage</replaceable></term>
   <listitem>
-<para>Dumps are written to that storage</para>
+<para>The vaulted dumps are written to the specified storage.</para>
+
+<para>If the <replaceable>vault-storage</replaceable> option is specified
+in &amconf;, amvault will use that storage as the default destination.
+If not, a destination storage must be specific on the amvault command
+line.</para>
   </listitem>
   </varlistentry>
 
@@ -184,22 +189,32 @@ import/export slots, where they can be more easily removed by an operator.
   <varlistentry>
   <term><option>--no-interactivity</option></term>
   <listitem>
-<para>Disable interactivity if a source volume is not found.</para>
+<para>Disable interactivity if a source or destination volume is not
+found.</para>
   </listitem>
   </varlistentry>
 
   <varlistentry>
   <term><option>--quiet</option></term><term><option>-q</option></term>
   <listitem>
-<para>Eliminate non-error messages, and is useful when running amvault from
-cron.</para>
+<para>Suppress the progress messages normally printed to the terminal
+as dumps are being copied.</para>
+  </listitem>
+  </varlistentry>
+
+  <varlistentry>
+  <term><option>--src-labelstr</option> <replaceable>labelstr</replaceable></term>
+  <listitem>
+<para>Only dumps from volumes matching labelstr are copied.</para>
   </listitem>
   </varlistentry>
 
   <varlistentry>
   <term><option>--src-storage</option> <replaceable>src-storage</replaceable></term>
   <listitem>
-<para>Dumps are read only from that storage</para>
+<para>Only dumps found on the specified storage are copied.
+(If this option is not given, all available source storages will be
+searched.)</para>
   </listitem>
   </varlistentry>
 
diff --git a/perl/Amanda/Vault.pm b/perl/Amanda/Vault.pm
index 114e75c..05166ce 100644
--- a/perl/Amanda/Vault.pm
+++ b/perl/Amanda/Vault.pm
@@ -52,7 +52,7 @@ sub local_message {
     } elsif ($self->{'code'} == 2500007) {
 	return "No dumps found";
     } elsif ($self->{'code'} == 2500008) {
-	return "$self->{'bytes_written'} KB";
+	return ($self->{'bytes_written'}/1024)." kbytes written";
     } elsif ($self->{'code'} == 2500010) {
 	return "No import/export slots available; skipping export";
     } elsif ($self->{'code'} == 2500011) {
@@ -294,7 +294,8 @@ sub create_status_file {
     $self->amdump_log("status file $self->{'id'}:" .  "$self->{status_filename}");
     print {$self->{status_fh}} "0";
 
-    # create timer callback, firing every 5s (=5000msec)
+    # create timer callback, firing every 'delay' ms (as specified by caller
+    # when this Vault was created))
     if (!$self->{'timer'}) {
 	$self->{timer} = Amanda::MainLoop::timeout_source($self->{'delay'});
 	$self->{timer}->set_callback(sub {
@@ -304,7 +305,9 @@ sub create_status_file {
 		print {$self->{status_fh}} $size, '     ';
 		$self->{status_fh}->flush();
 
-		if ($self->{'is_tty'}) {
+		# print progress message if we're running on a tty,
+		# unless --quiet option was given.
+		if ($self->{'is_tty'} && !$self->{'quiet'}) {
 		    $self->user_msg(Amanda::Vault::Message->new(
 				source_filename => __FILE__,
 				source_line     => __LINE__,
@@ -887,13 +890,13 @@ sub quit {
 	    $self->{'dst'}{'scribe'}->quit(
 		finished_cb => $steps->{'quit_scribe_finished'});
 	} else {
-	    $steps->{'quit_clerk'}->();
+	    $steps->{'quit_scribe_finished'}->();
 	}
     };
 
     step quit_scribe_finished => sub {
-	$self->{'dst'}{'scan'}->quit();
 	my ($err) = @_;
+	$self->{'dst'}{'scan'}->quit();
 	if ($err) {
 	    $self->user_msg($err);
 	    debug("scribe error: $err");
diff --git a/server-src/amvault.pl b/server-src/amvault.pl
index e0d2ecf..a5b630d 100644
--- a/server-src/amvault.pl
+++ b/server-src/amvault.pl
@@ -118,25 +118,34 @@ sub usage {
 **NOTE** this interface is under development and will change in future releases!
 
 Usage: amvault [-o configoption...] [-q] [--quiet] [-n] [--dry-run]
-	   [--fulls-only] [--latest-fulls] [--incrs-only] [--export]
-	   [--src-timestamp src-timestamp] [--exact-match]
-	   [--src-storage storage] [--dest-storage storage]
+	   [--exact-match] [--export] [--no-interactivity]
+	   [--src-labelstr labelstr] [--src-storage storage]
+	   [--dest-storage storage]
+	   [--fulls-only] [--latest-fulls] [--incrs-only]
+	   [--src-timestamp src-timestamp]
 	   config
 	   [hostname [ disk [ date [ level [ hostname [...] ] ] ] ]]
 
     -o: configuration override (see amanda(8))
-    -q: quiet progress messages
+    -q/--quiet: quiet progress messages
+
+    --dest-storage: destination storage for vaulting operation
+
+    --exact-match: parse host and disk as exact values
+    --export: move completed destination volumes to import/export slots
+    --src-labelstr: only copy dumps from volumes matching labelstr
+    --src-storage: only copy dumps from specified storage
+
     --fulls-only: only copy full (level-0) dumps
     --latest-fulls: copy the latest full of every dle
     --incrs-only: only copy incremental (level > 0) dumps
-    --export: move completed destination volumes to import/export slots
     --src-timestamp: the timestamp of the Amanda run that should be vaulted
 
-Copies data on storage src-storage from the run with timestamp <src-timestamp>
-onto volumes on the storage <dest-storage>.  If <src-timestamp> is "latest",
-then the most recent run of amdump or amflush will be used.  If any dumpspecs
-are included (<host-expr> and so on), then only dumps matching those dumpspecs
-will be dumped.  At least one of --fulls-only, --src-timestamp, or a dumpspec
+Copies dumps selected by the specified filters onto volumes on the storage
+<dest-storage>.  If <src-timestamp> is "latest", then the most recent run of
+amdump or amflush will be used.  If any dumpspecs are included (<host-expr> and
+so on), then only dumps matching those dumpspecs will be dumped.  At least one
+of --fulls-only, --latest-fulls, --incrs-only, --src-timestamp, or a dumpspec
 must be specified.
 
 EOF
@@ -242,14 +251,15 @@ if ($is_tty) {
 } else {
     $delay = 15000; # 15 seconds
 }
+$|++;
 
 sub user_msg {
     my $msg = shift;
 
-    if ($msg->{'code'} == 2400008) {
+    if ($msg->{'code'} == 2500008) {
 	if ($is_tty) {
 	    if (!$last_is_size) {
-		print STDOUT "\n";
+		#print STDOUT "\n";
 		$last_is_size = 1;
 	    }
 	    print STDOUT "\r" . $msg . " ";