Subject: amanda-client: Tar wrapper to allow amrecover to restore filenames 
with "\"
Package: amanda-client
Version: 1:2.5.2p1-5
Severity: wishlist


Hello,

starting with amanda 2.5.x we were no longer able to restore files with
the "\" char in their path with amrecover. amrecover gives the path unescaped
to tar and tar did not find the file in the archive.

This was a problem for us, because every homedir on our samba fileserver has
this char in its name.

It was easy to workaround this with amrestore.

To ease and speedup our restores I write a wrapper for tar that escapes the "\"
and patch amanda, so that only amrecover uses this wrapper.

Attached you find a patch for amanda 2.5.2p1.

Consider applying it, please, or put it to examples.


Regards,
Martin



-- System Information:
Debian Release: 4.0
  APT prefers oldstable
  APT policy: (500, 'oldstable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.24-etchnhalf.1-686-bigmem
Locale: lang=de...@euro, lc_ctype=de...@euro (charmap=ISO-8859-15)

Versions of packages amanda-client depends on:
ii  amanda-common       1:2.5.2p1-5          Advanced Maryland Automatic Networ
ii  libc6               2.3.6.ds1-13etch9+b1 GNU C Library: Shared libraries
ii  libncurses5         5.5-5                Shared libraries for terminal hand
ii  libreadline5        5.2-2                GNU readline and history libraries

amanda-client recommends no packages.

-- no debconf information
diff -ruN amanda-2.5.2p1-orig/amanda-2.5.2p1/debian/amanda-client.dirs amanda-2.5.2p1-tar-escape-wrapper/amanda-2.5.2p1/debian/amanda-client.dirs
--- amanda-2.5.2p1-orig/amanda-2.5.2p1/debian/amanda-client.dirs	2009-05-08 14:05:15.000000000 +0000
+++ amanda-2.5.2p1-tar-escape-wrapper/amanda-2.5.2p1/debian/amanda-client.dirs	2009-05-08 12:50:37.000000000 +0000
@@ -1,3 +1,4 @@
 usr/share/doc/amanda-client
 usr/share/lintian/overrides
 var/lib/amanda/gnutar-lists
+usr/bin
diff -ruN amanda-2.5.2p1-orig/amanda-2.5.2p1/debian/changelog amanda-2.5.2p1-tar-escape-wrapper/amanda-2.5.2p1/debian/changelog
--- amanda-2.5.2p1-orig/amanda-2.5.2p1/debian/changelog	2009-05-08 14:05:15.000000000 +0000
+++ amanda-2.5.2p1-tar-escape-wrapper/amanda-2.5.2p1/debian/changelog	2009-05-08 12:36:40.000000000 +0000
@@ -1,3 +1,13 @@
+amanda (1:2.5.2p1-5ms0) unstable; urgency=low
+
+  * Add #define GNUTAR "/usr/bin/tar-escape-wrapper" to recover-src/amrecover.h
+  * Add revocer-src/tar-escape-wrapper that is only called by amrecover
+    and escapes all "\?*" with one additional "\".
+    It seems not to be necessary to escape [] as tar seems to accept them
+    without \.
+
+ -- Martin <[email protected]>  Thu,  7 May 2009 09:55:43 +0000
+
 amanda (1:2.5.2p1-5) unstable; urgency=low
 
   * add --without-ipv6 as a short-term fix for amdump connectivity problems,
diff -ruN amanda-2.5.2p1-orig/amanda-2.5.2p1/debian/rules amanda-2.5.2p1-tar-escape-wrapper/amanda-2.5.2p1/debian/rules
--- amanda-2.5.2p1-orig/amanda-2.5.2p1/debian/rules	2009-05-08 14:05:15.000000000 +0000
+++ amanda-2.5.2p1-tar-escape-wrapper/amanda-2.5.2p1/debian/rules	2009-05-08 12:50:11.000000000 +0000
@@ -70,6 +70,7 @@
 	dh_installdirs -a
 	make install DESTDIR=$(r)
 	install -m 644 debian/amandahosts $(r)/etc/amandahosts
+	install -m 755 recover-src/tar-escape-wrapper $(c)/usr/bin/tar-escape-wrapper
 	dh_installdocs -a
 	dh_installexamples -a
 	cp ChangeLog $(r)/usr/share/doc/amanda-common/changelog
diff -ruN amanda-2.5.2p1-orig/amanda-2.5.2p1/recover-src/amrecover.h amanda-2.5.2p1-tar-escape-wrapper/amanda-2.5.2p1/recover-src/amrecover.h
--- amanda-2.5.2p1-orig/amanda-2.5.2p1/recover-src/amrecover.h	2007-05-04 11:38:58.000000000 +0000
+++ amanda-2.5.2p1-tar-escape-wrapper/amanda-2.5.2p1/recover-src/amrecover.h	2009-05-08 10:22:40.000000000 +0000
@@ -33,6 +33,7 @@
 #include "amfeatures.h"
 
 #define STARTUP_TIMEOUT 60
+#define GNUTAR "/usr/bin/tar-escape-wrapper"
 
 typedef struct DIR_ITEM
 {
diff -ruN amanda-2.5.2p1-orig/amanda-2.5.2p1/recover-src/tar-escape-wrapper amanda-2.5.2p1-tar-escape-wrapper/amanda-2.5.2p1/recover-src/tar-escape-wrapper
--- amanda-2.5.2p1-orig/amanda-2.5.2p1/recover-src/tar-escape-wrapper	1970-01-01 00:00:00.000000000 +0000
+++ amanda-2.5.2p1-tar-escape-wrapper/amanda-2.5.2p1/recover-src/tar-escape-wrapper	2009-05-08 11:53:30.000000000 +0000
@@ -0,0 +1,75 @@
+#!/usr/bin/perl -w
+
+# Tar Wrapper for Amrecover
+# This wrapper escapes all tar wildcards with "\"
+# to allow amrecover to restore files that have "\", "[" or "]" in their path.
+
+
+#
+# Globals
+#
+my $scriptname     = "tar-escape-wrapper";
+my $SyslogFacility = "user";
+
+
+#
+# Functions
+#
+sub logger {
+        my $priority = shift;
+        my $message  = shift;
+        system("logger", "-t", $scriptname, "-p", "$SyslogFacility.$priority", $message) ;
+}
+
+
+
+#
+#1) Get options list
+#
+
+#Copy option list
+my  @OLDoptions = @ARGV;
+my  @NEWoptions;
+
+
+#
+# 2) Escape wildcards in file an directory arguments
+#
+my $opt;
+foreach $opt (@OLDoptions) {
+  # Check if $opt start with "-". If not assume that it is
+  # a file or directory argument.
+  my $firstchar = substr($opt,0,1);
+  if ( $firstchar eq '-' ){
+    #print "Option: >$opt< \n";
+    logger "debug", "Option:$opt\n";
+  } else {
+    #print "Pre File: >$opt< \n";
+    logger "debug", "Pre File:$opt\n";
+
+    #Escape
+    #$opt =~ s/([\\?*\[\]])/\\$1/g;
+    # Do not escape [], tar seems to accept them without \.
+    $opt =~ s/([\\?*])/\\$1/g;
+
+    #print "PostFile: >$opt< \n";
+    logger "debug", "PostFile:$opt\n";
+  }
+
+  #Build new options list
+  push @NEWoptions, $opt
+
+}
+
+
+
+
+#
+# 3) Call real tar
+logger "debug", "CALL: /bin/tar @NEWoptions \n";
+my $status;
+$status = system("/bin/tar", @NEWoptions);
+my $rc = $status >> 8;
+logger "debug", "Tar exited with exit code $rc \n";
+
+exit $rc;

Reply via email to