Showing posts with label tar. Show all posts
Showing posts with label tar. Show all posts

Monday, March 17, 2014

Stuck in tar

I have a tarball AcmeScripts-1.26-scripts.tar.gz containing a subfolder:

tar tvzf AcmeScripts-1.26-scripts.tar.gz

drwxr-xr-x 508/100           0 2014-03-11 12:21 AcmeScripts-1.26/jms/
drwxr-xr-x 508/100           0 2014-03-11 12:21 AcmeScripts-1.26/logs/


(i.e. all the content is under AcmeScripts-1.26)

This is bloody maven who packages my scripts this way, no clue why.

When I untar the tarball, I want to get rid of the AcmeScripts-1.26 subfolder, and untar all the content in a /opt/oracle/acmescripts/ folder (without having a /opt/oracle/acmescripts/AcmeScripts-1.26/ )
I have tried everything, but all attempt failed.

This untars under /opt/oracle/acmescripts/AcmeScripts-1.26/:
tar xvzf AcmeScripts-1.26-scripts.tar.gz -C /opt/oracle/acmescripts/ AcmeScripts-1.26/*

this does the same:

tar xvzf AcmeScripts-1.26-scripts.tar.gz -C /opt/oracle/acmescripts/

There doesn't seem to be an option to untar the content of AcmeScripts-1.26-scripts.tar.gz/AcmeScripts-1.26/* directly to /opt/oracle/acmescripts/. I need to do it in 2 additional steps:

mv /opt/oracle/acmescripts/AcmeScripts-1.26/* /opt/oracle/acmescripts/
rmdir /opt/oracle/acmescripts/AcmeScripts-1.26/


Which I don't find ideal. I would rather have something like

tar xvzf AcmeScripts-1.26-scripts.tar.gz -C /opt/oracle/acmescripts/ -D AcmeScripts-1.26/

(don't try it, the -D option doesn't exist)

The workaround is to simply deploy  the scripts to /opt/oracle/acmescripts_staging/AcmeScripts-1.26, and then create a symbolic link between /opt/oracle/acmescripts_staging/AcmeScripts-1.26 and /opt/oracle/acmescripts/ :

ln -s /opt/oracle/acmescripts_staging/AcmeScripts-1.26  /opt/oracle/acmescripts/

Of course when you deploy a new version of the scripts, you have to:
a) remove the previous link
b) remove /opt/oracle/acmescripts_staging/AcmeScripts-1.26
c) create the new link 
ln -s /opt/oracle/acmescripts_staging/AcmeScripts-1.27  /opt/oracle/acmescripts/

which requires some coordination and making sure it all fits together. Not all that simple.

I am a bit disappointed by tar, I always found it a underdesigned utility.




(this must be some La Brea tar pit ad)



Friday, November 8, 2013

tar gzip exclude folder

Rule n.1:

never run tar inside the same folder you are tarring: tar will include the tar-file that it's creating... CRAZY!

Rule n. 2:

--exclude works only if it's the first parameter after tar... IN SOME versions of tar ONLY.... CRAZY!
in my version it has to come last.
cd /opt/oracle/backups
tar cvzf osbpr1dobackup11Nov2013_108.tar.gz /opt/oracle/domains/osbpr1do/ --exclude="shared/store/jms"


Rule n. 3:

if the exclude folder ends in /, tar will ignore it without warning.... CRAZY!

Rule n. 4:

The exclude parameter shoule be relative to the -C path:

this is good:

tar cvzf /opt/oracle/backups/deleteme.tar.gz -C /opt/oracle/bin/ . --exclude="src"

this is bad:

tar cvzf /opt/oracle/backups/deleteme.tar.gz -C /opt/oracle/bin/ . --exclude="/opt/oracle/bin/src"

That's why I never use tar but rather jar.

Saturday, July 31, 2010

Bash shell tricks

Tarring files recursively with filter

to create:
find . -name *.out | xargs tar cvf cohservernodes.tar

to append:
find . -name *.log | xargs tar rvf cohservernodes.tar

to list:
tar tf cohservernodes.tar


Find a text in files, recursively:

find . | xargs grep -s whatever



find and replace recursively

for file in $(grep -il "whatever" *.txt)
do
sed -e "s/Hello/Goodbye/ig" $file > /tmp/tempfile.tmp
mv /tmp/tempfile.tmp $file
done

how about:

perl -p -i -e 's/oldstring/newstring/g' `find ./ -name *.html`

the above command works very well, but if you try

perl -p -i -e 's/oldstring/newstring/g' `find ./ -name *`

you get the error:

Can't do inplace edit: bla is not a regular file, <> line

because it tries to change also the directories

To do a find excluding directories you must do this (add -type f):

perl -p -i -e 's/oldstring/newstring/g' `find ./ -name * -type f`