-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 
6
  • Why -1 without leaving a comment? Commented Mar 19, 2018 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 Commented Mar 19, 2018 at 13:44
  • ok I will now edit question Commented Mar 19, 2018 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 Commented Mar 19, 2018 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 Commented Mar 19, 2018 at 15:23

1 Answer 1

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.. 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.