Im running a php backup script to backup a website(files and database). I can directly call the script in a browser and the script will run fine with all backups created. When I schedule and run the script via a cron job I get the errors below.
Warning: opendir(…/wp-content/uploads/): failed to open dir: No such file or directory in /home/site/public_html/batch_script/functions.php on line 465
Warning: opendir(…/wp-content/themes/): failed to open dir: No such file or directory in /home/site/public_html/batch_script/functions.php on line 465
Warning: opendir(…/wp-content/plugins/): failed to open dir: No such file or directory in /home/site/public_html/batch_script/functions.php on line 465
Warning: fopen(backup/backup-21-10-10 03-44-01.zip): failed to open stream: No such file or directory in /home/site/public_html/batch_script/backup.php on line 121
Warning: fwrite(): supplied argument is not a valid stream resource in /home/site/public_html/batch_script/backup.php on line 122
Warning: fclose(): supplied argument is not a valid stream resource in /home/site/public_html/batch_script/backup.php on line 123
Thanks got rid of that message, now I get the below message, ive tried adding a local php.ini file but that doesnt reslove the error.
;; set memory limit for functions.php
memory_limit = 64M
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 14167822 bytes) in /home/site/public_html/batch_script/functions.php on line 110
When you run a program from the command line, any relative paths accessed are relative to the current working directory of the user executing the program. When cron runs your script, its current working directory is not the root of your website, so “…/wp-content” for example does not exist.
Within the code of your backup script, specify the full absolute paths to all files you are going to open.