Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

7 Answers 7

up vote 30 down vote accepted

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.

share|improve this answer
    
+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 Jul 29 '10 at 14:26

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 ...

share|improve this answer

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.

share|improve this answer
    
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 Oct 19 '13 at 12:14

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.

share|improve this answer

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.

share|improve this answer
2  
You 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 Oct 19 '13 at 12:40
    
See the GNU tar documentation and also for example Tru64 UNIX tar man page. –  pabouk Oct 19 '13 at 12:42
    
@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 May 29 at 13:46

You should have seen an error message while the program is running - perhaps you missed it?

If you want to see only error messages, try piping away stdout:

tar cvzf output.tgz input >/dev/null
share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.