Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding --ignore-failed-read to tar causes "unknown function modifier" error

Tags:

unix

tar

backup

I'm using the tar command in UNIX to perform backups of particular directories. However, some directories contain files/sub-directories which the current user doesn't have any read permissions on. As a result the tar command is returning a non 0 exit code.

I came across the following modifier in the man pages '--ignore-failed-read', which suppresses the non 0 exit code when encountering files it cannot read. However, whenever I try using it I get the error 'unknown function modifier'.

Could anyone help me out here?

my tar command looks something like this:

tar --create --ignore-failed-read --file=test.tar my_dir
like image 205
user1896168 Avatar asked Oct 30 '13 09:10

user1896168


2 Answers

Your command seems to be perfectly valid and I don't see any typos/mistakes. To be absolutely sure, I just tried it on my VM running under 32 bit Debian 7.1 (wheezy) with stock kernel 3.2.0.4. As I suspected, archive has been created successfuly (the only change was, of course, the name of the source directory). I also checked version of my tar with

tar --version

which gave me following output:

tar (GNU tar) 1.26

First of all, you should check this info. If you get the same (with possible difference in version number) output, that's fine. If not (or version that seems much older), it's possible, that you are using tar, which simply doesn't support this feature.

Also, you can check, if your tar really DOES support mentioned flag. To do this, type into console:

tar --help | grep ignore-failed-read

You should see something like this:

--ignore-failed-read   do not exit with nonzero on unreadable files

If output stays empty, that means this version of tar does not know this flag at all.

See if any of the above helps.

like image 82
Mateusz Grzejek Avatar answered Nov 14 '22 08:11

Mateusz Grzejek


Another option that might work better in this case is --warning=no-file-changed.

tar --warning=no-file-changed -czf backup.tgz dir1 dir2

--warning controls the display of warning messages. You can add no- to the message keyword to suppress it. So in this case no-file-changed suppresses the file-changed warning.

c.f. https://www.gnu.org/software/tar/manual/html_section/tar_27.html

like image 35
Cully Avatar answered Nov 14 '22 09:11

Cully