in reply to Re: Archive::Tar from somewhere outside my runtime directory
in thread Archive::Tar from somewhere outside my runtime directory

This is where my inexperience shows!
$tar->setcwd($vsvroot); foreach my $vsvxdb (<cntl/*>) { $tar->add_files($vsvxdb); } $tar->write("$vsvroot/tmp/cntlbkup.tar");
I thought from my reading of the doc that my $tar->setcwd would have caused tar to find all files in the $vsvroot/cntl directory then archive them in $vsvroot/tmp/cntlbkup.tar. I know those files exist but I don't get anything in the archive although the write statement does create it.

Replies are listed 'Best First'.
Re^3: Archive::Tar from somewhere outside my runtime directory
by GrandFather (Saint) on Dec 12, 2011 at 06:30 UTC

    Nope. Reading the docs it looks like setcwd is pure optimisation and that the cwd has to be set for relative paths to do what you expect. However there is an implication that absolute paths are unaffected by such silliness. So, you have two options ...

    True laziness is hard work
      It's working now - needs the chdir function, not tar->cwd!
      chdir($vsvroot); foreach my $vsvxdb (<cntl/*>) { $tar->add_files($vsvxdb); } $tar->write("$vsvroot/tmp/cntlbkup.tar");
      I think that the doc is actually telling me that tar->cwd is relevant only for extraction, not for creation.
        <lots of rude words of frustration!> It's NOT working. The example I had working was doing it running standalone but the production version has to run as a task called under another app. The code below never gets away from the application's run time directory even though they're both branches under the same root.
        $vsvroot = $config{$ServerX . "ROOT"}; chdir($vsvroot); MsgLog ("d", "vsvroot = $vsvroot"); MsgLog ("d", cwd()); foreach $vsvxdb (<cntl/*>) { MsgLog ("d", "Add $vsvxdb to tarfile\n"); if (! $tar->add_files($vsvxdb)) { MsgLog ("e", "Failed to add original $vsvxdb to backup + archive. Quitting.") } }
        The log shows...

        vsvroot = "C:\LRSROOT\vsvxroot"

        C:/LRSROOT/vpsxroot

        Add cntl/ckpt.dat to tarfile

        Which lines above correspond to the three MsgLog function calls in the sample code. Note that the vsvroot variable (I left the $ off in the log message) uses backslashes and points to the vsVxroot folder but the print of cwd() shows the vPsxroot folder - same parent, different subfolders. The perl code is called from and app who's root is vPsxroot. I've tried this with a simple test script and it definitely still calls tar from the working directory which is not changed by chdir(). I'm very confused!