Amrecover: wildcard characters in filenames

From The Open Source Backup Wiki (Amanda, MySQL Backup, BackupPC)

Jump to: navigation, search

This article is a part of the Troubleshooting collection.


If you have backed up files with wildcard characters as part of the filename, and you are using gnutar as part of your Amanda backup process, you may notice that you can no longer pull the files out. The symptoms are:

 amrecover> add *asid=\[101\]*
 Added /joe_asid=[101].gz
 amrecover> extract
 Extracting files using tape drive /dev/nst0 on  host
 The following tapes are needed: big1
 Restoring files into directory /tmp
 Continue? [Y/n]: y
 Load tape big1 now
 Continue? [Y/n]: y
 tar: ./joe_asid=[101].gz: Not found in archive
 tar: Error exit delayed from previous errors


The solution can be one of a number of things:

1. Try to make gnutar treat wildcard characters (like [ and ] and *) as normal characters. I'm not sure this is possible, and I haven't tried.

2. Edit the amrecover source code to make it escape wildcard characters.

3. Use amrestore instead of amrecover This allows you to escape the filenames you're interested in, e.g.:

 $ mt -f /dev/nst0 rewind
 $ amrestore -p /dev/nst0 \ \
    '/backed/up/directory$' | tar -xpvf - './joe_asid=\[101\].gz'

See also Amrestore: "$" character in the filename to be restored

4. Use a wrapper script for tar that escapes the wildcards

The following works for amanda 2.5.2p1. The wrapper script is only used by amrecover. Please note that I do not need to escape the [ ] with tar 1.16.

  1. Add #define GNUTAR "/usr/bin/tar-escape-wrapper" to recover-src/amrecover.h
  2. Recompile and install.
  3. Create the following script in "/usr/bin/tar-escape-wrapper":
 #!/usr/bin/perl -w
 # Tar Wrapper for Amrecover
 # This wrapper escapes all tar wildcards with "\"
 # to allow amrecover to restore files that have "\" 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 '-' ){
     logger "debug", "Option:$opt\n";
   } else {
     logger "debug", "Pre File:$opt\n";
     # Do not escape [], tar seems to accept them without \.
     $opt =~ s/([\\?*])/\\$1/g;
     #Escape the [],too
     #$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;
Personal tools