【问题标题】:Django archive via crontab in production在生产中通过 crontab 进行 Django 归档
【发布时间】:2017-01-12 02:27:39
【问题描述】:

我无法让 crontab 使用 django-archive 执行站点备份。

crontab 文件:

0 5 * * * python ~/SBGBook/gbsite/manage.py archive

错误:

 Traceback (most recent call last):
     File "/home/jgates/SBGBook/gbsite/manage.py", line 17, in <module>
       "Couldn't import Django. Are you sure it's installed and "
    ImportError: Couldn't import Django. Are you sure it's installed and available $

如果我在gbsite/ 目录中,python manage.py archive 命令效果很好,但我猜这里存在某种路径问题。这一切都在生产服务器上的 venv 中运行。

【问题讨论】:

    标签: python django crontab dev-to-production


    【解决方案1】:

    尝试使用 virtualenv 中的 python 解释器:

    0 5 * * * /path/to/virtualenv/bin/python ~/SBGBook/gbsite/manage.py archive
    

    【讨论】:

    • 这是个好主意,虽然上面的 python 路径没有找到
    • @DeltaG 未找到?这个解释器的路径是什么?你能从你的 CLI 运行它并运行你想传递给 cron 的命令吗? (我怀疑是权限问题)。
    • 显然你的虚拟环境的路径会有所不同! :)
    • 没问题 - 只是我的一个错字。 :)
    猜你喜欢
    • 1970-01-01
    • 2022-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-23
    • 2012-03-23
    相关资源
    最近更新 更多