LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How can I force tar to over-write busy files? (https://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-force-tar-to-over-write-busy-files-732005/)

KenShelby 06-10-2009 01:56 PM

How can I force tar to over-write busy files?
 
I'd like to just blast a tar archive's files down onto a (RHEL 3 update 8) machine and ignore all "text file busy" errors that would prevent writing a file. How can I do that, please?

rweaver 06-10-2009 02:29 PM

Quote:

Originally Posted by KenShelby (Post 3569525)
I'd like to just blast a tar archive's files down onto a (RHEL 3 update 8) machine and ignore all "text file busy" errors that would prevent writing a file. How can I do that, please?

The easiest method is boot into single user mode or alternate shutdown pretty much everything so the files aren't in use.

The alternative is extract it elsewhere and then mv -f or rsync it into place... but that's delving into scary territory. You might want to make sure your basic tools are statically linked before doing that.

KenShelby 06-10-2009 03:45 PM

Quote:

Originally Posted by rweaver (Post 3569564)
The easiest method is boot into single user mode or alternate shutdown pretty much everything so the files aren't in use.

The alternative is extract it elsewhere and then mv -f or rsync it into place... but that's delving into scary territory. You might want to make sure your basic tools are statically linked before doing that.

Thanks very much for the rapid reply!

I've already tried bringing the machine down into single-user mode: no joy.

I have no need whatever for the files that currently exist on the target machine, so it's not really all that scary. :) I need to somehow get tar to simply extract ALL the files. Is there any way to avoid those "text file busy" errors and just write, regardless?

chrism01 06-10-2009 08:03 PM

Which files are causing a problem?
If(!) they are still in use in single user mode, makes them pretty vital...
You could try using a rescue mode CD/DVD, that way (almost?) no files on the hdd are open when you mount it.

KenShelby 06-11-2009 09:31 AM

Quote:

Originally Posted by chrism01 (Post 3569834)
Which files are causing a problem?
If(!) they are still in use in single user mode, makes them pretty vital...
You could try using a rescue mode CD/DVD, that way (almost?) no files on the hdd are open when you mount it.

Thanks for the input!

But I have *absolutely* no need to preserve the files that are currently on the target machine. And the target box has no CD/DVD drive, so I'm getting my tar archives there via ftp.

The simplest solution would be to force tar to over-write ALL the files and ignore the "text file busy" errors. Is there no way to do this?

KenShelby 06-12-2009 10:56 AM

This is a snippet of the Korn script I'm now testing, for each of the tar archives I have...


"...
tar --extract --verbose --overwrite --same-owner --preserve-permissions \
--gunzip --file ${LocalDir}/${Tarfile} 1>>${LocalDir}/update.log 2>>${LocalDir}/tar-errors.txt
ReturnStatus="$?"
if [[ "$ReturnStatus" != "0" ]] ; then
grep -i 'file busy' ${LocalDir}/tar-errors.txt |\
awk '{print $2}' | \
tr ':' ' ' | \
awk '{print $1}' | \
while read BusyFile
do
if [[ ! -z "$BusyFile" ]] ; then
echo "Extracting with unlink: $BusyFile" >>${LocalDir}/update.log
tar --extract --verbose --unlink-first --same-owner --preserve-permissions \
--gunzip --file ${LocalDir}/${Tarfile} ${BusyFile} 1>>${LocalDir}/update.log
fi
done
fi
sync
..."

KenShelby 06-15-2009 09:49 AM

Well, that was a bad idea. Using the "--unlink-first" switch of tar only got me into more trouble when it ran into a place with softlinks pointing at real files that were busy, for example, in the "/lib/tls" directory. Dropping the files into a temporary area and using a forced move ("mv -f") failed, too.

Is there no-one out there in Linuxquestionsland who knows how I can simply over-write every single file on a machine with files from a tar archive?

rweaver 06-15-2009 12:41 PM

Quote:

Originally Posted by KenShelby (Post 3574513)
Well, that was a bad idea. Using the "--unlink-first" switch of tar only got me into more trouble when it ran into a place with softlinks pointing at real files that were busy, for example, in the "/lib/tls" directory. Dropping the files into a temporary area and using a forced move ("mv -f") failed, too.

Is there no-one out there in Linuxquestionsland who knows how I can simply over-write every single file on a machine with files from a tar archive?

I've never done it with tar (forced overwrite) but if a mv -f fails... you've got something else going on you need to look into.

I doubt this will work if mv -f didn't but try untaring them somewhere else and rsyncing them over the current system.

chrism01 06-15-2009 08:47 PM

You still haven't told us which files these are. Just because you don't think you need to worry, doesn't mean the system agrees.
If they're busy, it means they are open and being used. You need to shutdown the relevant process first, then untar.

KenShelby 06-16-2009 01:10 PM

Thanks once more for the input, but I really do not care at all about the files that are on the machine currently. As I said at the top, all I want to do is "...blast a tar archive's files down onto a machine..."

Is there really no way to do this?

rweaver 06-16-2009 02:45 PM

Quote:

Originally Posted by KenShelby (Post 3576170)
Is there really no way to do this?

I've rsync'd over live machines in the past... you just need to exclude certain 'special' items, like /dev, /proc, etc. You can't do a force overwrite on some locations.

If mv -f is failing, please tell us what file you're attempting to overwrite that is failing and we might be able to tell you why, at this point we can't help you any further without additional information.

KenShelby 06-17-2009 09:41 AM

Thanks, one and all, for your replies.

I'm going to try a different approach (in a new thread) to my basic problem, which is installing a new O/S and applications on a machine that has no CD/DVD or floppy and cannot boot from USB.

chrism01 06-17-2009 06:36 PM

If you're using RH, kickstart has a netboot (bootp ?) option


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