从cron运行rethinkdb-dump的问题

时间:2015-09-25 15:08:06

标签: python bash cron rethinkdb

我正在尝试设置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环境问题,但我无法弄清楚如何让它快乐...想法?救命啊!

2 个答案:

答案 0 :(得分:6)

当您从该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等)

答案 1 :(得分:0)

用于Windows的python安装程序将脚本和程序包安装在以下子文件夹中:

$env:APPDATA\Python\Python37 for powershell

%APPDATA%\Python\Python37 for cmd

cd此目录查看 /脚本 / site-packages pip软件包