Operating System - HP-UX
1832764 Members
3090 Online
110045 Solutions
New Discussion

File compression to a different dir dynamically

 
SOLVED
Go to solution
HP System Handle Owner
Occasional Advisor

File compression to a different dir dynamically

Can anyone tell me if there is a way of dynamically compressing files to another filesystem using either compress or gzip WITHOUT having to cp the uncompressed file to the target dir first.

i.e

I start with
/mountpoint1/file1.dbf

I want to end up with
/mountpoint1/file1.dbf
and
/mountpoint2/file1.dbf.Z

It is for performing a disk backup, but I do not want to copy the file to mountpoint2 and then compress it. I would like the compression program to read /mountpoint1/file1.dbf as a source and create /mountpoint2/file1.dbf.Z as an archive in it's compressed size leaving /mountpoint1/file1.dbf intact.

Thanks in advance

Russ

We are running 10.20
Not another questionnaire !!
19 REPLIES 19
John Carr_2
Honored Contributor

Re: File compression to a different dir dynamically



cd /newfile_system

compress /explicit_path/filename

this should put the compressed file into the directory you are located in when you run the command , I cant test this at moment but you could with some small file :-) John.
Robert-Jan Goossens
Honored Contributor

Re: File compression to a different dir dynamically

Hi

Take a look at this thread, and the answer from Kenneth Platz.

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=3212

Regards,
Robert-Jan
Pete Randall
Outstanding Contributor
Solution

Re: File compression to a different dir dynamically

Russ,

From looking at the man page, it appears that gzip will do what you require:

gzip -c /mountpoint1/file1.dbf > /mountpoint2/file1.dbf.Z

I would suggest trying a little test scenario first.


Pete

Pete
Mark Grant
Honored Contributor

Re: File compression to a different dir dynamically

Using the "-c" switch with "gunzip" causes output to go to the standard output so you can do "gzip -c myfile > /somewhere/else/completely/newfile.z"

Never preceed any demonstration with anything more predictive than "watch this"
John Palmer
Honored Contributor

Re: File compression to a different dir dynamically

gzip -c /mountpoint1/file1.dbf > /mountpoint2/file1.dbf.gz

As you are talking about database files, be aware that the 'standard' gzip doesn't handle files > 2Gb though.

Regards,
John
Jean-Louis Phelix
Honored Contributor

Re: File compression to a different dir dynamically

Hi,

I confirm what Pete wrote ... You can even read from standard input to be sure that compress will not open your file directly :

cat /mountpoint1/file1.dbf | compress > /mountpoint2/file1.dbf.Z


Regards
It works for me (© Bill McNAMARA ...)
John Carr_2
Honored Contributor

Re: File compression to a different dir dynamically

Hi

you can use -c option with compress command as well as gzip :-) John.
Massimo Bianchi
Honored Contributor

Re: File compression to a different dir dynamically

why not

gzip -9 -c /ABSOLUTE/filename > /ABSOLUTE/BACKUP/filename.gz

HP System Handle Owner
Occasional Advisor

Re: File compression to a different dir dynamically

We do have source files over 2Gb. Does this mean using compress ?

I guess it discounts gzip. We only have standard gzip

Cheers

Russ
Not another questionnaire !!
Pete Randall
Outstanding Contributor

Re: File compression to a different dir dynamically

Russ,

Get the gnu version:

http://hpux.cs.utah.edu/hppd/hpux/Gnu/gzip-1.3.5/


Pete

Pete
Mark Grant
Honored Contributor

Re: File compression to a different dir dynamically

Actually, I believe that modern gzip >= version 1.3 does support files larger than 2GB.
Never preceed any demonstration with anything more predictive than "watch this"
Massimo Bianchi
Honored Contributor

Re: File compression to a different dir dynamically

With standard unix utilities you can do the following:


mkdir /tmp/pipe p

dd if=/tmp/pipe of=/ABSOLUTE/BACKUP/filename.gz

gzip -9 -c /ABSOLUTE/filename > /tmp/pipe


Massimo
Mark Grant
Honored Contributor

Re: File compression to a different dir dynamically

Did you perhaps mean "mknod" and not "mkdir" there Massimo :)
Never preceed any demonstration with anything more predictive than "watch this"
Massimo Bianchi
Honored Contributor

Re: File compression to a different dir dynamically

geee... looks like i must stop writing while sleeping :)

Thanks for the correction!

Massimo
Steve Lewis
Honored Contributor

Re: File compression to a different dir dynamically


If you cat the file and pipe it to gzip or compress, then redirect the standard output to the destination, you avoid large file problems.

cat dbfile.dbf | gzip > /backup_dir/dbfile.dbf.gz

[ I think they really meant mkfifo, which can be used in conjunction with gzip/compress and tar to copy compressed versions of big files from a remote system. If you want to be really flash, you can use a named pipe as an archive device file for your database. ]
Mark Grant
Honored Contributor

Re: File compression to a different dir dynamically

Actually Steve,

Massimo's mkdir/mknod tempory mind block is creating a named pipe. "mknod" is the way to create such niceties :)
Never preceed any demonstration with anything more predictive than "watch this"
Patrick Wallek
Honored Contributor

Re: File compression to a different dir dynamically

The following will also work:

# gzip < /dir/inputfile > /dir/outputfile.gz
Steve Lewis
Honored Contributor

Re: File compression to a different dir dynamically

... quickly looks at mknod man page... so it is! Well I never knew that. Thank you for pointing that out.
/usr/bin/mkfifo appears to be a specific subset of /usr/sbin/mknod that anybody can run, not just the super-user.
Steve Lewis
Honored Contributor

Re: File compression to a different dir dynamically

Actually i screwed up again, it lets anyone mknod filename p , 0 points today again I think.