tar: Exiting with failure status due to previous errors

84

21

I have written a little script that tars and compresses a list of directories + files.

The script appears to run succesfully, in that a useable .tar.gz file is created after the script runs.

However, I get this annoying message after the script finishes:

tar: Exiting with failure status due to previous errors

I do not see any error messages whilst the script is working, and like I said, the produced file can be uncompressed with no warnings/errors. Since I am using this as part of my backup, I want to make sure that I am not ignoring something serious.

What are the possible reasons that this error/warning message is being produced - and can I safely ignore it?. If I cant ignore it, what are the steps to diagnose and resolve the error?

I am running on Ubuntu 10.0.4

morpheous

Posted 2010-07-29T07:17:55.313

Reputation: 3 533

Answers

106

You will get that message if, for any reason, tar can't add all of the specified files to the tar. One if the most common is not having read permission on one of the files. This could be a big problem since you are using this for backup. If you are using the -v flag, try leaving it off. This should reduce the output and let you see what is going on.

KeithB

Posted 2010-07-29T07:17:55.313

Reputation: 8 506

yes using sudo fixed the issue – whizcreed – 2015-11-17T12:44:05.250

8+1 for the suggestion (I was using the 'verbose' option previously). I found that there was a permission issue on at least one of the files. At least now I know how to resolve this. many thanks – morpheous – 2010-07-29T14:26:18.540

ditching the -v flag is great advice and helped me solve my problem. 'verbose' obscures the cause of the failure behind a wall of text – scottyseus – 2019-07-01T15:43:18.433

23

the problem is the argument, f argument take the next as the filename, so it must be the last of argument

tar cvzf output.tgz folder

or

tar -cvzf output.tgz folder

is the same and no take error.

Andrea Monni

Posted 2010-07-29T07:17:55.313

Reputation: 231

Solved my problem. I was trying tar -zcvfp giving error but when tried tar -zxvpf then all fine. Thanks. – Mian Asbat Ahmad – 2018-02-27T10:28:56.380

6

Sometimes backing up files that might change during the backup like logfiles, you might find useful the tar option '--ignore-failed-read' (I'm on Debian Linux, not sure for non gnu tar).

Standard output and error can be redirected in 2 different files with something like:

LOGDIR='/var/log/mylogdir' 
LOG=${LOGDIR}/backup.log 
ERRLOG=${LOGDIR}/backup.error.log 
DATE=$(date +%Y-%m-%d)
HOSTNAME=$(hostname)
DATA_DIRS='/etc /home /root'

tar --ignore-failed-read -f ${BACKUP_DIR}/${HOSTNAME}-${DATE}.tgz -cvz ${DATA_DIRS} > $LOG 2> $ERRLOG

I find this to be generally safe, but please be careful though as tar won't stop ...

Fabio Pedrazzoli

Posted 2010-07-29T07:17:55.313

Reputation: 171

5

I was having the same issue and none of the above answers worked for me. However, I found that running the following command worked:

tar -cpzf /backups/fullbackup.tar.gz --exclude=backups --exclude=proc --exclude=tmp --exclude=mnt --exclude=sys --exclude=dev --exclude=run /

The errors that were being referred to in tar: Exiting with failure status due to previous errors can be identified by turning off the -v option. Upon review, the errors came from directories like /run and /sys.

By excluding these directories, it works just fine. Hope this helps anyone with a similar issue.

DomainsFeatured

Posted 2010-07-29T07:17:55.313

Reputation: 179

3

I had the same problem. All i did was to remove the dash ("-") from the command.

Instead of typing it as

tar -cvfz output.tar.gz folder/

try typing it as

tar cvfz output.tar.gz folder/

I am unaware of why the dash was causing problems in my case but at least it worked.

jack

Posted 2010-07-29T07:17:55.313

Reputation: 31

I also had problems, but it was a file with the name -v so apparently tar has some bugs with regards to what files it can backup... this should not be a problem. my workaround since rm and mv would not work, was to use a file manager. so apparently mv and rm are buggy too. i tried mv '-v' v and rm '-v' but got error messages. tar mentioned it could not stat the tar file. was using -cfjv – Jim Michaels – 2015-03-15T05:15:27.600

6You probably tested this with GNU tar. Your confusion comes from the fact that it accepts two different styles of options - the "old-style" tar options without a dash and the "standard unix" options with a dash. The options with dash require an argument of an option to follow the option. So in this case the argument for -f should be output.tar.gz and there must not be z in between. Without re-ordering of the options it would correctly be: tar -cvf output.tar.gz -z folder/. The old style expects all the options in one place and all the arguments follow. – pabouk – 2013-10-19T12:40:11.987

See the GNU tar documentation and also for example Tru64 UNIX tar man page.

– pabouk – 2013-10-19T12:42:14.497

@pabouk That comment seemed worthy of being an answer by itself. Please add the contents of that comment as an answer to this question so that credit goes where credit is due.

– cwallenpoole – 2014-05-29T13:46:20.483

2

You have misunderstood an earlier answer. The problem is not the -, it is where the f is in your argument list.

tar cvfz target.tgz <files>

Will try to create an archive called "z", as that is the text after f. The error message is because tar can't find "target.gz" to add to archive "z".

tar cvzf target.tgz <files>

Will correctly create target.tgz and add files to it. This is because target.tgz is the first text after the f argument.

Thornbury

Posted 2010-07-29T07:17:55.313

Reputation: 21

This should be added as a comment to the "confused" reply. Unfortunately you will be allowed to add such comments only after gaining 50 points of reputation. To the subject: Did you test it? I tested it with GNU tar 1.26 and the variants with and without dash are really different as described in the reply of jack. It behaves as it is written in the reply. – pabouk – 2013-10-19T12:14:26.907

0

I had a similar issue untarring a file I had received. Turns out I didn't have permission to write the files in the archive owned by root. Using sudo fixed it.

ttwalkertt

Posted 2010-07-29T07:17:55.313

Reputation: 1

0

One of the reason to get this errors for beginners is that
They forget to perform operations in the directory where the files are present
Go to that location and perform the command 
As my files are in desktop 
~/Desktop# tar - cf done.tar abc xyz
Where xyz and abc are files and we are storing those files in done.tar
If we go and perform the command in other location we will get above error 

Ravi Teja Mureboina

Posted 2010-07-29T07:17:55.313

Reputation: 1

0

Usually you can ignore that message. If there are any changes (such as file deletions/creations/modifications) to underlying directory tree during tar creation, it will throw that message. Also if there special files like device nodes, fifos and so on, they will cause that warning.

Are you sure you can't see any culprit files? Try with tar cvfz yourtarball.tgz /your/path

Janne Pikkarainen

Posted 2010-07-29T07:17:55.313

Reputation: 6 717