Problem with tar & Perl - Help
This is a discussion on Problem with tar & Perl - Help ; I'm trying to write a Perl script that archives some files in tar
archives. I'm calling tar with Perl's system() function. The thing is,
if the file that I'm about to archive is already in the tar file, I
don't ...
-
Problem with tar & Perl
I'm trying to write a Perl script that archives some files in tar
archives. I'm calling tar with Perl's system() function. The thing is,
if the file that I'm about to archive is already in the tar file, I
don't want to add it again - but this is precisely what's happening.
I'm using tar with the -u switch, which should update files if they are
not already in the tar file or have been changed. Instead, tar just adds
another copy of the file. The modification dates of the original file
and the version in the tar file do match, so that isn't the problem. Any
ideas how I might get around this?
@+
srm
-
Re: Problem with tar & Perl
|I'm trying to write a Perl script that archives some files in tar
|archives. I'm calling tar with Perl's system() function. The thing is,
|if the file that I'm about to archive is already in the tar file, I
|don't want to add it again - but this is precisely what's happening.
Well it doesn't look like a perl problem so you should leave out the &
Perl in your subject.
|I'm using tar with the -u switch, which should update files if they are
|not already in the tar file or have been changed. Instead, tar just adds
|another copy of the file. The modification dates of the original file
|and the version in the tar file do match, so that isn't the problem. Any
|ideas how I might get around this?
Are you adding the file with the exact pathname as was stored in the
archive? Try it from the command line.
--
-
Re: Problem with tar & Perl
srm wrote:
> I'm trying to write a Perl script that archives some files in tar
> archives. I'm calling tar with Perl's system() function. The thing is,
> if the file that I'm about to archive is already in the tar file, I
> don't want to add it again - but this is precisely what's happening.
>
> I'm using tar with the -u switch, which should update files if they are
> not already in the tar file or have been changed. Instead, tar just adds
> another copy of the file. The modification dates of the original file
> and the version in the tar file do match, so that isn't the problem. Any
> ideas how I might get around this?
>
Sounds like you are not calling it correctly, so the switch never
makes it to tar. Suggest you post the relevant code.
Scott
--
POPFile, the OpenSource EMail Classifier
http://popfile.sourceforge.net/
Linux 2.6.5-7.95-default x86_64
-
Re: Problem with tar & Perl
fmundst@dytmvw.com wrote:
> |I'm using tar with the -u switch, which should update files if they are
> |not already in the tar file or have been changed. Instead, tar just adds
> |another copy of the file. The modification dates of the original file
> |and the version in the tar file do match, so that isn't the problem. Any
> |ideas how I might get around this?
>
> Are you adding the file with the exact pathname as was stored in the
> archive? Try it from the command line.
Yes. As tar strips the leading '/' I did the same. The thing is, when I
look in the tar file, after each run of the program, there's another
copy of the file in there. So a new copy gets added on every run, rather
than overwriting or (as I presumed would happen with '-u', being skipped).
-
Re: Problem with tar & Perl
Scott Leighton wrote:
> srm wrote:
>
>
>>I'm trying to write a Perl script that archives some files in tar
>>archives. I'm calling tar with Perl's system() function. The thing is,
>>if the file that I'm about to archive is already in the tar file, I
>>don't want to add it again - but this is precisely what's happening.
>>
>>I'm using tar with the -u switch, which should update files if they are
>>not already in the tar file or have been changed. Instead, tar just adds
>>another copy of the file. The modification dates of the original file
>>and the version in the tar file do match, so that isn't the problem. Any
>>ideas how I might get around this?
>>
>
>
> Sounds like you are not calling it correctly, so the switch never
> makes it to tar. Suggest you post the relevant code.
The name of the file is provided with the full path in a variable
$fullname. The name of the target tar file is in $tarfile. The code then
reads:
my @tar_cmd = ('tar','-uf',$tarfile,$fullname);
$result = system(@tar_cmd);
This kinda works, in that the file is added to the tar file. But it's
added again every time the script is run.
-
Re: Problem with tar & Perl
On Sun, 25 Jul 2004 22:50:18 +0200, srm wrote:
> I'm trying to write a Perl script that archives some files in tar
> archives. I'm calling tar with Perl's system() function. The thing is,
> if the file that I'm about to archive is already in the tar file, I
> don't want to add it again - but this is precisely what's happening.
>
> I'm using tar with the -u switch, which should update files if they are
> not already in the tar file or have been changed. Instead, tar just adds
> another copy of the file. The modification dates of the original file
> and the version in the tar file do match, so that isn't the problem. Any
> ideas how I might get around this?
I've never used the -u option but I would experiment with tar on
the command line to make sure I knew for sure I was using it
correctly before dedicating anything to a script.
-
Re: Problem with tar & Perl
srm writes:
>
> I'm trying to write a Perl script that archives some files in tar
> archives. I'm calling tar with Perl's system() function. The thing is,
> if the file that I'm about to archive is already in the tar file, I
> don't want to add it again - but this is precisely what's happening.
Looks like a "tar" bug. If you try to update a file specified by a
full pathname without the "-P" flag so that "tar" gives the warning
message:
tar: Removing leading `/' from member names
then "tar" will always append the file to the end of the archive,
whether it has been modified or not.
As a workaround, you can either "chdir" to the root directory and
"tar" up your file without the leading slash or else use the "-P"
flag whenever you create or update the tar file.
--
Kevin
-
Re: Problem with tar & Perl
Kevin Buhr wrote:
> srm writes:
>
>>I'm trying to write a Perl script that archives some files in tar
>>archives. I'm calling tar with Perl's system() function. The thing is,
>>if the file that I'm about to archive is already in the tar file, I
>>don't want to add it again - but this is precisely what's happening.
>
>
> Looks like a "tar" bug. If you try to update a file specified by a
> full pathname without the "-P" flag so that "tar" gives the warning
> message:
>
> tar: Removing leading `/' from member names
>
> then "tar" will always append the file to the end of the archive,
> whether it has been modified or not.
>
> As a workaround, you can either "chdir" to the root directory and
> "tar" up your file without the leading slash or else use the "-P"
> flag whenever you create or update the tar file.
>
Thanks for that - I did wonder whether that would make a difference. In
the meantime, I'v changed my mind about how to handle this! What I'm
using this Perl script for is archiving emails. Each night, it searches
specified email directories, looks at each message, and copies any
messages older than 6 months to an archive directory, saving the
messages in separate sub-dirs for each month.
(One of the things I actually miss about Outlook is its archiving of
messages, as I need to do this for business reasons. Of course, Outlook
archived them into proprietary .pst files - achh-spit!)
In Kmail, I have the selected mail directories set to expire messages
after 9 months.
My plan was to tar and zip the archived files, but I've now decided that
I have more than enough space available on the archive drive (it's a
separate disk) to not worry about that. All I need do now is write, say,
a weekly cron job to tar/zip the archived files to a backup directory
and I should be good to go... there's always more than one way to do it,
after all.
@+
srm