Skip to main content
 首页 » 编程设计

python之从 cron 运行 rethinkdb-dump 的问题

2025年05月04日15yxwkf

我正在尝试设置 rethinkdb 的定期备份,但总是遇到问题。如何设置 rethinkdb-dump 从 cron 运行?

这是我的脚本:

$ cat backup.sh  
#!/bin/bash 
NOW=$(date +"%Y-%m-%d-%H-%M") 
 
/usr/bin/rethinkdb dump -e my_db -f /root/db_backup/$NOW.tar.gz 

当我手动运行时,脚本运行得很好。但是,当尝试从 cron 运行它时它不起作用,我在 stderr 得到以下信息:

Error when launching 'rethinkdb-dump': No such file or directory 
The rethinkdb-dump command depends on the RethinkDB Python driver, which must be installed. 
If the Python driver is already installed, make sure that the PATH environment variable 
includes the location of the backup scripts, and that the current user has permission to 
access and run the scripts. 
Instructions for installing the RethinkDB Python driver are available here: 
http://www.rethinkdb.com/docs/install-drivers/python/ 

这似乎是一个 Python 环境问题,但我不知道如何让它开心……有什么想法吗?帮助!

请您参考如下方法:

当您从该 backup.sh 脚本运行它时,它可能会在没有正确设置 PATH 的情况下运行,并且无法找到 rethinkdb-dump 的 PATH。

首先,让我们找出 rethinkdb-dump 在哪里

which rethinkdb-dump 
(on my pc, I guess it's very different on your pc) 
/usr/local/bin/rethinkdb-dump 

现在,尝试将 PATH 附加到您的脚本 backup.sh

#!/bin/bash 
export PATH="$PATH:/path/to/folder/contain-rethinkdb-dump" 
# The rest of your script normally 

所以拿我的例子来说,我会这样说:

export PATH="$PATH:/usr/local/bin" 

我认为您的 rethinkdb-dump 位于普通 bin 文件夹之外(/usr/bin、/usr/local/bin 等)