TAR error — `wp-content: file changed as we read it`

Background

I have a bash alias I use to back up a Wordpress home folder. The command is run from /home/waiheke26/sites/

The command is:

tar --exclude='./wp-content/uploads' \ --exclude='./wp-content/cache' \ --exclude ='./cache' \ --exclude='./wp-content/backups' \ --exclude='./wp-snapshots' \ --exclude='./wp-content/envato-backups' \ -zcf \ /home/waiheke26/sites/(date +%Y-%m-%d-%H.%M.%S).tar.gz \ . \ && echo "File backup OK" || echo "File backup failed"';

The Issue

Recently, when I run the command I get the error:

tar: ./wp-content: file changed as we read it
File backup failed

Much of what I've seen online regarding this file changed as we read it error suggests it is because the user is creating the tar file within the directory being archived. In my case that does not apply, as the tar file is being created elsewhere.

Question

How can I determine the cause of this error?

6

1 Answer

So, sidestepping digging into what is changing wp-content while tar is working for a moment because of the stated sensitivity of your env.. which, speculatively, i might mess with watching lsof during the operation.

If you can spare the space in your environment, you can keep an "offline" copy of your public up to date using something like this:

rsync -va /home/asdf/public/ /home/asdf/backups/public/ --delete

It will run quickly after the initial copy, because it will only copy diffs. You could consider adding --exclude options here to save the work of copying files you will exclude from the archive anyway.

Then, make your tar archive as before, backups/public as source:

tar --exclude='./whatever' \ -zcf \ /home/asdf/backups/wp-files-$(date +%Y-%m-%d-%H.%M.%S).tar.gz \ /home/asdf/backups/public \ && echo "File backup OK" || echo "File backup failed"';

This effectively gives tar an environment where nothing will change while it's running, as others have suggested.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like