1831185 Members
3134 Online
110021 Solutions
New Discussion

Re: tar command

 
SOLVED
Go to solution
Ragni Singh
Super Advisor

tar command

hey all, how would I specify on the comand line if I'm in my home dir but I need to tar up stuff from / down. Points will be given and thanks for your time.
10 REPLIES 10
Stefan Farrelly
Honored Contributor

Re: tar command

tar cvf /
Im from Palmerston North, New Zealand, but somehow ended up in London...
Ken Hubnik_2
Honored Contributor

Re: tar command

tar cvf anyfilename /
Helen French
Honored Contributor

Re: tar command

If I understood your question correctly, then:

# tar -cvf /dev/rmt/0m /

You can replace /dev/rmt/0m with any other file name too.
Life is a promise, fulfill it!
Armin Feller
Honored Contributor

Re: tar command

Hi,

if you want to restore absolute TAR or CPIO archive to relative directory you have to use PAX.

Please see:
# man pax

e.g.
# cd $HOME
# pax -r -s ',^/,,' -f /dev/rmt/0m -t

Regards ...
Armin
A. Clay Stephenson
Acclaimed Contributor

Re: tar command

tr cvf /dev/rmt/3m (or whatever) /

The bad news is that all files will have an absolute path which will make restoring files to other locations difficult. My preference would be

HERE=$(pwd)
cd /
tar cvf /dev/rmt/3m .
cd ${HERE}

so that everything is tar'ed with relative paths and then restores to / or to another location are trivially easy.
If it ain't broke, I can fix that.
Vincent Fleming
Honored Contributor

Re: tar command

tar cvf

For example:

tar cvf /dev/rmt/0m /etc


When you specify a full path name from root for the directory (ie: it stars with /), it will do what you want.

Good luck!

Vince
No matter where you go, there you are.
Ragni Singh
Super Advisor

Re: tar command

I'm trying to set this up in cron to tar up everything on my linux server, ssh to a unix tape drive and then untar it. I tried to do this but not sure if ths will work.

tar -cf - / | ssh hostname dd of=/dev/rmt/0m
Vincent Fleming
Honored Contributor
Solution

Re: tar command

It looks good to me.
No matter where you go, there you are.
Ian Dennison_1
Honored Contributor

Re: tar command

Sanjay,

If I understand your question correctly, you want to tar up an archive containing files in a directory other than the one you are in right now.

eg.
cd /home/root
tar -cvf /tmp/test.tar /home/bob

This will work, however when extracting it will recreate the directory structure relative to where you are (Reference many, many ITRC Forums postings on this issue).

If you don't want this, but don't want to do a Change Directory, use the '-C' option on tar.

Share and Enjoy! Ian
Building a dumber user
Shannon Petry
Honored Contributor

Re: tar command

First, read the man pages, as some of the switches given here you may not want. I.E. "-v"

The tar command has always as the first argument what you want it to do..
-c = create
-x = extract
-t = view contents
-r = add to current archive

The -v option is verbose, meaning you will see everything that tar does. This may not be critical for you, as failures will come on screen without the -v option.

The -f option means that you are specifiying a file/device for the archive, as opposed to using the system default "/dev/tape".

The tar command has the following format.

tar

Unix can understand many switches in a single string. I.E.

tar -c -v -f
is the same as...
tar -cvf

When creating a tar file, you must have a file list. This can be any string space separated as long as your total command does not extend past about 4K characters.

tar -cf /home/me/backup.tar /usr /opt /var

would create a file in your home that was a tar archive of /usr, /opt, and /var.

I would recommend this over backing up "/", as you will not be needing most of the contents of /tmp, /var/tmp, and can get in trouble with things like /dev if your system configuration changes.
Microsoft. When do you want a virus today?