LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-29-2005, 01:36 PM   #1
mimithebrain
Member
 
Registered: Nov 2003
Location: ~
Distribution: Ubuntu 10.04
Posts: 843
Blog Entries: 1

Rep: Reputation: 30
using tar


I want to backup my root folder, using tar, how do I create a backup of the root folder, and keep the user ownership, file attributes and so on?

Then, how do I extract it properly so the owners and attributes are the same as before? how can I keep the symlinks?

thanks
 
Old 10-29-2005, 02:27 PM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
man tar gives you all available options but file permissions should be preserved by default... but the -p option is for preserve.

tar -cpvf root/ root.tar
 
Old 10-29-2005, 04:10 PM   #3
ahedler
Member
 
Registered: Oct 2005
Location: A safe distance from Detroit
Distribution: SuSE 10.0, Knoppix
Posts: 99

Rep: Reputation: 17
I'm pretty sure that the -f option requires the filename right after the option, so it should read:

tar -cpvf root.tar /root

This should create the root.tar file in the current directory and include the contents of /root and any subdirectories.

-Alan
 
Old 10-29-2005, 04:15 PM   #4
ahedler
Member
 
Registered: Oct 2005
Location: A safe distance from Detroit
Distribution: SuSE 10.0, Knoppix
Posts: 99

Rep: Reputation: 17
Oops, forgot the extract part.

tar -xvf root.tar

should untar all the files and subdirectories to your current directory, so be aware of where you are when you untar the file. Any symbolic links should be created as they were saved, but could point to non-existant locations if the tar file is extracted on a different box or in a different location. It depends partly on whether the links used absolute paths or relative paths, and whether they were pointing to something that was also in the tar file.
 
Old 10-29-2005, 04:32 PM   #5
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Quote:
Originally posted by ahedler
I'm pretty sure that the -f option requires the filename right after the option, so it should read:

tar -cpvf root.tar /root

This should create the root.tar file in the current directory and include the contents of /root and any subdirectories.

-Alan
Whoops, yeah, wasn't thinking but the name of the file does come before the directory or files your tar'ing up. Good eye..
 
Old 10-29-2005, 06:56 PM   #6
mimithebrain
Member
 
Registered: Nov 2003
Location: ~
Distribution: Ubuntu 10.04
Posts: 843

Original Poster
Blog Entries: 1

Rep: Reputation: 30
ah thanks
perfect!

Is there a way to make the symlinks relative instead of absolute?
 
Old 11-02-2005, 09:33 PM   #7
ahedler
Member
 
Registered: Oct 2005
Location: A safe distance from Detroit
Distribution: SuSE 10.0, Knoppix
Posts: 99

Rep: Reputation: 17
Yeah, but it can be a bit confusing. The basic syntax is just like a copy command, that is:

ln -s <target> <link>

So, for instance, if I want a link called media in my homedir that points at /download/media, it will be like this:

ln -s /download/media ~alan/media

This will create a link to an absolute path, /download/media.

But if I want to make a link to my brother's media stuff in his homedir that is parallel to mine (that is, mine may be /home/alan and his is /home/marty), then I can make it relative like this:

ln -s ../marty/media ~alan/media

Bear in mind that this relative path must be with respect to MY HOMEDIR, that is, with respect to where the link is created, rather than where I am when I create the link.

In other words, I can be at /root (or anywhere at all) and issue that 'ln -s' command just above, and it will point to the right place, ~marty/media, because it is how to get there from *where the link gets put*.

So if I were to tar up only my homedir, but not my brother's, when I untar it somewhere else, that link will be pointing to a non-existant directory, but if I tar the /home directory, it will still find my brother's media directory, no matter where it gets untarred.

Some people get confused because they specify the target relative to where they are when they issue the link command, which works OK if you are in the directory where the link will be created, but doesn't work if you are in a directory above or below, or elsewhere.

The easy way is to be in the directory where the link will be and specify the link relative to where you are.

The less-intuitive way is to specify the target relative to where the link will be. This actually would allow you to create a link that points at a non-existant directory when you create the tar file, but will point at a real directory when it gets untarred in its intended destination. Obscure, even weird, but doable.

-Alan
 
Old 11-02-2005, 10:06 PM   #8
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
You may want to use the -l (local) option, so that you don't back up files from your cdrom. If you have several partitions mounted, such as separate /home and /usr partitions, then doing this you will need to include each one separately.

There is a fairly lengthy manual, that you can produce from the source package/tarball. It isn't included in the "make" default target, but if you use "make pdf" or "make dvi" or "make ps", you will produce the manual.

Also, consider how you will select the files to be backed up in the future. You may want to use the file command to produce a list of files changed after the last date. Another thing to consider is using kar or kdar to produce the backups instead. Tar was written with tape backups in mind, while dar was written to make cdrom and dvd backups easier.
 
Old 11-03-2005, 12:52 AM   #9
happy78
Member
 
Registered: Aug 2003
Posts: 50

Rep: Reputation: 15
Quote:
Originally posted by trickykid
man tar gives you all available options but file permissions should be preserved by default... but the -p option is for preserve.

tar -cpvf root/ root.tar
But it doesn't preserve the ownership.
I had a bunch of files owned by user A
user B tar A's files. When B untar it, file permissions are preserved, but the owner now is B, instead of A.

Is there any way to preserve ownership?
 
Old 11-03-2005, 12:13 PM   #10
mimithebrain
Member
 
Registered: Nov 2003
Location: ~
Distribution: Ubuntu 10.04
Posts: 843

Original Poster
Blog Entries: 1

Rep: Reputation: 30
I think it does preserve it, from what I just read and the subscequant experiment... however, if you change system altogether, and the user ID are different, I experienced that the username gets mixed...
 
Old 11-03-2005, 02:00 PM   #11
ahedler
Member
 
Registered: Oct 2005
Location: A safe distance from Detroit
Distribution: SuSE 10.0, Knoppix
Posts: 99

Rep: Reputation: 17
The -p option should preserve the permissions, and I believe, ownership. When extracting, you also need to use the -p. If the ID doesn't exist on the box when extracting, it will probably show the UID of the previous owner.

(I tried to look up this info in man pages, but they are incomplete and say to read the info pages, but I have to go back and relearn how to use info - not at all intuitive!)

-Alan
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i decompress this tar.tar file? hmmm sounds new.. tar.tar.. help ;) kublador Linux - Software 14 10-25-2016 02:48 AM
tar tar cvf - . | (cd /root/; tar xvf -) ewt3y Linux - General 10 02-19-2014 10:55 AM
a tough question 4 u, problem in extracting tar & tar.gz files p_garg Linux - General 5 11-08-2010 11:02 AM
.rpms, .tar.gz, .tgz, .src.rpm, & .tar.bz2 whoots Mandriva 10 10-18-2003 12:08 PM
Diferance between rpm, tar, tar.gz, scr.tar, etc mobassir Linux - General 12 08-21-2003 06:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration