PIVOTAL HAWQ备份 - shell脚本错误

时间:2017-01-18 03:53:26

标签: bash shell crontab greenplum hawq

当我尝试使用shell脚本备份PIVOTAL HAWQ数据库时。

获取错误:

/home/gpadmin/backup_db.sh: line 12: pg_dump: command not found

输入shell脚本:backup_db.sh

#!/bin/bash
# Location to place backup.
backup_dir="/home/backup/"
#String to append at the name of the backup files
backup_date=`date +%d-%m-%Y`
#Numbers of days we want to keep copy databases
number_of_days=7
databases=(prod test gpadmin)
for i in ${databases[@]}; do
  if [ "$i" != "template0" ] && [ "$i" != "template1" ]; then
    echo Dumping $i to $backup_dir$i\_$backup_date
    pg_dump $i|gzip > $backup_dir$i\_$backup_date.gz
  fi
done
find $backup_dir -type f -prune -mtime +$number_of_days -exec rm -f {} \;

CRONTAB: 输入SHELL SCRIPT - * / 5 * * * * /home/gpadmin/backup_db.sh> /tmp/bkp.log

运行shell时手动转储数据。但同时不能通过每5分钟运行一次的crontab工作。

对此有任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

看起来像PATH的问题是crontab找不到pg_dump二进制文件。请尝试使用pg_dump(usr / local / hawq / bin / pg_dump)的绝对路径运行脚本。

您也可以在调用pg_dump调用之前获取/usr/local/hawq/greenplum_path.sh。

答案 1 :(得分:1)

如果从cron运行它,则需要在脚本上获取hawq二进制文件。

#!/bin/bash
# Source hawq binaries
. /usr/local/hawq/greenplum_path.sh  #Change into your exact binaries location

# Location to place backup.
backup_dir="/home/backup/"