use of the date command in tar

use of the date command in tar

am 27.12.2007 01:00:58 von swordsaintzero

siteid=3333
localbkup=/home/$siteid
tar cvf `date +%F-%R`-$siteid.tar $localbkup -C $localbkup

from what I understand the above command would create a tar file (in a
verbose fashion) with the date and time as part of the file name in it
would be consist of the contents of /home/3333 and be stored in that
same directory.

when I run the snippet I get...

tar: 2007-12-2617\:57.tar: Cannot open: Input/output error
tar: Error is not recoverable: exiting now


I am pulling my hair out here, would someone be so kind as to point
out what I did wrong. Or point me to a page that has the documentation
that shows me what I did wrong and let me figure it out on my own.

(this is not a homework assignment just a personal project that's not
working)

Thank you in advance.

ss0

Re: use of the date command in tar

am 27.12.2007 01:25:45 von mallin.shetland

swordsaintzero@gmail.com scrisse:

> tar: 2007-12-2617\:57.tar: Cannot open: Input/output error
> tar: Error is not recoverable: exiting now

You have some trouble with the colon.

tar tries to open remote file 57.tar on remote machine
2007-12-2517

Use GNU tar --force-local option.

info tar
man tar

Re: use of the date command in tar

am 27.12.2007 02:55:38 von Bill Marcum

On 2007-12-27, mallin.shetland wrote:
>
>
> swordsaintzero@gmail.com scrisse:
>
>> tar: 2007-12-2617\:57.tar: Cannot open: Input/output error
>> tar: Error is not recoverable: exiting now
>
> You have some trouble with the colon.
>
> tar tries to open remote file 57.tar on remote machine
> 2007-12-2517
>
> Use GNU tar --force-local option.
>
Or change the date command so it doesn't produce a colon.
date +%F%H%M

Re: use of the date command in tar

am 27.12.2007 03:04:22 von swordsaintzero

On Dec 26, 6:25 pm, "mallin.shetland" wrote:
> swordsaintz...@gmail.com scrisse:
>
> > tar: 2007-12-2617\:57.tar: Cannot open: Input/output error
> > tar: Error is not recoverable: exiting now
>
> You have some trouble with the colon.
>
> tar tries to open remote file 57.tar on remote machine
> 2007-12-2517
>
> Use GNU tar --force-local option.
>
> info tar
> man tar

> tar tries to open remote file 57.tar on remote machine
> 2007-12-2517
>
> Use GNU tar --force-local option.
>
> info tar
> man tar

Thank you so much, it never occurred to me that the colon was behaving
as it does in rsync or scp. Now that I know this should I use "-l, --
one-file-system" during the creation of the archive as well?

One more question, tar seems to create the archive in whatever
directory I'm in when it runs the command even if I specify -C /home/
3333 am I missing how to use -C properly? I have now read the info
page as well as the man page and this option appears to be the only
one to address the afore mentioned need.

Thank you so much for the help.

Re: use of the date command in tar

am 27.12.2007 03:13:44 von Barry Margolin

In article
<900367b4-fc23-4ced-b56b-dec392a001ba@x29g2000prg.googlegroups.com>,
swordsaintzero@gmail.com wrote:

> On Dec 26, 6:25 pm, "mallin.shetland" wrote:
> > swordsaintz...@gmail.com scrisse:
> >
> > > tar: 2007-12-2617\:57.tar: Cannot open: Input/output error
> > > tar: Error is not recoverable: exiting now
> >
> > You have some trouble with the colon.
> >
> > tar tries to open remote file 57.tar on remote machine
> > 2007-12-2517
> >
> > Use GNU tar --force-local option.
> >
> > info tar
> > man tar
>
> > tar tries to open remote file 57.tar on remote machine
> > 2007-12-2517
> >
> > Use GNU tar --force-local option.
> >
> > info tar
> > man tar
>
> Thank you so much, it never occurred to me that the colon was behaving
> as it does in rsync or scp. Now that I know this should I use "-l, --
> one-file-system" during the creation of the archive as well?
>
> One more question, tar seems to create the archive in whatever
> directory I'm in when it runs the command even if I specify -C /home/
> 3333 am I missing how to use -C properly? I have now read the info
> page as well as the man page and this option appears to be the only
> one to address the afore mentioned need.

-C is only used to specify where the files to be archived or extracted
belong, it doesn't affect the -f option. Why not just put /home/3333 in
the pathname, i.e.

tar cvf `date +/home/3333/%F-%R`-$siteid.tar ...

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

Re: use of the date command in tar

am 27.12.2007 04:20:40 von swordsaintzero

On Dec 26, 8:13 pm, Barry Margolin wrote:
> In article
> <900367b4-fc23-4ced-b56b-dec392a00...@x29g2000prg.googlegroups.com>,
>
>
>
> swordsaintz...@gmail.com wrote:
> > On Dec 26, 6:25 pm, "mallin.shetland" wrote:
> > > swordsaintz...@gmail.com scrisse:
>
> > > > tar: 2007-12-2617\:57.tar: Cannot open: Input/output error
> > > > tar: Error is not recoverable: exiting now
>
> > > You have some trouble with the colon.
>
> > > tar tries to open remote file 57.tar on remote machine
> > > 2007-12-2517
>
> > > Use GNU tar --force-local option.
>
> > > info tar
> > > man tar
>
> > > tar tries to open remote file 57.tar on remote machine
> > > 2007-12-2517
>
> > > Use GNU tar --force-local option.
>
> > > info tar
> > > man tar
>
> > Thank you so much, it never occurred to me that the colon was behaving
> > as it does in rsync or scp. Now that I know this should I use "-l, --
> > one-file-system" during the creation of the archive as well?
>
> > One more question, tar seems to create the archive in whatever
> > directory I'm in when it runs the command even if I specify -C /home/
> > 3333 am I missing how to use -C properly? I have now read the info
> > page as well as the man page and this option appears to be the only
> > one to address the afore mentioned need.
>
> -C is only used to specify where the files to be archived or extracted
> belong, it doesn't affect the -f option. Why not just put /home/3333 in
> the pathname, i.e.
>
> tar cvf `date +/home/3333/%F-%R`-$siteid.tar ...
>
> --
> Barry Margolin, bar...@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
> *** PLEASE don't copy me on replies, I'll read them in the group ***
Thank you for your reply!

I did try this previous to inquiring about the -C option ( thank you
for the explanation now I understand that -C is purely changing the
directory being manipulated rather than changing the container the
manipulated results are created in, or extracted to) however it seems
when the file is extracted it creates a folder named home which the
contents of the tar file are inside of. I would rather not have this
happen. I want to prevent the creation of a tar bomb while
simultaneously not creating a folder which might exist on another
machine. Could that overwrite the home directory if a user opened it
in the home directory of there machine?

Thank you for all your help.

Re: use of the date command in tar

am 27.12.2007 04:37:54 von Janis Papanagnou

swordsaintzero@gmail.com wrote:
> On Dec 26, 8:13 pm, Barry Margolin wrote:
>
>>In article
>><900367b4-fc23-4ced-b56b-dec392a00...@x29g2000prg.googlegroups.com>,
>>
>>
>>
>> swordsaintz...@gmail.com wrote:
>>
>>>On Dec 26, 6:25 pm, "mallin.shetland" wrote:
>>>
>>>>swordsaintz...@gmail.com scrisse:
>>
>>>>>tar: 2007-12-2617\:57.tar: Cannot open: Input/output error
>>>>>tar: Error is not recoverable: exiting now
>>
>>>>You have some trouble with the colon.
>>
>>>>tar tries to open remote file 57.tar on remote machine
>>>>2007-12-2517
>>
>>>>Use GNU tar --force-local option.
>>
>>>>info tar
>>>>man tar
>>
>>>>tar tries to open remote file 57.tar on remote machine
>>>>2007-12-2517
>>
>>>>Use GNU tar --force-local option.
>>
>>>>info tar
>>>>man tar
>>
>>>Thank you so much, it never occurred to me that the colon was behaving
>>>as it does in rsync or scp. Now that I know this should I use "-l, --
>>>one-file-system" during the creation of the archive as well?
>>
>>>One more question, tar seems to create the archive in whatever
>>>directory I'm in when it runs the command even if I specify -C /home/
>>>3333 am I missing how to use -C properly? I have now read the info
>>>page as well as the man page and this option appears to be the only
>>>one to address the afore mentioned need.
>>
>>-C is only used to specify where the files to be archived or extracted
>>belong, it doesn't affect the -f option. Why not just put /home/3333 in
>>the pathname, i.e.
>>
>>tar cvf `date +/home/3333/%F-%R`-$siteid.tar ...
>>
>>--
>>Barry Margolin, bar...@alum.mit.edu
>>Arlington, MA
>>*** PLEASE post questions in newsgroups, not directly to me ***
>>*** PLEASE don't copy me on replies, I'll read them in the group ***
>
> Thank you for your reply!
>
> I did try this previous to inquiring about the -C option ( thank you
> for the explanation now I understand that -C is purely changing the
> directory being manipulated rather than changing the container the
> manipulated results are created in, or extracted to) however it seems
> when the file is extracted it creates a folder named home which the
> contents of the tar file are inside of. I would rather not have this
> happen.

I usually cd into the directory where my archive structure shall be
taken from or where the data tree starts...

( cd where-to-start; tar cf where/the/archive/goes.tar . )

( cd where/to/start; tar cf where/archive/goes.tar top/of/data/tree )


> I want to prevent the creation of a tar bomb while
> simultaneously not creating a folder which might exist on another
> machine. Could that overwrite the home directory if a user opened it
> in the home directory of there machine?

At least with GNU tar there's the option k to prevent overwriting
existing files.

Janis

>
> Thank you for all your help.

Re: use of the date command in tar

am 27.12.2007 10:09:11 von Keith Thompson

Bill Marcum writes:
> On 2007-12-27, mallin.shetland wrote:
>> swordsaintzero@gmail.com scrisse:
>>
>>> tar: 2007-12-2617\:57.tar: Cannot open: Input/output error
>>> tar: Error is not recoverable: exiting now
>>
>> You have some trouble with the colon.
>>
>> tar tries to open remote file 57.tar on remote machine
>> 2007-12-2517
>>
>> Use GNU tar --force-local option.
>>
> Or change the date command so it doesn't produce a colon.
> date +%F%H%M

For legibility, I'd suggest
date +%F-%H%M
for example:
2007-12-27-0104

Though ':' is a legal filename character (as is anything other than
'/' and the null character), it's best to avoid using it unless you
really need to. tar isn't the only command that will have trouble
with it; scp is another example. Different commands will have
different ways of dealing with the ':' character; some may not be able
to handlet it at all.

Finally, if you need to guarantee that your timestamps can be sorted,
even during Daylight Saving Time transitions, consider using UTC
rather than local time: "date -u +%F-%H%M". For 1-second precision
rather than 1-minute precision, you can use "date -u +%F-%H%M%S".

--
Keith Thompson (The_Other_Keith)
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Re: use of the date command in tar

am 27.12.2007 15:46:07 von hymie_

In our last episode, the evil Dr. Lacto had captured our hero,
Keith Thompson , who said:
>
>Though ':' is a legal filename character (as is anything other than
>'/' and the null character),

It's been a while for me, but isn't : a directory separator in MacOS?

--hymie! http://lactose.homelinux.net/~hymie hymie@lactose.homelinux.net
------------------------ Without caffeine for 422 days ------------------------

Re: use of the date command in tar

am 27.12.2007 19:12:06 von Janis Papanagnou

hymie! wrote:
> In our last episode, the evil Dr. Lacto had captured our hero,
> Keith Thompson , who said:
>
>>Though ':' is a legal filename character (as is anything other than
>>'/' and the null character),
>
>
> It's been a while for me, but isn't : a directory separator in MacOS?

MacOS is now Unix based. But faint memories suggest that the colon was
a directory separator in VMS. (I may be wrong, though; I've used that
system two decades ago.)

Janis

Re: use of the date command in tar

am 27.12.2007 22:40:44 von swordsaintzero

On Dec 26, 9:37 pm, Janis Papanagnou
wrote:
> swordsaintz...@gmail.com wrote:
> > On Dec 26, 8:13 pm, Barry Margolin wrote:
>
> >>In article
> >><900367b4-fc23-4ced-b56b-dec392a00...@x29g2000prg.googlegroups.com>,
>
> >> swordsaintz...@gmail.com wrote:
>
> >>>On Dec 26, 6:25 pm, "mallin.shetland" wrote:
>
> >>>>swordsaintz...@gmail.com scrisse:
>
> >>>>>tar: 2007-12-2617\:57.tar: Cannot open: Input/output error
> >>>>>tar: Error is not recoverable: exiting now
>
> >>>>You have some trouble with the colon.
>
> >>>>tar tries to open remote file 57.tar on remote machine
> >>>>2007-12-2517
>
> >>>>Use GNU tar --force-local option.
>
> >>>>info tar
> >>>>man tar
>
> >>>>tar tries to open remote file 57.tar on remote machine
> >>>>2007-12-2517
>
> >>>>Use GNU tar --force-local option.
>
> >>>>info tar
> >>>>man tar
>
> >>>Thank you so much, it never occurred to me that the colon was behaving
> >>>as it does in rsync or scp. Now that I know this should I use "-l, --
> >>>one-file-system" during the creation of the archive as well?
>
> >>>One more question, tar seems to create the archive in whatever
> >>>directory I'm in when it runs the command even if I specify -C /home/
> >>>3333 am I missing how to use -C properly? I have now read the info
> >>>page as well as the man page and this option appears to be the only
> >>>one to address the afore mentioned need.
>
> >>-C is only used to specify where the files to be archived or extracted
> >>belong, it doesn't affect the -f option. Why not just put /home/3333 in
> >>the pathname, i.e.
>
> >>tar cvf `date +/home/3333/%F-%R`-$siteid.tar ...
>
> >>--
> >>Barry Margolin, bar...@alum.mit.edu
> >>Arlington, MA
> >>*** PLEASE post questions in newsgroups, not directly to me ***
> >>*** PLEASE don't copy me on replies, I'll read them in the group ***
>
> > Thank you for your reply!
>
> > I did try this previous to inquiring about the -C option ( thank you
> > for the explanation now I understand that -C is purely changing the
> > directory being manipulated rather than changing the container the
> > manipulated results are created in, or extracted to) however it seems
> > when the file is extracted it creates a folder named home which the
> > contents of the tar file are inside of. I would rather not have this
> > happen.
>
> I usually cd into the directory where my archive structure shall be
> taken from or where the data tree starts...
>
> ( cd where-to-start; tar cf where/the/archive/goes.tar . )
>
> ( cd where/to/start; tar cf where/archive/goes.tar top/of/data/tree )
>
> > I want to prevent the creation of a tar bomb while
> > simultaneously not creating a folder which might exist on another
> > machine. Could that overwrite the home directory if a user opened it
> > in the home directory of there machine?
>
> At least with GNU tar there's the option k to prevent overwriting
> existing files.
>
> Janis
>
>
>
> > Thank you for all your help.

On Dec 26, 9:37 pm, Janis Papanagnou
wrote:
> swordsaintz...@gmail.com wrote:
> > On Dec 26, 8:13 pm, Barry Margolin wrote:
>
> >>In article
> >><900367b4-fc23-4ced-b56b-dec392a00...@x29g2000prg.googlegroups.com>,
>
> >> swordsaintz...@gmail.com wrote:
>
> >>>On Dec 26, 6:25 pm, "mallin.shetland" wrote:
>
> >>>>swordsaintz...@gmail.com scrisse:
>
> >>>>>tar: 2007-12-2617\:57.tar: Cannot open: Input/output error
> >>>>>tar: Error is not recoverable: exiting now
>
> >>>>You have some trouble with the colon.
>
> >>>>tar tries to open remote file 57.tar on remote machine
> >>>>2007-12-2517
>
> >>>>Use GNU tar --force-local option.
>
> >>>>info tar
> >>>>man tar
>
> >>>>tar tries to open remote file 57.tar on remote machine
> >>>>2007-12-2517
>
> >>>>Use GNU tar --force-local option.
>
> >>>>info tar
> >>>>man tar
>
> >>>Thank you so much, it never occurred to me that the colon was behaving
> >>>as it does in rsync or scp. Now that I know this should I use "-l, --
> >>>one-file-system" during the creation of the archive as well?
>
> >>>One more question, tar seems to create the archive in whatever
> >>>directory I'm in when it runs the command even if I specify -C /home/
> >>>3333 am I missing how to use -C properly? I have now read the info
> >>>page as well as the man page and this option appears to be the only
> >>>one to address the afore mentioned need.
>
> >>-C is only used to specify where the files to be archived or extracted
> >>belong, it doesn't affect the -f option. Why not just put /home/3333 in
> >>the pathname, i.e.
>
> >>tar cvf `date +/home/3333/%F-%R`-$siteid.tar ...
>
> >>--
> >>Barry Margolin, bar...@alum.mit.edu
> >>Arlington, MA
> >>*** PLEASE post questions in newsgroups, not directly to me ***
> >>*** PLEASE don't copy me on replies, I'll read them in the group ***
>
> > Thank you for your reply!
>
> > I did try this previous to inquiring about the -C option ( thank you
> > for the explanation now I understand that -C is purely changing the
> > directory being manipulated rather than changing the container the
> > manipulated results are created in, or extracted to) however it seems
> > when the file is extracted it creates a folder named home which the
> > contents of the tar file are inside of. I would rather not have this
> > happen.
>
> I usually cd into the directory where my archive structure shall be
> taken from or where the data tree starts...
>
> ( cd where-to-start; tar cf where/the/archive/goes.tar . )
>
> ( cd where/to/start; tar cf where/archive/goes.tar top/of/data/tree )
>
> > I want to prevent the creation of a tar bomb while
> > simultaneously not creating a folder which might exist on another
> > machine. Could that overwrite the home directory if a user opened it
> > in the home directory of there machine?
>
> At least with GNU tar there's the option k to prevent overwriting
> existing files.
>
> Janis
>
>
>
> > Thank you for all your help.

Thank you for taking the time to reply everyone!


Janis, In theory what I would like to have happen is this.

(pseudo code)

tarball files in directory foo, place the tar file in the directory it
was created in to be picked up by rsync
mv files from directory foo to server bar in directory baz via rsync

if someone wanted to extract the archived files in directory baz and
they untarred the archive.
when the tar is extracted create directory /baz/name of tar ball/tar
contents;

However, when I run the command cd $localbkup && tar -czvf `date +%F-
%H%M`-$siteid.tar.gz *

(localbkup = /home/3333 in this case, and siteid = 3333 as you may
have guessed by now)

I do indeed get a tar file created in the home/3333 dir. however if
you extract it, it creates no directory at all it simply places the
files in the directory the extraction was run in.
So if I specify the full path /home/3333/`date +%F-%H%M`-
$siteid.tar.gz I get the two directories home/3333/filesitarred. What
am I missing here?

Any ideas on how I can tell tar a directory name to pack all the
files into, so when they are extracted they stay in a nice neat
"folder" that has nothing to do with the file hierarchy of the system
they were compressed on.

(btw I am still surprised there is no flag to determine an output
directory, I guess the ease of using a cd before running the tar
command precludes that)

Re: use of the date command in tar

am 27.12.2007 23:09:57 von Barry Margolin

In article
<964156aa-2dd3-4aed-ae2d-a647d3537031@x29g2000prg.googlegroups.com>,
swordsaintzero@gmail.com wrote:

> On Dec 26, 8:13 pm, Barry Margolin wrote:
> > In article
> > <900367b4-fc23-4ced-b56b-dec392a00...@x29g2000prg.googlegroups.com>,
> >
> >
> >
> > swordsaintz...@gmail.com wrote:
> > > On Dec 26, 6:25 pm, "mallin.shetland" wrote:
> > > > swordsaintz...@gmail.com scrisse:
> >
> > > > > tar: 2007-12-2617\:57.tar: Cannot open: Input/output error
> > > > > tar: Error is not recoverable: exiting now
> >
> > > > You have some trouble with the colon.
> >
> > > > tar tries to open remote file 57.tar on remote machine
> > > > 2007-12-2517
> >
> > > > Use GNU tar --force-local option.
> >
> > > > info tar
> > > > man tar
> >
> > > > tar tries to open remote file 57.tar on remote machine
> > > > 2007-12-2517
> >
> > > > Use GNU tar --force-local option.
> >
> > > > info tar
> > > > man tar
> >
> > > Thank you so much, it never occurred to me that the colon was behaving
> > > as it does in rsync or scp. Now that I know this should I use "-l, --
> > > one-file-system" during the creation of the archive as well?
> >
> > > One more question, tar seems to create the archive in whatever
> > > directory I'm in when it runs the command even if I specify -C /home/
> > > 3333 am I missing how to use -C properly? I have now read the info
> > > page as well as the man page and this option appears to be the only
> > > one to address the afore mentioned need.
> >
> > -C is only used to specify where the files to be archived or extracted
> > belong, it doesn't affect the -f option. Why not just put /home/3333 in
> > the pathname, i.e.
> >
> > tar cvf `date +/home/3333/%F-%R`-$siteid.tar ...
> >
> > --
> > Barry Margolin, bar...@alum.mit.edu
> > Arlington, MA
> > *** PLEASE post questions in newsgroups, not directly to me ***
> > *** PLEASE don't copy me on replies, I'll read them in the group ***
> Thank you for your reply!
>
> I did try this previous to inquiring about the -C option ( thank you
> for the explanation now I understand that -C is purely changing the
> directory being manipulated rather than changing the container the
> manipulated results are created in, or extracted to) however it seems
> when the file is extracted it creates a folder named home which the
> contents of the tar file are inside of. I would rather not have this
> happen. I want to prevent the creation of a tar bomb while
> simultaneously not creating a folder which might exist on another
> machine. Could that overwrite the home directory if a user opened it
> in the home directory of there machine?

You must have done something else. The directory of the -f argument
should have no effect on where files get extracted to. What you
describe is what would happen if you used the full paths when specifying
the directories to archive. Which is why you should still use the -C
option to specify the initial directory for them.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

Re: use of the date command in tar

am 27.12.2007 23:16:22 von Barry Margolin

In article ,
hymie_@_lactose.homelinux.net (hymie!) wrote:

> In our last episode, the evil Dr. Lacto had captured our hero,
> Keith Thompson , who said:
> >
> >Though ':' is a legal filename character (as is anything other than
> >'/' and the null character),
>
> It's been a while for me, but isn't : a directory separator in MacOS?

Yes, but OS X hides this. If you use the POSIX API, as tar does, it
treats / as the directory separator and : is allowed (it's converted
behind the scenes to / when writing to an HFS+ filesystem).

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

Re: use of the date command in tar

am 27.12.2007 23:51:06 von Janis Papanagnou

swordsaintzero@gmail.com wrote:
> On Dec 26, 9:37 pm, Janis Papanagnou
> wrote:
>
>>swordsaintz...@gmail.com wrote:
>>
>>>On Dec 26, 8:13 pm, Barry Margolin wrote:
>>
>>>>In article
>>>><900367b4-fc23-4ced-b56b-dec392a00...@x29g2000prg.googlegroups.com>,
>>
>>>>swordsaintz...@gmail.com wrote:
>>
>>>>>On Dec 26, 6:25 pm, "mallin.shetland" wrote:
>>
>>>>>>swordsaintz...@gmail.com scrisse:
>>
>>>>>>>tar: 2007-12-2617\:57.tar: Cannot open: Input/output error
>>>>>>>tar: Error is not recoverable: exiting now
>>
>>>>>>You have some trouble with the colon.
>>
>>>>>>tar tries to open remote file 57.tar on remote machine
>>>>>>2007-12-2517
>>
>>>>>>Use GNU tar --force-local option.
>>
>>>>>>info tar
>>>>>>man tar
>>
>>>>>>tar tries to open remote file 57.tar on remote machine
>>>>>>2007-12-2517
>>
>>>>>>Use GNU tar --force-local option.
>>
>>>>>>info tar
>>>>>>man tar
>>
>>>>>Thank you so much, it never occurred to me that the colon was behaving
>>>>>as it does in rsync or scp. Now that I know this should I use "-l, --
>>>>>one-file-system" during the creation of the archive as well?
>>
>>>>>One more question, tar seems to create the archive in whatever
>>>>>directory I'm in when it runs the command even if I specify -C /home/
>>>>>3333 am I missing how to use -C properly? I have now read the info
>>>>>page as well as the man page and this option appears to be the only
>>>>>one to address the afore mentioned need.
>>
>>>>-C is only used to specify where the files to be archived or extracted
>>>>belong, it doesn't affect the -f option. Why not just put /home/3333 in
>>>>the pathname, i.e.
>>
>>>>tar cvf `date +/home/3333/%F-%R`-$siteid.tar ...
>>
>>>>--
>>>>Barry Margolin, bar...@alum.mit.edu
>>>>Arlington, MA
>>>>*** PLEASE post questions in newsgroups, not directly to me ***
>>>>*** PLEASE don't copy me on replies, I'll read them in the group ***
>>
>>>Thank you for your reply!
>>
>>>I did try this previous to inquiring about the -C option ( thank you
>>>for the explanation now I understand that -C is purely changing the
>>>directory being manipulated rather than changing the container the
>>>manipulated results are created in, or extracted to) however it seems
>>>when the file is extracted it creates a folder named home which the
>>>contents of the tar file are inside of. I would rather not have this
>>>happen.
>>
>>I usually cd into the directory where my archive structure shall be
>>taken from or where the data tree starts...
>>
>> ( cd where-to-start; tar cf where/the/archive/goes.tar . )
>>
>> ( cd where/to/start; tar cf where/archive/goes.tar top/of/data/tree )
>>
>>
>>>I want to prevent the creation of a tar bomb while
>>>simultaneously not creating a folder which might exist on another
>>>machine. Could that overwrite the home directory if a user opened it
>>>in the home directory of there machine?
>>
>>At least with GNU tar there's the option k to prevent overwriting
>>existing files.
>>
>>Janis
>>
>>
>>
>>
>>>Thank you for all your help.
>
>
> On Dec 26, 9:37 pm, Janis Papanagnou
> wrote:
>
>>swordsaintz...@gmail.com wrote:
>>
>>>On Dec 26, 8:13 pm, Barry Margolin wrote:
>>
>>>>In article
>>>><900367b4-fc23-4ced-b56b-dec392a00...@x29g2000prg.googlegroups.com>,
>>
>>>>swordsaintz...@gmail.com wrote:
>>
>>>>>On Dec 26, 6:25 pm, "mallin.shetland" wrote:
>>
>>>>>>swordsaintz...@gmail.com scrisse:
>>
>>>>>>>tar: 2007-12-2617\:57.tar: Cannot open: Input/output error
>>>>>>>tar: Error is not recoverable: exiting now
>>
>>>>>>You have some trouble with the colon.
>>
>>>>>>tar tries to open remote file 57.tar on remote machine
>>>>>>2007-12-2517
>>
>>>>>>Use GNU tar --force-local option.
>>
>>>>>>info tar
>>>>>>man tar
>>
>>>>>>tar tries to open remote file 57.tar on remote machine
>>>>>>2007-12-2517
>>
>>>>>>Use GNU tar --force-local option.
>>
>>>>>>info tar
>>>>>>man tar
>>
>>>>>Thank you so much, it never occurred to me that the colon was behaving
>>>>>as it does in rsync or scp. Now that I know this should I use "-l, --
>>>>>one-file-system" during the creation of the archive as well?
>>
>>>>>One more question, tar seems to create the archive in whatever
>>>>>directory I'm in when it runs the command even if I specify -C /home/
>>>>>3333 am I missing how to use -C properly? I have now read the info
>>>>>page as well as the man page and this option appears to be the only
>>>>>one to address the afore mentioned need.
>>
>>>>-C is only used to specify where the files to be archived or extracted
>>>>belong, it doesn't affect the -f option. Why not just put /home/3333 in
>>>>the pathname, i.e.
>>
>>>>tar cvf `date +/home/3333/%F-%R`-$siteid.tar ...
>>
>>>>--
>>>>Barry Margolin, bar...@alum.mit.edu
>>>>Arlington, MA
>>>>*** PLEASE post questions in newsgroups, not directly to me ***
>>>>*** PLEASE don't copy me on replies, I'll read them in the group ***
>>
>>>Thank you for your reply!
>>
>>>I did try this previous to inquiring about the -C option ( thank you
>>>for the explanation now I understand that -C is purely changing the
>>>directory being manipulated rather than changing the container the
>>>manipulated results are created in, or extracted to) however it seems
>>>when the file is extracted it creates a folder named home which the
>>>contents of the tar file are inside of. I would rather not have this
>>>happen.
>>
>>I usually cd into the directory where my archive structure shall be
>>taken from or where the data tree starts...
>>
>> ( cd where-to-start; tar cf where/the/archive/goes.tar . )
>>
>> ( cd where/to/start; tar cf where/archive/goes.tar top/of/data/tree )
>>
>>
>>>I want to prevent the creation of a tar bomb while
>>>simultaneously not creating a folder which might exist on another
>>>machine. Could that overwrite the home directory if a user opened it
>>>in the home directory of there machine?
>>
>>At least with GNU tar there's the option k to prevent overwriting
>>existing files.
>>
>>Janis
>>
>>
>>
>>
>>>Thank you for all your help.
>
>
> Thank you for taking the time to reply everyone!
>
>
> Janis, In theory what I would like to have happen is this.
>
> (pseudo code)
>
> tarball files in directory foo, place the tar file in the directory it
> was created in to be picked up by rsync
> mv files from directory foo to server bar in directory baz via rsync
>
> if someone wanted to extract the archived files in directory baz and
> they untarred the archive.
> when the tar is extracted create directory /baz/name of tar ball/tar
> contents;

How should the actual 'name' be composed, just as a literal "name"?

>
> However, when I run the command cd $localbkup && tar -czvf `date +%F-
> %H%M`-$siteid.tar.gz *
>
> (localbkup = /home/3333 in this case, and siteid = 3333 as you may
> have guessed by now)
>
> I do indeed get a tar file created in the home/3333 dir. however if
> you extract it, it creates no directory at all it simply places the
> files in the directory the extraction was run in.
> So if I specify the full path /home/3333/`date +%F-%H%M`-
> $siteid.tar.gz I get the two directories home/3333/filesitarred. What
> am I missing here?

Tar removes the leading / from an absolute path.

>
> Any ideas on how I can tell tar a directory name to pack all the
> files into, so when they are extracted they stay in a nice neat
> "folder" that has nothing to do with the file hierarchy of the system
> they were compressed on.

You want to trick tar to pick/add a non-existing directory?

Before tar'ing use the ln(1) command to create an new entry referencing
the directory where the tar data are residing (for directories you have
to create a soft link using ln -s), then tar that newly created directory
name (with GNU tar you need the 'h' option so that not the symlink will
be added but the actual file structure).

>
> (btw I am still surprised there is no flag to determine an output
> directory, I guess the ease of using a cd before running the tar
> command precludes that)

Tar creates a hierarchical image of the actual directory structure; the
term "output directory" may mislead you.

Janis

Re: use of the date command in tar

am 28.12.2007 02:52:35 von Barry Margolin

In article ,
Janis Papanagnou wrote:

> Tar removes the leading / from an absolute path.

GNU tar does that. Traditional tar doesn't. I haven't checked, but I
expect that POSIX tar doesn't.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***