LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-26-2012, 12:21 PM   #1
sudo_su
Member
 
Registered: Aug 2012
Location: Australia
Distribution: Redhat, CentOS
Posts: 59

Rep: Reputation: Disabled
untar with wrong locations


Dear Members

I make tar from multiple files for my backup but when I untar them, the first file adapt sm weird directory structure and the ones after that seems ok. please view how I tar and notice the locations

Quote:
[root@server /]# tar -cvf /backup/25dec.tar /root/Documents/daily-logs/24dec 25dec
tar: Removing leading `/' from member names
/root/Documents/daily-logs/24dec
25dec
[root@server /]# tar -tvf /backup/25dec.tar
-rw-r--r-- root/root 0 2012-12-25 23:11 root/Documents/daily-logs/24dec
-rw-r--r-- root/root 0 2012-12-25 23:11 25dec
[root@server /]#
Please tell me what I am doing wrong.

Last edited by sudo_su; 12-26-2012 at 12:22 PM.
 
Old 12-26-2012, 12:31 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
That is correct. You are telling tar to verbosely create an archive of root/documents/daily-logs/24dec and 25dec to a file named 25dec.tar. If you don't want the preceding directory structure change to the directory with the file in it and it will only backup that file.

E,g

Code:
cd /root/Documents/daily-logs/
tar -cvf /backup/25dec.tar 24dec 25dec
This assumes that the file 25dec is also in the daily-logs folder
 
1 members found this post helpful.
Old 12-26-2012, 12:45 PM   #3
sudo_su
Member
 
Registered: Aug 2012
Location: Australia
Distribution: Redhat, CentOS
Posts: 59

Original Poster
Rep: Reputation: Disabled
Respected Kustom;

You mean to say that first I have to change my directory to the directory where I have files which I need to make tar?

like I cant do it while I am working in some other directory? ( like the case i posted with error)

Last edited by sudo_su; 12-26-2012 at 12:47 PM.
 
Old 12-26-2012, 01:01 PM   #4
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
You can make a tar anywhere but think about what you are telling tar to do...

If you tell tar to backup /root/Documents/daily-logs/24dec its going to backup just that, the entire path and meta data for the files. This is by the design of tar, imagine for a moment that you have developed an application with a big directory structure that you want to be able to port to another system. This app is contained in /opt/app1 with multiple folders underneath, /opt/app1/folder1, /opt/app1/folder2, /opt/app1/folder1/subfolder1, /opt/app1/folder1/subfolder1/subfolder2.

You are currently in the root home directory, /root.

You tell tar to make a backup with the following:

Code:
tar -czvf /tmp/myapp1.tar.gz /opt/app1

Tar will backup the files and folders as:

opt/app1/folder1

opt/app1/folder1/subfolder1

opt/app1/folder1/subfolder2

opt/app1/folder2

So when you go to deploy the tarball on another system the directory structure is the same as it was on the original system.

Note that tar will be default remove the leading / from file and folder paths.
 
1 members found this post helpful.
Old 12-26-2012, 03:57 PM   #5
ruario
Senior Member
 
Registered: Jan 2011
Location: Oslo, Norway
Distribution: Slackware
Posts: 2,559

Rep: Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773
@sudo_su: If you want to store or extract absolute paths (not usually recommended) you can with -P. If you want to change the directory use the -C option and state the directory. You might want to have a look at:

http://www.gnu.org/software/tar/manual/tar.html

Edit: These are the relevant sections of the GNU Tar online Manual:

6.10.1 Changing the Working Directory
6.10.2 Absolute File Names

Last edited by ruario; 12-26-2012 at 04:07 PM. Reason: Added direct links the relevant sections of the online Manual
 
Old 12-26-2012, 04:18 PM   #6
ruario
Senior Member
 
Registered: Jan 2011
Location: Oslo, Norway
Distribution: Slackware
Posts: 2,559

Rep: Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773
Looking at your original post, I think what you wanted was:

Code:
tar Pcf /backup/25dec.tar /root/Documents/daily-logs/24dec 25dec
 
Old 12-27-2012, 03:44 PM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,908

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by sudo_su View Post
Respected Kustom;

You mean to say that first I have to change my directory to the directory where I have files which I need to make tar?

like I cant do it while I am working in some other directory? ( like the case i posted with error)
You can use the tar option -C <path> (or --directory=<path>) to have tar set its directory to what you want to use for the base of the archive tree instead of using the cd command.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy single file to multiple locations - What am I doing wrong decartes Linux - Newbie 7 04-26-2008 04:09 PM
Untar from a CD CJohnM Linux - Newbie 8 03-12-2006 03:39 AM
'untar'? stevesk Linux - Newbie 11 12-20-2004 06:50 PM
Untar Dharma_bum07 Linux - Newbie 2 11-26-2004 10:16 AM
untar imsajjadali Red Hat 3 01-29-2004 01:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:13 AM.

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