Running the script as what user? root? sudo for apache?
The backup routine (running under the user of the web server) must be able to create folders and files as well as remove them. If the backup fails there might be a directory by a hash name. It will look something like: 7dc0a71d3909e876d847e132782d4e9c
From the command line change into that directory and look around.
You might see something like:
activities files groups.xml outcomes.xml scales.xml
completion.xml files.xml moodle_backup.log questions.xml sections
course gradebook.xml moodle_backup.xml roles.xml users.xml
Notice the .log file and the most important file in there is moodle_backup.xml. IF one discovers what it's choking upon, one can edit the .xml files related, rebuild the files and folders as a .zip ... change the extension of the .zip to .mbz and believe it or not, restore it. If you can do that, the backup is good to archive.
Am assuming that your flavor of UNIX has a 'watch' command. To check, as root user: which watch.
If it shows a path to watch, one could do this ...
Use one terminal session to login as root user and change into the moodledata/temp/backup.
Then issue the watch command like so: watch "ls -lR" [ENTER]
In another terminal session logged on as root, run the automated backup script. Watch the watch window. Sometimes, actually watching the activity in the watch window one an get a clue even if it crashes before creating a .log file - which would have provided hints/clues.
'spirit of sharing', Ken