Added MYSQL_BIN, MYSQLADMIN_BIN and MYSQLADMIN_BIN variables
This commit is contained in:
parent
94eaf90c4f
commit
6c2e48b783
|
@ -29,6 +29,7 @@
|
|||
# #
|
||||
##############################################################################################
|
||||
# #
|
||||
# 2021/07/26 1.9 Added MYSQL_BIN, MYSQLADMIN_BIN and MYSQLADMIN_BIN variables #
|
||||
# 2020/12/30 1.8 Added DBS_SKIP to prevent dumping certain databases #
|
||||
# 2020/02/27 1.7 Added username and password and set default retention to 1 day #
|
||||
# 2019/01/28 1.6 Fixed backups of databases with dash (-) in name #
|
||||
|
@ -95,6 +96,11 @@ if [ "$?" == "0" ]; then
|
|||
USE_MYDUMPER=1
|
||||
fi
|
||||
|
||||
# Set paths
|
||||
MYSQL_BIN=$(which mysql)
|
||||
MYSQLADMIN_BIN=$(which mysqladmin)
|
||||
MYSQLDUMP_BIN=$(which mysqldump)
|
||||
|
||||
# Check if MYSQL_USER or MYSQL_PW is set and set options accordingly
|
||||
MYSQL_OPTS=""
|
||||
|
||||
|
@ -111,7 +117,7 @@ MYSQL_OPTS="${MYSQL_OPTS} -p${MYSQL_PW}"
|
|||
fi
|
||||
# Get list of Databases except the pid file
|
||||
DBS_SKIP="'performance_schema','information_schema'"
|
||||
DBS_LIST=$(mysql ${MYSQL_OPTS} -s -N -e "SELECT schema_name FROM information_schema.schemata WHERE schema_name NOT IN (${DBS_SKIP});")
|
||||
DBS_LIST=$(${MYSQL_BIN} ${MYSQL_OPTS} -s -N -e "SELECT schema_name FROM information_schema.schemata WHERE schema_name NOT IN (${DBS_SKIP});")
|
||||
|
||||
index=0
|
||||
# Check if we can connect to the mysql server; otherwise die
|
||||
|
@ -119,7 +125,7 @@ if [ ! "$(id -u -n)" = "root" ]; then
|
|||
echo -e "Error: $0 : Only user 'root' can run this script"
|
||||
exit 100
|
||||
fi
|
||||
mysqladmin ${MYSQL_OPTS} status >> /dev/null 2>&1
|
||||
${MYSQLADMIN_BIN} ${MYSQL_OPTS} status >> /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Unable to connect to MySQL Server, exiting!"
|
||||
exit 101
|
||||
|
@ -129,7 +135,7 @@ fi
|
|||
START_DATETIME=$(date +%Y%m%d-%H%M)
|
||||
|
||||
# Flush logs prior to the backup.
|
||||
mysql ${MYSQL_OPTS} -e "FLUSH LOGS"
|
||||
${MYSQL_BIN} ${MYSQL_OPTS} -e "FLUSH LOGS"
|
||||
|
||||
if [ $USE_MYDUMPER -eq 1 ]; then
|
||||
# Use mydumper
|
||||
|
@ -145,10 +151,10 @@ else
|
|||
[ ! -d ${DB_BKP_FLDR} ] && mkdir -p ${DB_BKP_FLDR} && chmod 700 ${DB_BKP_FLDR}
|
||||
# Get the schema of database with the stored procedures.
|
||||
# This will be the first file in the database backup folder
|
||||
mysqldump ${MYSQL_OPTS} -R -d --single-transaction ${DB} | gzip -c > ${DB_BKP_FLDR}/000-DB_SCHEMA.sql.gz
|
||||
${MYSQLDUMP_BIN} ${MYSQL_OPTS} -R -d --single-transaction ${DB} | gzip -c > ${DB_BKP_FLDR}/000-DB_SCHEMA.sql.gz
|
||||
index=0
|
||||
#Get the tables and its type. Store it in an array.
|
||||
table_types=($(mysql ${MYSQL_OPTS} -e "show table status from \`${DB}\`" | awk '{ if ($2 == "MyISAM" || $2 == "InnoDB") print $1,$2}'))
|
||||
table_types=($(${MYSQL_BIN} ${MYSQL_OPTS} -e "show table status from \`${DB}\`" | awk '{ if ($2 == "MyISAM" || $2 == "InnoDB") print $1,$2}'))
|
||||
table_type_count=${#table_types[@]}
|
||||
# Loop through the tables and apply the mysqldump option according to the table type
|
||||
# The table specific SQL files will not contain any create info for the table schema.
|
||||
|
@ -163,7 +169,7 @@ else
|
|||
else
|
||||
DUMP_OPT="${DB} --no-create-info --single-transaction --tables --events --quote-names "
|
||||
fi
|
||||
mysqldump ${MYSQL_OPTS} ${DUMP_OPT} ${table} |gzip -c > ${DB_BKP_FLDR}/${table}.sql.gz
|
||||
${MYSQLDUMP_BIN} ${MYSQL_OPTS} ${DUMP_OPT} ${table} |gzip -c > ${DB_BKP_FLDR}/${table}.sql.gz
|
||||
index=$((${index} + 2))
|
||||
#echo -e " - Total time : $(($(date +%s) - ${START}))\n"
|
||||
done
|
||||
|
|
Loading…
Reference in New Issue