From: Alan Chandler on
I am using tar within a monthly cron job, and found that my command line
has an error. I 'think' I understand what it is, but I can't find any
examples or explanation by reading the tar manual on the GNU website, or
generally using google of how to work round it.

I presume my cron job is being run with the current directory as
filesystem root, because this command line

tar -czf /bak/archive/snap/mb.com/melinda.tar.gz --exclude-tag=NOBAK.TAG
-C /bak/mb.com *

complains that it can't find many of the root level directories.

I suspect the * here is being expanded by the shell before it calls tar,
which is what causes the problem. How can I tell tar to copy all the
files in the /bak/mb.com directory into the archive (exluding the
directories that have a file called NOBAK.TAG in them) in such a way
that the inside of the tar archive does NOT have the directory mb.com as
its top level, but all the files and directories under mb.com. (I am
relaxed about including the files/directories starting with a dot,
although on balance I would prefer that they be included).
--
Alan Chandler
http://www.chandlerfamily.org.uk


--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org
Archive: http://lists.debian.org/4C559BD5.1000107(a)chandlerfamily.org.uk
From: Sven Joachim on
On 2010-08-01 18:07 +0200, Alan Chandler wrote:

> I am using tar within a monthly cron job, and found that my command
> line has an error. I 'think' I understand what it is, but I can't
> find any examples or explanation by reading the tar manual on the GNU
> website, or generally using google of how to work round it.
>
> I presume my cron job is being run with the current directory as
> filesystem root, because this command line
>
> tar -czf /bak/archive/snap/mb.com/melinda.tar.gz
> --exclude-tag=NOBAK.TAG -C /bak/mb.com *
>
> complains that it can't find many of the root level directories.
>
> I suspect the * here is being expanded by the shell before it calls
> tar, which is what causes the problem.

Indeed, that is the problem.

> How can I tell tar to copy all
> the files in the /bak/mb.com directory into the archive (exluding the
> directories that have a file called NOBAK.TAG in them) in such a way
> that the inside of the tar archive does NOT have the directory mb.com
> as its top level, but all the files and directories under mb.com. (I
> am relaxed about including the files/directories starting with a dot,
> although on balance I would prefer that they be included).

Use "tar --strip-components=1 … -C /bak mb.com" (untested).

Sven


--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org
Archive: http://lists.debian.org/877hkaux5z.fsf(a)turtle.gmx.de
From: Bob Proulx on
Sven Joachim wrote:
> Alan Chandler wrote:
> > I presume my cron job is being run with the current directory as
> > filesystem root, because this command line
> > tar -czf /bak/archive/snap/mb.com/melinda.tar.gz --exclude-tag=NOBAK.TAG -C /bak/mb.com *
> > complains that it can't find many of the root level directories.

I prefer not to use a '*' file glob wildcard there. That will skip
dot files for example. Use '.' instead to mean the current directory
and to get everything in the directory.

> > I suspect the * here is being expanded by the shell before it calls
> > tar, which is what causes the problem.
>
> Indeed, that is the problem.

Agreed.

> > How can I tell tar to copy all the files in the /bak/mb.com
> > directory into the archive (exluding the directories that have a
> > file called NOBAK.TAG in them) in such a way that the inside of
> > the tar archive does NOT have the directory mb.com as its top
> > level, but all the files and directories under mb.com. (I am
> > relaxed about including the files/directories starting with a dot,
> > although on balance I would prefer that they be included).
>
> Use "tar --strip-components=1 … -C /bak mb.com" (untested).

I may have read too quickly and you may have been illustrating the
general concept but if already changing directories then why strip any
components?

tar -czf /.../tarfile.tar.gz --exclude-tag=NOBAK.TAG -C /bak/mb.com .

Alternatively you can change directory to there first.

cd /bak/mb.com && tar -czf /.../tarfile.tar.gz --exclude-tag=NOBAK.TAG .

In case due to font reasons it isn't easily noticeable note the use of
'.' for a directory name at the end of the command line.

Bob
From: Alan Chandler on
On 01/08/10 18:00, Bob Proulx wrote:
> Sven Joachim wrote:
>> Alan Chandler wrote:
>
>>> I suspect the * here is being expanded by the shell before it calls
>>> tar, which is what causes the problem.
>>
>> Indeed, that is the problem.
>
> Agreed.
>
>>> How can I tell tar to copy all the files in the /bak/mb.com
>>> directory into the archive (exluding the directories that have a
>>> file called NOBAK.TAG in them) in such a way that the inside of
>>> the tar archive does NOT have the directory mb.com as its top
>>> level, but all the files and directories under mb.com. (I am
>>> relaxed about including the files/directories starting with a dot,
>>> although on balance I would prefer that they be included).
>>
>> Use "tar --strip-components=1 … -C /bak mb.com" (untested).
>
> I may have read too quickly and you may have been illustrating the
> general concept but if already changing directories then why strip any
> components?
>
> tar -czf /.../tarfile.tar.gz --exclude-tag=NOBAK.TAG -C /bak/mb.com .
>
> Alternatively you can change directory to there first.
>
> cd /bak/mb.com&& tar -czf /.../tarfile.tar.gz --exclude-tag=NOBAK.TAG .
>
> In case due to font reasons it isn't easily noticeable note the use of
> '.' for a directory name at the end of the command line.
>

Thanks to both of you. I'll go with Bob's first approach - just is the
closest to what I was doing before

--
Alan Chandler
http://www.chandlerfamily.org.uk



--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org
Archive: http://lists.debian.org/4C55DE85.8010200(a)chandlerfamily.org.uk