Hpux find tar gzip

Hello,

I will like to execute a find, tar & gzip in one command.

 find * -type f -mtime -$nb_days -print | xargs tar -cvf  $MAITUT/BCK_DATA.tar 
gzip $MAITUT/BCK_DATA.tar.gz 

The fact that the TAR is very big, at the end I need to generate only a compress file.

Please note that the option z or -T on the tar are not available.

thanks

What keeps you from just piping tar 's stdout into gzip ?

1 Like

thank you for your answer.

I'm a HP MPE guy's.. I'm just starting with Unix. I'm not really understand when you said pipe in stdout.

Is it possible to have an example ?

Merci

Je vous en prie.

You already used a pipe in your sample. Try (untested, may need further polishing)

find * -type f -mtime -$nb_days -print | xargs tar -cv | gzip > $MAITUT/BCK_DATA.tar.gz
1 Like

Thanks,

I tries and gave me the error :

tar: cannot open /dev/rmt/0m

Hmmm - would adding -f- (i.e. write to stdout) help?

I tried with the f and have no errors..

the command that I used :

find * -type f -mtime -365 -print | xargs tar -cvf | gzip > $MAITUT/BCK_DATA.tar.gz

Maybe I've not understand where to put the -f ?

It showed me on the screen all files selected by the Find command.

At the end when I did a ll of my gzip file it seems that it has nothing in :

-rw-rw-r-- 1 maitdev mait 20 Aug 5 10:19 /umaitdevapp/home/maitdev/tmp/BCK_DATA.tar.gz

and when I used : gzip -dc < $MAITUT/BCK_DATA.tar.gz | tar -xvf -
I've got the error : Tar: blocksize = 0; broken pipe ?

Seems that the result does not go into the gzip file.

thanks

Does the tar without gzip contain anything?

1 Like
find * -type f -mtime -$nb_days -print | xargs tar cf - | gzip > $MAITUT/BCK_DATA.tar.gz

Maybe the following works as well (and handles special characters in filenames better)

find * -type f -mtime -$nb_days -exec tar cf - {} + | gzip > $MAITUT/BCK_DATA.tar.gz

Both methods will fail if there are too many files: a second tar is invoked that certainly obscures the tar file.

1 Like

These options will struggle with too many filenames because xargs will produce multiple commands from the list. The command xargs (as I understand it) will take the input list and try to make a single command line from the options given using the input as described or as the final part of the line by default. If the line is going to exceed the maximum command length, then xargs will loop on the command with the remaining input.

With a tar this could be disastrous because the potential multiple tar commands would not be able to be disentangled if you needed to read it back.

If this was AIX, I would recommend writing the names of the required items into a temporary file and passing that with the -L flag, but I'm not sure that HP-UX or anything else supports that. Solaris might use -I (capital i) instead. You would have to read the manual page and look for a flag to accept a list or input file.

Could you consider cpio or other tools instead?

Robin

1 Like

hello
you can use this code:

find * -type f -mtime -$nb_days -print -exec tar cvf {} \; && bzip2 *.tar
1 Like

Looking at Rudi's

find * -type f -mtime -$nb_days -print | xargs tar cf - | gzip > $MAITUT/BCK_DATA.tar.gz

I would say xarg is useless and will give you trouble and is maybe what is upsetinf you from the beginning
Im quite sure

find * -type f -mtime -$nb_days -print |  tar -cvf - | gzip > $MAITUT/BCK_DATA.tar.gz

should work but I have no HP-UX or any unix to give try at the moment...

1 Like

Hmmm - isn't it that tar expects the files to create an archive from on the command line? Doesn't it use stdin only when extracting from a data stream?

So xargs WOULD be needed to supply the file names coming from find on stdin as parameters on the command line to tar .

Above proposal yields

tar: no files or directories specified

on FreeBSD, and

tar: Cowardly refusing to create an empty archive

on my linux machine.

1 Like

tar: Under linux you can use -T - to read filenames from stdin.

Pack:

find /path -type f | tar -T - -cf - | gzip >file.tar.gz

Unpack:

gzip -dc file.tar.gz | tar -xf -

I doubt that HP-UX tar already has this option. But maybe. I recommend cpio as the better option here too, because it's designed right from start to work with files from stdin.

tar -cvf has not argument for -f. What was recommended to you is this command(dash at the end): tar -cvf -

First,
Thanks to all to take times to answer me.

I tried all commands that I received and only one works properly for me. (at least, a GZIP file is created.) I will verify the contains.

Below the 3 tests that I did :

test 1 ==> seems to work well

find * -type f -mtime -100 -exec tar cf - {} + | gzip > $MAITUT/BCK_DATA.tar.gz

Result :

-rw-rw-r-- 1 maitdev mait 290757296 Aug 8 09:04 BCK_DATA.tar.gz
find * -type f -mtime -2 -exec tar cf - {} + | gzip > $MAITUT/BCK_DATA.tar.gz

result :

-rw-rw-r-- 1 maitdev mait 7876 Aug 8 09:12 BCK_DATA.tar.gz

test 2

find * -type f -mtime -900 -print | tar -cvf - | gzip > $MAITUT/BCK_DATA.tar.gz

Result :

Attempt to create archive of no files. Nothing dumped.

test 3

find * -type f -mtime -900 -print -exec tar cvf {} \; && bzip2 *.tar

result :

4fa056a8
Attempt to create archive of no files. Nothing dumped.
ARCNEWLD.dat
Attempt to create archive of no files. Nothing dumped.
ARCNEWLD.idx
Attempt to create archive of no files. Nothing dumped.
ARCNEWLD.sfd

etc.. same error on each files reported.

again, thanks to all

 find * -type f -mtime -100 -exec tar cf - {} + | gzip > $MAITUT/BCK_DATA.tar.gz

As stated from others here: The above command will break when there are too many files found.

This is an alternative with cpio:

Backup

find * -type f -mtime -100 | cpio -o --format=crc | gzip >file.cpio.gz

Examine

gzip -dc file.cpio.gz | cpio -itv 

Restore

gzip -dc file.cpio.gz | cpio -i --make-directories 
1 Like

I just tried the new command above and got the error :

find * -type f -mtime -100 | cpio -o --format=crc | gzip >file.cpio.gz
  
cpio: illegal option -- -
cpio: illegal option -- =
Usage: cpio -o[aAcBvxCh] [-e warn|force|ignore] <name-list >collection
       cpio -i[BcdmPrtuvfsSbx6RU] [pattern ...] <collection
       cpio -p[adlmruvxU] [-e warn|force|ignore] directory <name-list

ok. Seems your cpio does not understand --format=crc. Just leave that option out. --make-directories is not understood either.

1 Like

Hi.

On a system I sometimes use:

OS, ker|rel, machine: HP-UX, B.11.11, 9000/785
Distribution        : GenericSysName [HP Release B.11.11] (see /etc/issue)
/bin/tar - ( /bin/tar May 23 2007 )
/usr/bin/tar - ( /usr/bin/tar May 23 2007 )
/usr/local/bin/tar tar (GNU tar) 1.26

I see that GNU tar is available in /usr/local/bin.

It may be worthwhile to see if GNU tar is available on your system.

Best wishes ... cheers, drl

1 Like

Thank you so much everyone.

I used the command below and works fine.

code :

find * -type f -mtime -$nb_days | cpio -o | gzip >$MAITUT/BCK_DATA.cpio.gz

to extract :

gzip -dc $MAITUT/BCK_DATA.cpio.gz  | cpio -imd