redirecting files from tar -xvf
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix administration > redirecting files from tar -xvf




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    redirecting files from tar -xvf  
Chris Campbell


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 09:49 PM

Howdy -

I'm trying to set up a simple script to do some automated backups.
The basic command to create the archive is something like:

tar -cvf archive.tar files-to-be-tar'd

"files-to-be-tar'd" can include path, but there are some tradeoffs on
how you do that path:

/path/to/directory/*    - will pull correct files no matter what the
pwd is when the tar command is run
- will restore files to that same location
(is there some way to override?)
path/to/directory/*     - will pull correct files only if the tar
command is run from the root directory
- will restore files to whatever the
pwd is when the tar command is run

[I hope that formatted properly, try fixed width if it didn't]

I'd like to pull the files from a path that starts explicitely from
root (e.g. /path/to/directory) so it doesn't matter what the pwd is
when it runs, but I don't like that the restore (xvf) puts them back
in that same spot, *no matter* what the pwd is when I run it.  I'd
like to be able to restore them someplace else.

Is there some trivial way to redirect where the files go when I
un-tar, even if the paths in the tar explicitely start at root?  Note
that the archive may contain several directories, not just a bunch of
files from one directory.

Sorry if this is a stupid question.  Thanks!





[ Post a follow-up to this message ]



    Re: redirecting files from tar -xvf  
paroikos


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 09:49 PM

On 17 Sep 2003 11:40:30 -0700, Chris Campbell <chris-google@pobox.com> wrote:
quote:
> Howdy - > > I'm trying to set up a simple script to do some automated backups. > The basic command to create the archive is something like: > > tar -cvf archive.tar files-to-be-tar'd > > "files-to-be-tar'd" can include path, but there are some tradeoffs on > how you do that path: > > /path/to/directory/* - will pull correct files no matter what the > pwd is when the tar command is run > - will restore files to that same location > (is there some way to override?) > path/to/directory/* - will pull correct files only if the tar > command is run from the root directory > - will restore files to whatever the > pwd is when the tar command is run > > [I hope that formatted properly, try fixed width if it didn't] > > I'd like to pull the files from a path that starts explicitely from > root (e.g. /path/to/directory) so it doesn't matter what the pwd is > when it runs, but I don't like that the restore (xvf) puts them back > in that same spot, *no matter* what the pwd is when I run it. I'd > like to be able to restore them someplace else. > > Is there some trivial way to redirect where the files go when I > un-tar, even if the paths in the tar explicitely start at root? Note > that the archive may contain several directories, not just a bunch of > files from one directory. > > Sorry if this is a stupid question. Thanks!
The GNU version of tar will strip the leading slash and that can be overridden with the -P option. You should be able to use this to accomplish your goal, if you're using the GNU version.




[ Post a follow-up to this message ]



    Re: redirecting files from tar -xvf  
Carl Lowenstein


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 09:49 PM

In article <ba42132e.0309171040.29f7b0ff@posting.google.com>,
Chris Campbell <chris-google@pobox.com> wrote:
quote:
>Howdy - > >I'm trying to set up a simple script to do some automated backups. >The basic command to create the archive is something like: > > tar -cvf archive.tar files-to-be-tar'd > >"files-to-be-tar'd" can include path, but there are some tradeoffs on >how you do that path: > >/path/to/directory/* - will pull correct files no matter what the > pwd is when the tar command is run > - will restore files to that same location > (is there some way to override?) >path/to/directory/* - will pull correct files only if the tar > command is run from the root directory > - will restore files to whatever the > pwd is when the tar command is run > >[I hope that formatted properly, try fixed width if it didn't] > >I'd like to pull the files from a path that starts explicitely from >root (e.g. /path/to/directory) so it doesn't matter what the pwd is >when it runs, but I don't like that the restore (xvf) puts them back >in that same spot, *no matter* what the pwd is when I run it. I'd >like to be able to restore them someplace else. > >Is there some trivial way to redirect where the files go when I >un-tar, even if the paths in the tar explicitely start at root? Note >that the archive may contain several directories, not just a bunch of >files from one directory.
./path/to/directory/* Notice the "./" at the beginning of the path. I think that counts as a trivial modification. This will take files from wherever tar is run (e.g. root directory) They will be restored to the pwd when the tar extract is run. carl -- carl lowenstein marine physical lab u.c. san diego clowenst@ucsd.edu




[ Post a follow-up to this message ]



    Re: redirecting files from tar -xvf  
Frederico Fonseca


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 09:49 PM

On 17 Sep 2003 11:40:30 -0700, chris-google@pobox.com (Chris Campbell)
wrote:
quote:
>Howdy - > >I'm trying to set up a simple script to do some automated backups. >The basic command to create the archive is something like: > > tar -cvf archive.tar files-to-be-tar'd > >"files-to-be-tar'd" can include path, but there are some tradeoffs on >how you do that path: > >/path/to/directory/* - will pull correct files no matter what the > pwd is when the tar command is run > - will restore files to that same location > (is there some way to override?) >path/to/directory/* - will pull correct files only if the tar > command is run from the root directory > - will restore files to whatever the > pwd is when the tar command is run > >[I hope that formatted properly, try fixed width if it didn't] > >I'd like to pull the files from a path that starts explicitely from >root (e.g. /path/to/directory) so it doesn't matter what the pwd is >when it runs, but I don't like that the restore (xvf) puts them back >in that same spot, *no matter* what the pwd is when I run it. I'd >like to be able to restore them someplace else. > >Is there some trivial way to redirect where the files go when I >un-tar, even if the paths in the tar explicitely start at root? Note >that the archive may contain several directories, not just a bunch of >files from one directory. > >Sorry if this is a stupid question. Thanks!
Most Tar's will have an option to "remove" the leading "/" while creating the archive file. (e.g. Solaris is "-P" or "-p", not sure now) Do a man tar and search for it. If you tell us which OS we may be able to tell you what option it is, but your manual is a better target. Frederico Fonseca ema il: frederico_fonseca at syssoft-int.com




[ Post a follow-up to this message ]



    Re: redirecting files from tar -xvf  
Chris Campbell


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 09:49 PM

> > Is there some trivial way to redirect where the files go when I
quote:
[QUOTE] > ./path/to/directory/* > > Notice the "./" at the beginning of the path. > I think that counts as a trivial modification. > > This will take files from wherever tar is run (e.g. root directory) > They will be restored to the pwd when the tar extract is run.
Yep, that did it. Thanks! In reply to the other posts, this is on a QNX 4.25 system, and it does not appear to be the GNU version of tar; there is no -p or -P option affecting the leading directory slash. Oddly, a Solaris machine I looked at referred to the -p option as affecting the *trailing* slash.




[ Post a follow-up to this message ]



    Re: redirecting files from tar -xvf  
Carl Lowenstein


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 09:49 PM

In article <ba42132e.0309201302.6b1e1971@posting.google.com>,
Chris Campbell <chris-google@pobox.com> wrote:
quote:
> > > >Eh, actually it didn't. I was misled because I happened to have a >/path/to/directory/path/to/directory/* directory branch set up as part >of testing. The above syntax takes it from the pwd, NOT from root. > >If anyone can help, look back in the thread. I want to run tar from >anywhere (pwd irrelevant), explicitlying specify the files-to-archive >path, but I want the restore to go where I tell it.
Well then, how about (cd / && tar -cf ./path/to/directory/*) You can't have everything. If you are using GNU tar, then gnutar -C / -cf ./path/to/directory/* carl -- carl lowenstein marine physical lab u.c. san diego clowenst@ucsd.edu




[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:20 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register