1

I have used Percona XtraBackup to create a compressed backup, but now I need to decompress the files. The instructions say I should run:

for bf in `find . -iname "*\.qp"`; do qpress -d $bf $(dirname $bf) && rm $bf; done

but this looks like it is going to search everywhere and decompress any files it finds. I only want it to only decompress the files in one specific directory and its subdirectories.

I tried running:

for bf in `find . -iname "/path/to/my/directory/*.qp"`; do qpress -d $bf $(dirname $bf) && rm $bf; done

But this gave the error:

find: warning: Unix filenames usually don't contain slashes (though pathnames do).  
That means that '-iname `/path/to/my/directory/*.qp'' will probably evaluate to false all the time on this system.  

How can I do this?

2

2 Answers 2

2
for bf in `find . -iname "*\.qp"`; do qpress -d $bf $(dirname $bf) && rm $bf; done

for bf in `find . -iname "/path/to/my/directory/*.qp"`; do qpress -d $bf $(dirname $bf) && rm $bf; done

Both of these commands have a number of problems. Most obviously, they fail to handle unusual filenames, both by looping over the output of find and by failing to quote variables.

Then, of course, there's the fact that a filename will never contain a slash, as noted in the error you got.


What you want is:

find /path/to/my/directory -type f -iname '*.qp' -exec sh -c 'for f in "$@"; do qpress -d "$f" "$(dirname "$f")" && rm "$f"; done' find-sh {} +

Or, an alternate version with line breaks:

find /path/to/my/directory -type f -iname '*.qp' -exec sh -c '
  for f
  do
    qpress -d "$f" "${f%/*}" &&
      rm "$f"
  done' find-sh {} +

Further reading:

1
  • cheers for that, as a bit of a Linux newbie there's a lot of very useful information there. It'l take a while for me to fully digest it though. . .
    – IGGt
    Nov 8, 2016 at 11:55
1

The error tell you where is the error. No filenames ending with /directory/*.qp exists. The -iname parameter is about proper file name, not path.

So you should precede the command with cd /path/to/my/directory/ or write the find command as find /path/to/my/directory/ -iname "*.qp" which is what you want: starting from that directory, check all filename matching the *.qp.

1
  • cheers, that makes more sense now.
    – IGGt
    Nov 7, 2016 at 15:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .