Link to home
Create AccountLog in
Avatar of Shamsul Kamal
Shamsul Kamal

asked on

How to copy a file on the fly from GUNZIP and TAR backup file ?

Hi,

I would like to request an assistant.

I have the following backup file :

/backup/cpbackup/daily/server2.tar.gz

Inside the server2.tar.gz backup file , having the following structure :

/server2/homedir.tar

Inside the homedir.tar, having the following structure :

/public_html/index.html

May i know how to copy the "index.html" file located in the homedir.tar inside the server2.tar.gz ?

I have tried the following command , but no luck :

zcat server2.tar.gz|tar -xvf homedir.tar|/bin/cp -f ./public_html/index.html /home/server2/public_html/index.html

The error are as follows :

tar: homedir.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now

Appreciates if anybody can help me on this.

Thanks.



Avatar of Harisha M G
Harisha M G
Flag of India image

Try this:
tar xzf server2.tar.gz && tar xf server2/homedir.tar && cp server2/homedir/public_html/index.html .

Open in new window

SOLUTION
Avatar of Harisha M G
Harisha M G
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
gunzip -c /backup/cpbackup/daily/server2.tar.gz | tar -O -xf - /server2/homedir.tar | tar -xf - /public_html/index.html

wmp

 
Avatar of Shamsul Kamal
Shamsul Kamal

ASKER

Hi woolmilkporc,

May i know how to copy the index.html into certain folder based on your command ?

Thanks .

gunzip -c /backup/cpbackup/daily/server2.tar.gz | tar -O -xf - /server2/homedir.tar | tar -O -xf - /public_html/index.html | cat > /certain/folder/index.html
If your "tar" supports "-z"

tar -O -xzf /backup/cpbackup/daily/server2.tar.gz /server2/homedir.tar | tar -O -xf - /public_html/index.html | cat > /certain/folder/index.html

wmp
Hi Woolmilkporc ,

I tried the following :

tar -O -xzf /backup/cpbackup/daily/server2.tar.gz /server2/homedir.tar | tar -O -xf - /public_html/index.html | cat > /home/server2/public_html/index.html

Get the following error :

tar: /server2/homedir.tar: Not found in archive
tar: Error exit delayed from previous errors
tar: This does not look like a tar archive
tar: /public_html/index.html: Not found in archive
tar: Error exit delayed from previous errors

I can confirm that the server2/homedir.tar is exist in the archive ...

 

You have to modify it like this (note that - is not needed for options):
tar Oxzf /backup/cpbackup/daily/server2.tar.gz server2/homedir.tar | tar Oxf - /public_html/index.html | cat > /home/server2/public_html/index.html

Open in new window

Sorry.. like this (there shouldn't be any absolute path references to /):
tar Oxzf /backup/cpbackup/daily/server2.tar.gz server2/homedir.tar | tar Oxf - public_html/index.html | cat > /home/server2/public_html/index.html

Open in new window

If it's server2/homedir.tar and not /server2/homedir.tar as you posted you must of course omit the leading slash!
Generally: For extracting use exactly the same filenames as you used during archiving! If in doubt perform a "tar -tvf ..." beforehand!
I suspect that it's also public_/html/index.html and not /public_html/... !
Hi,

I ran the following with errors :

root@svr27 [/backup/cpbackup/daily]# tar Oxzf /backup/cpbackup/daily/server2.tar.gz server2/homedir.tar | tar Oxf public_html/index.html | cat > /home/server2/public_html/index.html
tar: This does not look like a tar archive
tar: Error exit delayed from previous errors

Can you help to spot where is the problem ?
The second tar must have -Oxf -
The minus sign means "extract from stdin"

wmp
I meant the minus sign following the "f", in case this was not quite clear!
New error :

root@svr27 [/backup/cpbackup/daily]# tar Oxzf /backup/cpbackup/daily/server2.tar.gz server2/homedir.tar | tar -Oxf - public_html/index.html | cat > /home/server2/public_html/index.html

tar: public_html/index.html: Not found in archive
tar: Error exit delayed from previous errors

Anyway to check ?
tar Oxzf /backup/cpbackup/daily/server2.tar.gz server2/homedir.tar | tar -tvf -

This way you can check the contents of servers/homedir.tar!

Hi,

When i ran :

tar Oxzf /backup/cpbackup/daily/server2.tar.gz server2/homedir.tar | tar -tvf -

Yes, its there :

-rw-r--r-- server2/server2    84 2010-12-05 16:19:31 ./public_html/index.html

May i know why the previous command won't work ?

ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Did it work now? Do you need more help?

wmp
It works now ..thanks.