Thesqldump error on bash script

backupMySQLmysqldump

I'm trying to run a bash script to backup my database with Cronjob.

# Backup and compress each database
for database in $mysql_databases
do
  if [ "${database}" == "information_schema" ] || [ "${database}" == "performance_schema" ]; then
        additional_mysqldump_params1="--single-transaction"
  else
        additional_mysqldump_params=""
  fi
  echo "Creating backup of \"${database}\" database"
  mysqldump ${additional_mysqldump_params} --user=${mysql_user} --password=${mysql_password} ${database} | gzip > "${backup_dir}/${database}.gz"
  chmod 600 "${backup_dir}/${database}.gz" ${additional_mysqldump_params1}
done

but the --single-transaction option is not recognized

Best Answer

OBSERVATION #1

It is not recognized because of a typo

You have

  if [ "${database}" == "information_schema" ] || [ "${database}" == "performance_schema" ]; then
        additional_mysqldump_params1="--single-transaction"
  else
        additional_mysqldump_params=""
  fi

It should be

  if [ "${database}" == "information_schema" ] || [ "${database}" == "performance_schema" ]; then
        additional_mysqldump_params="--single-transaction"
  else
        additional_mysqldump_params=""
  fi

Please change the additional_mysqldump_params1 to additional_mysqldump_params

OBSERVATION #2

You have

chmod 600 "${backup_dir}/${database}.gz" ${additional_mysqldump_params1}

It should read

chmod 600 "${backup_dir}/${database}.gz"

Please remove additional_mysqldump_params1 from that line of code

OBSERVATION #3

There is no need to mysqldump information_schema or performance_schema databases

  • The INFORMATION_SCHEMA database is made of up in-memory temporary tables. They are dynamically generated and populated on mysqld startyo.
  • The PERFORMANCE_SCHEMA database is for the instrumentation of measuring performance. Each individual MySQL instance is responsible for populating it with instrumentation data when it is in use.