Search code examples
bashshellcrongreenplumhawq

PIVOTAL HAWQ Backup - shell script error


When I am trying to backup PIVOTAL HAWQ database using shell script.

Getting error :

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

Input shell script: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 : ENTRY FOR SHELL SCRIPT - */5 * * * * /home/gpadmin/backup_db.sh > /tmp/bkp.log

When running the shell manually dumping the data. But at the same time not working via crontab which runs every 5 minute.

Any help on it would be much appreciated.


Solution

  • You will need to source hawq binaries on your script if you run it from cron.

    #!/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/"