I've written a php script that creates a backup of a mysql database and set it to run daily using crontab on Ubuntu server, but the script is never executed (at least so it seems).
- The script is called backup.php.
- It generates a backup (sql within a gz archive) and stores it in folder /backup.
- It adds a few lines of text to /backup/log.txt.
The script is called in crontab for root user like this (sudo crontab -e):
* * * * * php -f /var/www/cmdb/backup.php
(Time needs to be adjusted, but this is for testing purposes.)
Nothing happens. No file gets created, no log gets modified.
However, all of the following tests succeed:
- Running the script directly in the console using
php backup.php - Running cron job:
* * * * * php -v > /var/www/cmdb/backup/php-v.txt - Running cron job:
* * * * * php -f /var/www/cmdb/test.php > /var/www/cmdb/backup/text.txt(writing a string to a file)
I think these tests indicate that:
- backup.php script works without error
- Cron is running
- The backup folder is writeable
- PHP command is accessible from crontab
So, why isn't backup.php doing anything when run from crontab?