Attempting to use cfexecute to run a shell script to back up databases.
This has worked successfully for years and years prior to upgrading to Lucee 5
There are two scripts I can choose from.
SCRIPT 1: automysql backup - an old program that still works
CALL FROM COMMAND LINE: automysqlbackup
For years, I have used this:
<cfexecute name="/usr/local/bin/automysqlbackup" arguments="" timeout="60" />
Lucee says:
/usr/local/bin/automysqlbackup: line 835: 6: Bad file descriptor
/usr/local/bin/automysqlbackup: line 836: 7: Bad file descriptor
Why the line numbers? I have no idea. The CFM file only contains one line (cfexecute)
SCRIPT 2: generic backup script - named it “hello.sh”
CALL FROM COMMAND LINE: ./hello.sh
Here is the complete script, attempting to trigger mysql dump via cfexecute. Permissions in the shell script are set correctly.
If I call the script from the command line, it works no problem. I can give the shell script any permissions needed, but it doesn’t work when called from cfexecute. And I have made sure the script is executable.
The script is at the root of the system simply to make testing easy. So /hello.sh is correct.
<cfexecute name="/hello.sh" arguments="" timeout="15" errorVariable="returnedError"></cfexecute>
Lucee says:
Permission denied mysqldump:
Content of Hello.sh
#!/bin/bash
################################################################
##
## MySQL Database Backup Script
## Written By: Rahul Kumar
## URL: https://tecadmin.net/bash-script-mysql-database-backup/
## Last Update: Jan 05, 2019
##
################################################################
export PATH=/bin:/usr/bin:/usr/local/bin
TODAY=`date +20%y%m%d-%H%M%S`
################################################################
################## Update below values ########################
DB_BACKUP_PATH='/path/to/my/backups/dbname'
MYSQL_HOST='127.0.0.1'
MYSQL_PORT='3306'
MYSQL_USER='user'
MYSQL_PASSWORD='password'
DATABASE_NAME='dbname'
BACKUP_RETAIN_DAYS=30 ## Number of days to keep local backup copy
#################################################################
#mkdir -p ${DB_BACKUP_PATH}/${TODAY}
echo "Backup started for database - ${DATABASE_NAME}"
mysqldump -h ${MYSQL_HOST} \
-P ${MYSQL_PORT} \
-u ${MYSQL_USER} \
-p${MYSQL_PASSWORD} \
${DATABASE_NAME} | gzip > ${DB_BACKUP_PATH}/${DATABASE_NAME}-${TODAY}.sql.gz
if [ $? -eq 0 ]; then
echo "Database backup successfully completed"
else
echo "Error found during backup"
fi
##### Remove backups older than {BACKUP_RETAIN_DAYS} days #####
DBDELDATE=`date +"%d%b%Y" --date="${BACKUP_RETAIN_DAYS} days ago"`
if [ ! -z ${DB_BACKUP_PATH} ]; then
cd ${DB_BACKUP_PATH}
if [ ! -z ${DBDELDATE} ] && [ -d ${DBDELDATE} ]; then
rm -rf ${DBDELDATE}
fi
fi
### End of script ####