LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   tar hangs after extracting from pipe (https://www.linuxquestions.org/questions/linux-newbie-8/tar-hangs-after-extracting-from-pipe-738328/)

eric_torti 07-07-2009 09:45 AM

tar hangs after extracting from pipe
 
Hello,

I'm making some backup files with predefined sizes for cd storage with the folowing command.

# tar cvPf - /home | gzip v - | split -b 600m - backup.tar.gz.*

This generates a number of files like
backup.tar.gz.aa
backup.tar.gz.ab
backup.tar.gz.ac
... and so on.

Problem is, when I extract from these files with the command

# cat backup.tar.gz.* - | tar xzvPf -

Everything works great, except that, after extracting the files, the prompt hangs. So I have to Ctrl+C to get it back.

I've experimented with tar parameters, but no success so far.

Any help will be greatly appreciated.

System is: Linux version 2.6.18-6-686 (Debian 2.6.18.dfsg.1-23etch1)

Thanks.

Eric

whirler 07-07-2009 12:55 PM

It's been a little while since I've written any shell scripts but would it work to use something like "exit" or "break" to force the script to end after your files are extracted?

eric_torti 07-08-2009 02:00 PM

Curiously it doesn't work.

When I do:

# cat backup.tar.gz.* - | tar xzvPf - && break

or

# cat backup.tar.gz.* - | tar xzvPf - && exit

It just hangs as if exit or break were not there. So I infer that, as the tar command doesn't return the prompt, exit or break are actualy never reached.

On the other hand, when I try:

# cat backup.tar.gz.* - | tar xzvPf - | break

The prompt displays a warning saying that break must be used solely on loops.

And:

# cat backup.tar.gz.* - | tar xzvPf - | exit

The tar process is inerrupted prematurely and not all tared files are extracted.

When I try:

# cat backup.tar.gz.* - | tar xzvPf - > exit

Prompt hangs as if > exit were not even there.

So..

I think I'm running out of options :]

Thank you for the reply, though.

chrism01 07-08-2009 07:27 PM

tar won't know where the end of file is because you split the output.
You could try sorting the list before input, so tar is extracting in the right order.
You could concatenate the files first, before extraction.

I think there are tools that will do all this for you instead of tar.
See the page here http://www.debianhelp.co.uk/backuptools1.htm

norobro 07-08-2009 08:34 PM

Quote:

Originally Posted by eric_torti (Post 3601300)
# cat backup.tar.gz.* - | tar xzvPf - && break

From the cat man page:
Quote:

With no FILE, or when FILE is -, read standard input
Remove the "-" and it should work.
Code:

# cat backup.tar.gz.* | tar xzvPf -
Your cat command is waiting for input from the keyboard (stdin).

eric_torti 07-10-2009 01:43 PM

Quote:

Originally Posted by chrism01 (Post 3601571)
tar won't know where the end of file is because you split the output.
You could try sorting the list before input, so tar is extracting in the right order.
You could concatenate the files first, before extraction.

I think there are tools that will do all this for you instead of tar.
See the page here http://www.debianhelp.co.uk/backuptools1.htm

Hello, chrism01, thank you for the references. I'll have a look at them.

eric_torti 07-10-2009 01:53 PM

Quote:

Originally Posted by norobro (Post 3601627)
From the cat man page:
Remove the "-" and it should work.
Code:

# cat backup.tar.gz.* | tar xzvPf -
Your cat command is waiting for input from the keyboard (stdin).

Hi, norobro, I've tryed the xzvP parameters and tar hangs as well.

The solution I found was adding nohup to the beginning of the command, as in:

# nohup cat test.tar.gz.a* - | tar xzvP

And I got away with a warning:

gzip: stdin: decompression OK, trailing garbage ignored
tar: Child returned status 2
tar: Saída por erro atrasada pelos erros anteriores
(translating last line from portuguese)
tar: Error exit delayed by previous errors

Thank you for your help.

norobro 07-10-2009 02:00 PM

I was referring to the first "-".
Code:

cat backup.tar.gz.* - | tar xzvPf -
Your cat command is piping all of your tar.gz files to tar then the dash is causing cat to wait for input from stdin.

eric_torti 07-11-2009 09:01 AM

Quote:

Originally Posted by norobro (Post 3603644)
I was referring to the first "-".
Code:

cat backup.tar.gz.* - | tar xzvPf -
Your cat command is piping all of your tar.gz files to tar then the dash is causing cat to wait for input from stdin.

Thanks, norobro, you are absolutely right.

Working command is

# cat backup.tar.gz.* | tar xzvP

or

# cat backup.tar.gz.* | tar xzvPf -

Being that the first makes more sense to me.

Thank you.


All times are GMT -5. The time now is 01:37 AM.