Tar cf cannot archive files with a colon in their name

0

I'm currently working on a task of archiving an old web application. I made back-ups of the database and the application itself, now I'm trying to back-up the filestore that contains all uploaded files.

Unfortunately, said application hasn't always correctly handled uploaded files, which has resulted in a lot of files containing the full pathname on the client that uploaded them, for example "C:\test\test.doc".

I want to create a tar archive containing all the files, but tar cf gives errors on files having a colon in their name. I tried escaping, but no luck.

An example:

-rw-r--r-- 1 root root 29696 Jan  3 09:43 C:\test\test.doc

Just tar everything:

[root@server test]# tar cf test.tar *
tar: C\:\test\test.doc: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors

Surrounded by double quotes:

[root@server test]# tar cf test.tar "C:\\test\\test.doc"
tar: C\:\test\test.doc: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors

Using the escape character:

[root@server test]# tar cf test.tar C\:\\test\\test.doc
tar: C\:\test\test.doc: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors

Is there a way to achieve this (without file rename)?

verhage

Posted 2017-01-03T09:01:40.977

Reputation: 143

1Have you tried the first match on google for "tar escape colon" search? – Zumo de Vidrio – 2017-01-03T09:05:44.607

Yup, first hit is about extracting a tar file with a colon in its name ;) – verhage – 2017-01-03T09:13:42.087

Answers

3

Use . to archive the whole directory instead of *

tar cf ../test.tar .

Ipor Sircer

Posted 2017-01-03T09:01:40.977

Reputation: 3 578

1

The following also works (escape the \ inside single quotes):

$ touch 'C:\test\test.doc'
$ ls
C:\test\test.doc
$ tar cf test.tar 'C:\\test\\test.doc' 
$ tar tf test.tar 
C:\\test\\test.doc

dirkt

Posted 2017-01-03T09:01:40.977

Reputation: 11 627