Showing posts with label directory exclusion. Show all posts
Showing posts with label directory exclusion. Show all posts

Saturday, February 9, 2008

Excluding Directories using tar on Solaris

Moving an application from one directory to another or to another machine, I've simply used tar and been on my way. A few back up shell scripts and temporary files did not matter. Simply tar, gzip and then reverse the sequence at the target directory.

This time, the application creates hundreds of temporary sql, srt and ctl files in one of its temp directories. And that was a serious bloat on the code size.

Get them removed, keep the directory structure and plug them on to another machine was the order. tar give -X option.

tar cvfX temp.txt b_proc_and_load.tar ./load

That didn't work.

Reread the manual. Still doesn't work.


Let's break this down.

1. How do I get a list of files to exclude?
That is easy, you use find, like so

find ./p/bin/temp -print |sed '1,1d' > /tmp/exclusion.list
find ./p/m/data -print |sed '1,1d' >> /tmp/exclusion.list

you delete the first line using sed because you want to preserve
the directory structure but not have any files within. The first
line output of the find command is the directory path name.

2. Work out the command to use the exclusion list.
Well, this took some time till it was mentioned that the arguments
and flag order are important. Finally got it working and it
turned out to be

tar cvfX ../b_proc_and_load.tar /tmp/exclusion.list . (note the
period at the end)

Also notice that the created archive is one level higher? So that, it
does not come in the archive too. Though Solaris tar warns you about

Thus endth the lesson on excluding directories using tar on Solaris.