tar: Exiting with failure status due to previous errors

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.


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.


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