tar: Exiting with failure status due to previous errors

229,852

Solution 1

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.

Solution 2

The problem is the f argument. It takes the next value as the filename, so it must be the last argument:

tar cvzf output.tgz folder

or:

tar -cvzf output.tgz folder

These are both the same and don't produce an error.

Solution 3

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

Solution 4

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.

Solution 5

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:
229,852

Related videos on Youtube

morpheous
Author by

morpheous

Updated on September 17, 2022

Comments

  • morpheous
    morpheous over 1 year

    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
    morpheous almost 14 years
    +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
  • pabouk - Ukraine stay strong
    pabouk - Ukraine stay strong over 10 years
    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 - Ukraine stay strong
    pabouk - Ukraine stay strong over 10 years
    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.
  • cwallenpoole
    cwallenpoole almost 10 years
    @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.
  • Jim Michaels
    Jim Michaels about 9 years
    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
  • whizcreed
    whizcreed over 8 years
    yes using sudo fixed the issue
  • Mian Asbat Ahmad
    Mian Asbat Ahmad about 6 years
    Solved my problem. I was trying tar -zcvfp giving error but when tried tar -zxvpf then all fine. Thanks.
  • scottysseus
    scottysseus almost 5 years
    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