iredmail / iRedMail

Full-featured, open source mail server solution for mainstream Linux/BSD distributions.
https://www.iredmail.org/
GNU General Public License v3.0
1.45k stars 216 forks source link

/var/vmail/backup/backup_mysql.sh: line 197: [: argument expected #111

Closed magsdev closed 3 years ago

magsdev commented 3 years ago

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):

Line 197 of /var/vmail/backup/backup_mysql.sh: if [ X"${REMOVE_OLD_BACKUP}" == X'YES' -a -d ${REMOVED_BACKUP_DIR} ]; then

iredmail commented 3 years ago

Please run it with “bash”, not “sh”.

magsdev commented 3 years ago

It is running bash...

!/usr/bin/env 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.

magsdev commented 3 years ago

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.

iredmail commented 3 years ago

Got it, it’s caused by empty value of variable “REMOVED_BACKUP_DIR”, will fix it soon.

Thank you very much for the feedback. :)

iredmail commented 3 years ago

Could you please show me full output of commands below?

ls -l /bin/bash
bash -xv /var/vmail/backup/backup_mysql.sh
magsdev commented 3 years ago

ls -l /bin/bash -rwxr-xr-x+ 1 root root 1183448 Jun 18 2020 /bin/bash

bash -xv /var/vmail/backup/backup_mysql.sh

!/usr/bin/env bash

Author: Zhang Huangbin (zhb@iredmail.org)

Date: 16/09/2007

Purpose: Backup specified mysql databases with command 'mysqldump'.

License: This shell script is part of iRedMail project, released under

GPL v2.

###########################

REQUIREMENTS

########################### #

* Required commands:

+ mysqldump

+ du

+ bzip2 # If bzip2 is not available, change 'CMD_COMPRESS'

to use 'gzip'.

#

###########################

USAGE

########################### #

* It stores all backup copies in directory '/var/vmail/backup' by default,

You can change it in variable $BACKUP_ROOTDIR below.

#

* Set correct values for below variables:

#

BACKUP_ROOTDIR

MYSQL_ROOT_USER

DATABASES

DB_CHARACTER_SET

#

* Add crontab job for root user (or whatever user you want):

#

crontab -e -u root

1 4 * bash /path/to/backup_mysql.sh

#

* Make sure 'crond' service is running, and will start automatically when

system startup:

#

---- On RHEL/CentOS ----

chkconfig --level 345 crond on

/etc/init.d/crond status

#

---- On Debian/Ubuntu ----

update-rc.d cron defaults

/etc/init.d/cron status

#

#########################################################

Modify below variables to fit your need ----

#########################################################

Keep backup for how many days. Default is 90 days.

KEEP_DAYS='90'

Where to store backup copies.

export BACKUP_ROOTDIR="/var/vmail/backup"

MySQL username. Root user is required to dump all databases.

export MYSQL_ROOT_USER='root'

~/.my.cnf

export MYSQL_DOT_MY_CNF='/root/.my.cnf'

Databases we should backup.

Multiple databases MUST be seperated by SPACE.

export DATABASES='mysql vmail roundcubemail amavisd iredadmin sogo iredapd'

Database character set for ALL databases.

Note: Currently, it doesn't support to specify character set for each databases.

export DB_CHARACTER_SET="utf8"

#########################################################

You do NOT need to modify below lines.

######################################################### export PATH='/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin'

Commands.

export CMD_DATE='/bin/date'

Date.

export YEAR="$(${CMD_DATE} +%Y)" ++ /bin/date +%Y

Pre-defined backup status

export BACKUP_SUCCESS='YES'

Define, check, create directories.

export BACKUP_DIR="${BACKUP_ROOTDIR}/mysql/${YEAR}/${MONTH}/${DAY}"

Find the old backup which should be removed.

export REMOVE_OLD_BACKUP='NO'

Log file

export LOGFILE="${BACKUP_DIR}/${TIMESTAMP}.log"

Verify MySQL connection.

${CMD_MYSQL} -e "show databases" &>/dev/null

Check and create directories.

[ ! -d ${BACKUP_DIR} ] && mkdir -p ${BACKUP_DIR} 2>/dev/null

Initialize log file.

echo "* Starting backup: ${TIMESTAMP}." >${LOGFILE}

Backup.

echo "* Backing up databases: ${DATABASES}." >> ${LOGFILE}

Append file size of backup files.

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}):"

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.

iredmail commented 3 years ago

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

magsdev commented 3 years ago

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.

magsdev commented 3 years ago

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.