Operating System - HP-UX
1752423 Members
4722 Online
108788 Solutions
New Discussion юеВ

Corrupted Files when used tar command

 
Adrianne Hoang
Occasional Advisor

Corrupted Files when used tar command

Hello,

In my production line I typed:

u ;tar -cvf - . | (cd /u.sav ; tar -xvf -)

I did it under root and all the files in /etc got over written, SAM got corrupted, and vmunix got corrupted as well. Could you tell me why it is doing this?

Please advise,
Adrianne
5 REPLIES 5
Mark Fenton
Esteemed Contributor

Re: Corrupted Files when used tar command

looks like we're missing a few pieces at the start of your command line:

mayhap it should have read

cd u ; tar cvf - .| (cd /u.sav ; tar xvf - )

which in my testing works fine.

if both the first and second cd failed, then you're trying to write the entire contents of your drive from wherever you currently are to wherever you currently are, which will probably result in the corruption you saw.

Why would the cd operations fail? The first directory u wasn't in the current directory (ie you were in / and u is actually under /tmp or some such) -- ditto for /u.sav -- if it is truly under / then fine, otherwise you need the full path to be safe.

hth
Mark
Adrianne Hoang
Occasional Advisor

Re: Corrupted Files when used tar command

We have to restore /etc from the backup and copy the /stand/build/vmunix_test to /stand/vmunix. It was a horrible experience. Anyhow, we are making Ignite tape and run a full backup before we are rebooting.

Keep your finger crossed.

Thanks,
Adrianne
Mark Fenton
Esteemed Contributor

Re: Corrupted Files when used tar command

does sound ugly.

Hope not too much was lost between backup and restore. Last time I had to restore a production server from backup we lost about 23 employees work for most of a day (yikes!).

James R. Ferguson
Acclaimed Contributor

Re: Corrupted Files when used tar command

Hi Andranne:

You can protect yourself in situations like this by *only* performing the operation if the 'cd' is successful, thusly:

# ( cd /u && tar -cvf - . ) | ( cd /u.sav && tar -xvf - )

...Now, if either change-directory fails, nothing happens.

Regards!

...JRF...
Adrianne Hoang
Occasional Advisor

Re: Corrupted Files when used tar command

Thank you for all your help.

Adrianne