通过crontab启动时,PHP脚本失败(“目录”

发布于 2025-01-31 05:31:11 字数 322 浏览 1 评论 0原文

我有一个PHP脚本创建MySQL转储,从浏览器启动时可以很好地工作。它通过exec()函数调用mysqldump。

我将此PHP脚本安排为 root (在Ubuntu VPS上)。以下错误消息失败:

sh:1:无法创建./backups/db_20220522.sql:目录nothxistent

i set_include_path('/var/www/mysite.com/');在我的PHP脚本的开头。脚本和“备份”目录在其中。

我想念什么?

非常感谢您的帮助

I have a PHP script creating a MySQL dump, working perfectly when launched from the browser. It calls mysqldump through the exec() function.

I scheduled this PHP script as root in the crontab (on an Ubuntu VPS). It fails with the following error message :

sh: 1: cannot create ./backups/db_20220522.sql: Directory nonexistent

I have set_include_path('/var/www/mysite.com/'); at the beginning of my PHP script. The script and the "backups" directory are in there.

What am I missing ?

Thanks a lot for your help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

熊抱啵儿 2025-02-07 05:31:11

您需要在脚本中指定备份目录的完整路径。
Cron从其他目录运行。

例如

/home/username/domains/domain.com/public_html/backup

You need the specify the full path to your backup directory in your script .
Cron runs from a different directory.

eg

/home/username/domains/domain.com/public_html/backup
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文