-1

I have a shell script that I got from trante's answer in:

Linux shell script for database backup

The script runs correctly from the command line and creates the mysql backup.

However when it runs from a cron job the script executes and creates a the mysqldump file but the file is empty.

I have tried setting the PATH environment in the script but nothing I have tried works.

Regards

EDIT:

Adding script

#!/bin/sh
now="$(date +'%d_%m_%Y_%H_%M_%S')"
filename="db_backup_$now".gz
backupfolder="/mybackupfolder"
fullpathbackupfile="$backupfolder/$filename"
logfile="$backupfolder/"backup_log_"$(date +'%Y_%m')".txt
echo "mysqldump started at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile"
mysqldump --user=myuser --password=mypassword --default-character-set=utf8 mydatabase | gzip > "$fullpathbackupfile"
echo "mysqldump finished at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile"
chown myuser "$fullpathbackupfile"
chown myuser "$logfile"
echo "file permission changed" >> "$logfile"
find "$backupfolder" -name db_backup_* -mtime +8 -exec rm {} \;
echo "old files deleted" >> "$logfile"
echo "operation finished at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile"
echo "*****************" >> "$logfile"
exit 0
LiquidLunch
  • 47
  • 1
  • 7
  • Why -1 without leaving a comment? – LiquidLunch Mar 19 '18 at 13:36
  • Because if you need help to debug a script, then don't paste link of a entire post (even not linked to the good answer) but code **as text** in **your original post** – Gilles Quénot Mar 19 '18 at 13:44
  • ok I will now edit question – LiquidLunch Mar 19 '18 at 13:47
  • If you don't have time to spend to provide full informations, not sure you will get any help. You tell about fixing PATH, but **nothing related here** – Gilles Quénot Mar 19 '18 at 14:56
  • Not a question of time. I spent hours already ;). I have tried adding this to the script: PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin and other variants like PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/pathToMyScript – LiquidLunch Mar 19 '18 at 15:23
  • I just meant that it doesnt seem related to the PATH as the script executes. But the mysqldump part doesnt work – LiquidLunch Mar 19 '18 at 15:24

1 Answers1

1

Finally I found the solution.

You have to put the path to mysql in the following line:

mysqldump --user=myuser --password=mypassword..

Which in my case is:

/opt/bitnami/mysql/bin/mysqldump --user=myuser --password=mypassword..
LiquidLunch
  • 47
  • 1
  • 7