Solaris tar command to ignore mount points?

i.e. to stay in local filesytem.

I believe the flag in linux is one-file-system. Is there corresponding in solaris?

SOLARIS 9 BTW.

Depending on your release, there are couple of options.

  1. You can use find -xdev option and feed it to tar utility via pipe and xargs.
    This should be quite portable solution, the internet is full of examples.

  2. On newer releases (11 and on), gnu tar is (probably) installed and can be invoked as gtar .
    Also, other gnu utilities can be invoked with g prefix (gfind gsed ..)

Please, if you ask questions on this forum, you will get much more precise answers by specifying your operating system version and shell you are using.

Hope that helps
Regards
Peasant.

1 Like

As Peasant says, what O/S version exactly?

Talking generic Solaris, you can:

# find /path/to/files | xargs tar cvf archive.tar

or (depending on whether you want to write a relative path to the archive)

 # cd /path/to/files
 # find . | xargs tar cvf archive.tar
 

to pipe 'find' into 'tar'

THEN, to answer your question, restrict the find to the current filesystem only by using the -mount switch on 'find', for example:

# find -mount /path/to/files | xargs tar cvf archive.tar

You may also need to use other switches on 'find' to refine the file selection eg, date/time filters, file type, etc.

Hope that helps, perhaps is doesn't. Which O/S is it????

1 Like

Thanks its solaris 9.

So if I had two mount points /export and /export/home and I only wanted to tar the stuff in export (And subdirectories) but NOT /export/home then find -mount would work?

I think that, assuming you have a root filesystem (/), a /export, and a /export/home all as individual filesystems, then I reckon so.

Basically, look at it like this. The -mount switch restricts 'find' to the filesystem of the directory that you are currently in. Therefore, you would need to:

# cd /export
# find -mount . | xargs tar cvf archive.tar

Give that a go on Solaris 9. Tell me if I'm wrong.

---------- Post updated at 05:10 PM ---------- Previous update was at 05:02 PM ----------

Of course, unless the /export filesystem contains other mount points to lower levels, what I wrote above would just work anyway without the '-mount'. It just creates a relative path backup which can therefore be restored to anywhere on the system you choose (which is good practice).

---------- Post updated at 05:25 PM ---------- Previous update was at 05:10 PM ----------

You could also simply use:

 # cd /export
 # tar cvf archive.tar .
 

if /export has no lower mount points on it.

Just for the sake of argument, -xdev option is in the standards, while -mount is not.

If you take a look at the find manuals from solaris, hpux, aix, linux etc. you will find that -xdev is the common denominator for not traversing filesystems in unix or unix like operating system.

Regards
Peasant.

1 Like

That's true but do you remember whether Solaris 5.9 supports 'find -xdev'?

Yes, sure.
All SysV-derived Unixes have -xdev .

2 Likes

Yes. In the example I use, /export and /export/home have separate mount points. I only want /export (and subdirectories) BUT NOT /export/home.

SO I guess I'll give this a try.

---------- Post updated at 04:15 AM ---------- Previous update was at 02:58 AM ----------

Hmmm. Not working too well.

I think its because the find command finds directory names within the filesystem (like /export/home) but not the files within that directory (because of xdev).

Trouble is that tar then attempts to tar everything in that directory anyway.

Sound about right?

I've run find . -xdev > tarlist and then looked at tarlist and this confirms it. I guess what I need to do is stop tar looking at directory names and tarring the contents.

---------- Post updated at 04:43 AM ---------- Previous update was at 04:15 AM ----------

Hmmm. Was thinking of using

find . -xdev ! -type d

But of course, using my example, you'd lose directories that were empty such as, say /export/1.

Wondering if way forward is to exclude directories based on the "other" mount points?

Of course, if I could get tar not to recurse it'd be fine. Not sure if its possible with solaris though.

find /export -xdev

should not print a mounted /export/home.
--
In principle cpio works better with find.

cd /export && find . -xdev -cpio /tmp/export.cpio

and this cpio archive can be listed with

cpio -idt < /tmp/export.cpio

And extracted to the current directory with

cpio -id < /tmp/export.cpio

Thanks MIG.

Spookily, I got it working with CPIO as you say.