Tar archive won't unpack – "Path contains '..'"

8

The name of the file 2014-12-12 04-00-01.tar. I executed the command:

tar xvf 2014-12-12\ 04-00-01.tar

The output is many lines of the form:

x ../server/: Path contains '..'

And then a few of the form:

tar: copyfile unpack (../server/logs/.DS_Store) failed: No such file or directory

It seems that I wasn't very careful when I wrote the backup script. How can I unpack the file?

Thom Smith

Posted 2014-12-15T01:34:19.590

Reputation: 617

Answers

11

You'll want to add the P (or -P) flag to your command line. From the manpage:

-P Preserve pathnames. By default, absolute pathnames (those that begin with a / character have the leading slash removed both when creating archives and extracting from them. Also, tar will refuse to extract archive entries whose pathnames contain .. or whose target directory would be altered by a symlink. This option suppresses these behaviors.

Try tar Pxvf 2014-12-12\ 04-00-01.tar. Note that you'll need write access to the parent directory of the working directory where you invoke the command.

zackse

Posted 2014-12-15T01:34:19.590

Reputation: 532

That did the trick! – Thom Smith – 2014-12-15T05:33:10.053

0

You could try:
mkdir ./dir
tar xvf 2014-12-12\ 04-00-01.tar -C --./dir

LDC3

Posted 2014-12-15T01:34:19.590

Reputation: 2 062

tar: could not chdir to '--./dir' – Thom Smith – 2014-12-15T03:21:59.517

Strange. Try tar xvf 2014-12-12\ 04-00-01.tar -C --dir instead. – LDC3 – 2014-12-15T04:11:19.647

What's the double-dash signify? – Xen2050 – 2014-12-15T05:44:28.027

It's in the man file, I think it indicates that the letters that follow are part of the command since you can have tar xv -C --dir -f --2014-12-12\ 04-00-01.tar – LDC3 – 2014-12-16T01:19:33.557