cancel
Showing results for 
Search instead for 
Did you mean: 

The tar utility

SOLVED
Go to solution
rustam_2
Super Advisor

The tar utility

Hi all,
These days i'm doing cold backup of my database and i need free space for 2 weeks. There are a lot files and have uses big size. Can i archive them? I looked for and found that tar can help me. I read this article about tar utility - http://docs.hp.com/en/B2355-60105/tar.1.html

should i do like these for archiving file1, file2 etc?

$tar cvf /tmp/my_directory file1 file2 fileN?

and how can i rearchive them?

Best regards,
Rustam,
11 REPLIES
rariasn
Honored Contributor

Re: The tar utility

Hi rustam,

http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=102710


WARNINGS
Because of industry standards and interoperability goals, tar does not
support the archival of files larger than 8GB or files that have user/group IDs greater than 2048k. Files with user/group IDs greater than 2048k are archived and restored under the user/group ID of the
current process, unless the uname/gname exists (see tar(4)).

1.- Firs day

# tar cvf file.tar file1 file2

2.- Second day

# tar uvf file.tar file1

# tar tvf file.tar

rw------- 0/3 16 Jul 8 11:24 2010 ./file1.txt
rw------- 0/3 14 Jul 8 11:24 2010 ./file2.txt
rw------- 0/3 32 Jul 8 11:24 2010 ./file1.txt

3.- recover file

tar xvf file.tar ./file2.txt

rgs,





rgs,
Amit Chaurasia
Occasional Advisor

Re: The tar utility

Unless you have specific requirement, I guess archiving the whole directory makes sense.

For Eg: you wish to back /data

# tar -cvf data-.tar /data
James R. Ferguson
Acclaimed Contributor

Re: The tar utility

Hi Rustam:

If you are concerned about files larger than 8GB, you will need to use 'pax' [with the '-x pax' format specification; use 'fbackup'/'frecover'; or use another product like Data Protector.

Regards!

...JRF...
rustam_2
Super Advisor

Re: The tar utility

Hi and thanks, rariasn, Amit, ...JRF...
1. my file size was:
... 5396217435 Jun 29 20:51 exp_full.dmp
i run
$ tar cvf file_test.tar exp_full.dmp
and it became
... 5396224000 Jul 9 10:03 file_test.tar
why? file created but size more than source file?
2. # tar uvf file.tar file1 - is this command added in tar file new file1 for being archived?
3. #tar xvf file.tar ./file2.txt - this command extracts file file2.txt from archive set file.tar?
4. and this one shows all file in tar set - # tar tvf file.tar ?
5. # tar -cvf data-.tar /data -- thanks, good idea to put day automatically instead create folder by myself.
6. ...JRF...-- my files havent larger than 8GB, yet. But think in few months they will. Could you give me a list of example of using pax?

Best regards,
Rustam


muruganantham raju
Valued Contributor
Solution

Re: The tar utility

Hi Rustam,

Answers are inline.

1. my file size was:
... 5396217435 Jun 29 20:51 exp_full.dmp
i run
$ tar cvf file_test.tar exp_full.dmp
and it became
... 5396224000 Jul 9 10:03 file_test.tar
why? file created but size more than source file?

ANS: The tar command writes data in blocks of 512 bytes in length. Hence the file length is rounded up to multiple of 512 byte and extra zeros are added to fill the length. Thus you see the tar package size more than the source file.

If you want to compress the tar package, then use gzip command.
For e.g. the following cmd creates file_test.tar.gz much compressed than original source file.
gzip file_test.tar # To compress
gunzip file_test.tar.gz # To uncompress

2. # tar uvf file.tar file1 - is this command added in tar file new file1 for being archived?

ANS: Yes. Following is the snippet from man tar
u option Add any named file to the archive if it is not already present or has been modified since it was last written in the archive. The same blocking factor used to create the archive must be used to update it.


3. #tar xvf file.tar ./file2.txt - this command extracts file file2.txt from archive set file.tar?

ANS: In a way correct. But you need to specify the whole path used while creating tar package.

For e.g: To extract file a from TEST.tar

# tar -tvf TEST.tar
rwxrwxrwx 0/3 0 Jul 9 13:28 2010 TEST/
rw-rw-rw- 0/3 0 Jul 9 13:28 2010 TEST/a
rw-rw-rw- 0/3 0 Jul 9 13:28 2010 TEST/b
rw-rw-rw- 0/3 0 Jul 9 13:28 2010 TEST/c
rw-rw-rw- 0/3 0 Jul 9 13:28 2010 TEST/d
rw-rw-rw- 0/3 0 Jul 9 13:28 2010 TEST/e

# tar -xvf TEST.tar TEST/a

4. and this one shows all file in tar set - # tar tvf file.tar ?

ANS: YES. you are right.

HTH
Muru
V. Nyga
Honored Contributor

Re: The tar utility

Hi,

1. my file size was:
... 5396217435 Jun 29 20:51 exp_full.dmp
i run
$ tar cvf file_test.tar exp_full.dmp
and it became
... 5396224000 Jul 9 10:03 file_test.tar
why? file created but size more than source file?

That tar - tar stores more information than just the file, so it's a bit greater. You can see this information like an envelope.

BTW. You want MORE space? Then you should use a compress programm like 'compress' or gzip! Tar doesn't compress it only 'archive' data files. The only way to compress with tar is to write it to a tape, where the tape does the compression.

2. # tar uvf file.tar file1 - is this command added in tar file new file1 for being archived?

Yes - see also the manual pages of tar:
'man tar' (or the document you mentioned)

3. #tar xvf file.tar ./file2.txt - this command extracts file file2.txt from archive set file.tar?

like 2.

4. and this one shows all file in tar set - # tar tvf file.tar ?

Yes

As mentioned above, with tar you'll create an additional file, so you don't create free space, but double the space a file needs.
With a tarred archive you can compress it simplier with 'gzip', but then you can't add another file to the archive.

Else you want to write it with tar to a tape ....

HTH
V.

BTW. what's your os?
*** Say 'Thanks' with Kudos ***
Dennis Handly
Acclaimed Contributor

Re: The tar utility

>Could you give me a list of example of using pax?

It's pretty simple it has the best of cpio and tar options:
pax -v -w -f /tmp/my_directory.pax file1 directory2 ...

And -r to read and nothing to list.
rustam_2
Super Advisor

Re: The tar utility

I could run and test all command and itâ s clear for me. Now i can make 1 tar file where i'm putting 1,2,3 ..N file and can do gzip file, which makes size of original source file smaller 10 times. THANK YOU A LOT for everyone!

Except these commands:
# tar -cvf data-.tar /data
I donâ t know why, maybe I got misunderstand of syntaxâ ¦
And this one,
>It's pretty simple it has the best of cpio and tar options:
>pax -v -w -f /tmp/my_directory.pax file1 directory2 ...
Denis, I didnâ t run your command coz my files donâ t have size more than 8Gb. Hope in few weeks it will be useful for me and I can use it.

Thank you, Muru and V,
My OS is HP-UX and version is 11.3


Regards,
Rustam
V. Nyga
Honored Contributor

Re: The tar utility

Hi again,

># tar -cvf data-.tar /data
>I don't know why, maybe I got misunderstand of syntax

There's no syntax :-)
just a suggestion.

You have to define a variable first:

set DATUM=`date +%y%m%d`
Then you can use:
# tar -cvf data-$DATUM.tar /data
(This is in csh-shell)

HTH
V.
*** Say 'Thanks' with Kudos ***
Dennis Handly
Acclaimed Contributor

Re: The tar utility

># tar -cvf data-.tar /data
I don't know why, maybe I got misunderstand of syntax

Those were meta chars indicating that you figure out how you want the date. Either manually, or by V. Nyga's variable or you can use $() directly:
tar -cvf data-$(date +%Y%m%d).tar /data

>I didn't run your command coz my files don't have size more than 8Gb.

There is no need to wait. You can stop using tar now and switch to pax. They are compatible until you use "-x pax".
rustam_2
Super Advisor

Re: The tar utility

Thanks a lot, V and Dennis, and other who gave me advice,suggestions and examples.
I could solve and learn how to work with tar utility.

regards,
Rustam