Force tar to ignore/skip errors while compressing files

tar

Let's say I do this tar cfzp home.tar.gz /home (takes a while) and a file changes during compression and tar fails, I get "file changed as we read it" and tar stops. I assume home.tar.gz is now incomplete, or was that just the "notice" and not really an error?

Is there some kind of "force" option to make tar finish its work and not abort on errors?

Edit/update: I found "–ignore-failed-read do not exit with nonzero on unreadable files" and at least I think it's working. But need to be careful with the order of the parameters because you can end up with a tar file called "–ignore-failed-read"

Do I need to ignore anything else?

Update: Without "–ignore-failed-read" tar will keep going if a file has been removed "File removed before we read it". However, I think it might be aborting on the "file changed as we read it" error but I don't really know. Hard to compare the archive to the "original" as I have cache files that come and go, etc.

Update: Upon closer observation "file changed as we read it" is more like a notice, it appears tar will keep going if files change while tar is doing its business. But I'll leave the answer open, maybe someone more experienced can add more insight.

Best Answer

Your assumption is correct, "File changed as we read it" is a notice, usually related to files in use (i.e. written to during the creation process) while tar is creating the archive. If consistency is vital, you're better off rsyncing the contents elsewhere i.e.

rsync -avz /my/home/ /somebackupdir/my/home/  # initial sync, followed by 
rsync -avz /my/home/ /somebackupdir/my/home/  # any subsequent sync, repeated
                                              # as often as you feel necessary

This gives you the benefit of having a backup location that will only need to update the diffs before creating the tarball.

Related Topic