Closed magsdev closed 3 years ago
Please run it with “bash”, not “sh”.
It is running bash...
On February 13, 2021, at 21:02, iRedMail notifications@github.com wrote:
Please run it with “bash”, not “sh”.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/iredmail/iRedMail/issues/111#issuecomment-778708389, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJTO6UJ5DZDQMMSZFCPX7WDS64VM7ANCNFSM4XSSG2BQ.
And cron: 30 3 * /bin/bash /var/vmail/backup/backup_mysql.sh
On February 13, 2021, at 21:02, iRedMail notifications@github.com wrote:
Please run it with “bash”, not “sh”.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/iredmail/iRedMail/issues/111#issuecomment-778708389, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJTO6UJ5DZDQMMSZFCPX7WDS64VM7ANCNFSM4XSSG2BQ.
Got it, it’s caused by empty value of variable “REMOVED_BACKUP_DIR”, will fix it soon.
Thank you very much for the feedback. :)
Could you please show me full output of commands below?
ls -l /bin/bash
bash -xv /var/vmail/backup/backup_mysql.sh
ls -l /bin/bash -rwxr-xr-x+ 1 root root 1183448 Jun 18 2020 /bin/bash
bash -xv /var/vmail/backup/backup_mysql.sh
###########################
########################### #
#
###########################
########################### #
#
#
#
#
#
#
#
#
#########################################################
#########################################################
KEEP_DAYS='90'
export BACKUP_ROOTDIR="/var/vmail/backup"
export MYSQL_ROOT_USER='root'
export MYSQL_DOT_MY_CNF='/root/.my.cnf'
export DATABASES='mysql vmail roundcubemail amavisd iredadmin sogo iredapd'
export DB_CHARACTER_SET="utf8"
#########################################################
######################################################### export PATH='/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin'
export CMD_DATE='/bin/date'
export YEAR="$(${CMD_DATE} +%Y)" ++ /bin/date +%Y
export BACKUP_SUCCESS='YES'
export BACKUP_DIR="${BACKUP_ROOTDIR}/mysql/${YEAR}/${MONTH}/${DAY}"
export REMOVE_OLD_BACKUP='NO'
export LOGFILE="${BACKUP_DIR}/${TIMESTAMP}.log"
${CMD_MYSQL} -e "show databases" &>/dev/null
mysql --defaults-file=/root/.my.cnf -uroot -e 'show databases' if [ X"$?" != X"0" ]; then echo "[ERROR] MySQL username or password is incorrect in file ${0}." 1>&2 echo "Please fix them first." 1>&2
exit 255 fi
[ ! -d ${BACKUP_DIR} ] && mkdir -p ${BACKUP_DIR} 2>/dev/null
echo "* Starting backup: ${TIMESTAMP}." >${LOGFILE}
echo "* Backing up databases: ${DATABASES}." >> ${LOGFILE}
echo '* Backing up databases: mysql vmail roundcubemail amavisd iredadmin sogo iredapd.' for db in ${DATABASES}; do
output_sql="${BACKUP_DIR}/${db}-${TIMESTAMP}.sql"
${CMD_MYSQL} -e "USE ${db}" &>/dev/null
if [ X"$?" == X'0' ]; then
${CMD_MYSQLDUMP} ${db} > ${output_sql}
chmod 0400 ${output_sql}
if [ X"$?" == X'0' ]; then
# Get original SQL file size
original_size="$(${CMD_DU} ${output_sql} | awk '{print $1}')"
# Compress
${CMD_COMPRESS} ${output_sql} >>${LOGFILE}
chmod 0400 ${output_sql}.*
if [ X"$?" == X'0' ]; then
rm -f ${output_sql} >> ${LOGFILE}
fi
# Get compressed file size
compressed_file_name="${output_sql}.${COMPRESS_SUFFIX}"
compressed_size="$(${CMD_DU} ${compressed_file_name} | awk '{print $1}')"
sql_log_msg="INSERT INTO log (event, loglevel, msg, admin, ip, timestamp) VALUES ('backup', 'info', 'Database: ${db}, size: ${compressed_size} (original: ${original_size})', 'cron_backup_sql', '127.0.0.1', UTC_TIMESTAMP());"
else
# backup failed
export BACKUP_SUCCESS='NO'
sql_log_msg="INSERT INTO log (event, loglevel, msg, admin, ip, timestamp) VALUES ('backup', 'info', 'Database backup failed: ${db}. Log: $(cat ${LOGFILE})', 'cron_backup_sql', '127.0.0.1', UTC_TIMESTAMP());"
fi
# Log to SQL table `iredadmin.log`, so that global domain admins can
# check backup status (System -> Admin Log)
${CMD_MYSQL} iredadmin -e "${sql_log_msg}"
fi done
echo -e "* File size:\n----" >>${LOGFILE}
echo "* Backup completed (Success? ${BACKUP_SUCCESS})." >>${LOGFILE}
if [ X"${BACKUP_SUCCESS}" == X'YES' ]; then echo "==> Backup completed successfully." else echo -e "==> Backup completed with !!!ERRORS!!!.\n" 1>&2 fi
if [ X"${REMOVE_OLD_BACKUP}" == X'YES' -a -d ${REMOVED_BACKUP_DIR} ]; then echo -e "* Old backup found. Deleting: ${REMOVED_BACKUP_DIR}." >>${LOGFILE} rm -rf ${REMOVED_BACKUP_DIR} >> ${LOGFILE} 2>&1
sql_log_msg="INSERT INTO log (event, loglevel, msg, admin, ip, timestamp) VALUES ('backup', 'info', 'Remove old backup: ${REMOVED_BACKUP_DIR}.', 'cron_backup_sql', '127.0.0.1', UTC_TIMESTAMP());"
${CMD_MYSQL} iredadmin -e "${sql_log_msg}"
fi
echo "==> Detailed log (${LOGFILE}):"
cat ${LOGFILE}
On Feb 15, 2021, at 09:53, iRedMail notifications@github.com wrote:
Could you please show me full output of commands below?
ls -l /bin/bash bash -xv /var/vmail/backup/backup_mysql.sh — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
Seems you upgraded this server from and old iRedMail release but didn't upgrade the backup_mysql.sh
script. This fix was introduced in iRedMail-1.1:
https://docs.iredmail.org/upgrade.iredmail.1.0-1.1.html#fixed-mysql-backup-script-doesnt-relies-on-python-anymore
No I installed from scratch
Sent from my iPad
On Feb 15, 2021, at 23:40, iRedMail notifications@github.com wrote:
Seems you upgraded this server from and old iRedMail release but didn't upgrade the backup_mysql.sh script. This fix was introduced in iRedMail-1.1: https://docs.iredmail.org/upgrade.iredmail.1.0-1.1.html#fixed-mysql-backup-script-doesnt-relies-on-python-anymore
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
But you are right, /var/mail is it’s own file system and came from a previous install - would have been better if scripts were not in this location
Sent from my iPad
On Feb 16, 2021, at 00:40, Magnus Larsson mlarsson@mserv.pw wrote:
No I installed from scratch
Sent from my iPad
On Feb 15, 2021, at 23:40, iRedMail notifications@github.com wrote:
Seems you upgraded this server from and old iRedMail release but didn't upgrade the backup_mysql.sh script. This fix was introduced in iRedMail-1.1: https://docs.iredmail.org/upgrade.iredmail.1.0-1.1.html#fixed-mysql-backup-script-doesnt-relies-on-python-anymore
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
This error happens from time to time, not always... Using iRedMail-1.3.2 on Ubuntu 20.04.2 LTS x86_64 - no additional information in the detailed log /var/vmail/backup/mysql/2021/02/13/2021-02-13-03-30-01.log
==> Backup completed successfully. /var/vmail/backup/backup_mysql.sh: line 197: [: argument expected ==> Detailed log (/var/vmail/backup/mysql/2021/02/13/2021-02-13-03-30-01.log):
File size:
44K amavisd-2021-02-13-03-30-01.sql.bz2 8.0K iredadmin-2021-02-13-03-30-01.sql.bz2 12K iredapd-2021-02-13-03-30-01.sql.bz2 104K mysql-2021-02-13-03-30-01.sql.bz2 4.0K roundcubemail-2021-02-13-03-30-01.sql.bz2 8.0K vmail-2021-02-13-03-30-01.sql.bz2
Line 197 of /var/vmail/backup/backup_mysql.sh: if [ X"${REMOVE_OLD_BACKUP}" == X'YES' -a -d ${REMOVED_BACKUP_DIR} ]; then