skip to Main Content

The script in file modBackup.sh does not run completely when started by cron, the result is a corrupted tar.gz file that is half the size of this one if I run manually. In any case, its size is many times smaller than the one started manually, but still creates some content that can not be opened normally, archive is damaged

file modBackup.sh:

 #!/bin/sh
    find /home/share/ -mmin -720 -type f -exec tar -rvf /mnt/archives/`date +%F`-modified.tar.gz "{}" +

Тhe behavior of the automatic one seems to be interrupted and does not end.
When I run it manualy, the script creates a genuine archive as [current date]-modified.tar.gz

Here is the crontab -e:

00 18 * * 1-5 /home/myScripts/modBackup.sh

Edit:
There is no information in the logs except that crond has started
neither in the mail log, nor in the cron, nor in the messages
(I use very old CentOS 🙁 but I don’t think this is the reason for the error).
For testing only: I added %H%M of the file name in the script and did the following:
I ran it manually: sh /home/myScripts/modBackup.sh
and set with crontab -e to run a two minutes later the same command

After a few minutes, two files appeared that grew at the same time, but then the one created by cronjob
stopped growing
(two files).
I use the same GUI tool (Archive Manager) to open in both cases.
Тhe file, created by manually starting the script, opens (manually started), but the other one, from cronjob cannot, even after I changed the extension, the error is ‘unexpected EOF in archive’ (auto started)

2

Answers


  1. Chosen as BEST ANSWER

    I found that in the cron environment the "find" command misinterprets filenames containing specific characters, even with the explicit change of the encoding with add at the beginning of the script line "export LANG = en_US.UTF-8; LC_CTYPE=...". With many other combinations and attempts I had no success. That's why I left the "find" command and use the tar command with an option to archive modified files. This way works perfect now:

    fromDate = $(date --date = '15 hours ago')
    
    /bin/tar -N "$fromDate" -zcf /mnt/archives/`date +% F-% H% M`-share.modified.tar.gz /home/share/
    

  2. Suggesting to include the users’s environment context with $PATH and other critical environment variables for the application to work.:

    modBackup.sh:

    #!/bin/sh
    
    source ~/.profile
    find /home/share/ -mmin -720 -type f -exec tar -rvf /mnt/archives/`date +%F`-modified.tar.gz "{}" +
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search