Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tar error: Unexpected EOF in archive when running via Cron/PHP

Tags:

php

tar

cron

I have a PHP console script that is called via cron which itself among other things creates a tar file of a directory.

When calling the PHP script via cron the the tar file is not created correctly. The following error is given when viewing the tar file:

gzip: stdin: unexpected end of file
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now

When calling the PHP script manually via console the tar file is created correctly. The cron log output shows no errors.

Here the tar call form the PHP script.

 exec("cd $this->backupTempFolderName/$id; tar -czf ../../$this->backupFolderName/$tarFileName $dbDumpFileName documents");

Dose anybody have an idea why the tar is created correctly when manually called and fails when called via cron?

Update: The error given while creating the tar file via cron is:

tar: ../../backup/20150819-060003.tar.gz: Wrote only 4096 of 10240 bytes
tar: Error is not recoverable: exiting now

Sometimes the error is:

tar: ../../backup/20150819-054002.tar.gz: Cannot write: Broken pipe
tar: Error is not recoverable: exiting now

As said before, the when executed via cron the tar file is created, but always 50% of the correct size (when manually executing the script):

-rw-r--r--  1 gtz gtz 1596099468 Aug 19 06:25 20150819-042330.tar.gz <- Manually called skript, working tar
-rw-r--r--  1 gtz gtz  858570752 Aug 19 07:21 20150819-052002.tar.gz <- Script called via cron, broken tar

Update 2

After doing some further research based on the input given here, might should add that the cron called script is running on a virtual private server - I suspect that some limitations may exist for cron jobs that are not documented by the hoster (only limit on minimum repetition time is given in the docs).

like image 245
wowpatrick Avatar asked Aug 17 '15 14:08

wowpatrick


1 Answers

That error comes usually from lack of disk space.

I would do some more researching on this subject, by adding some logs before and after the tar execution.

Also check what user your configuration is using for the cron job you have running the backup. It can be some quota limit on that user as well, that doesn't happen when you run on the console outside cron.

Ask your provider for quota limits on the VPS for users and for processes... That is what rings the bell here.

like image 91
prc Avatar answered Nov 12 '22 16:11

prc