Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added skip wildcard table option #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions mysql/mysql-backup.conf
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ CONFIG_SKIP_DATABASES=(information_schema performance_schema sys)
# Default: SKIP_TABLES=()
CONFIG_SKIP_TABLES=()

# Option to skip wildcard tables.
# BE AWARE!! Matched tables will be skipped for all databases!!
# Sample: SKIP_TABLES_WILDCARD=('tmp_%')
# Default: SKIP_TABLES_WILDCARD=()
CONFIG_SKIP_TABLES_WILDCARD=()

# Minimal free diskspace in Gigabytes (GB).
# Default: CONFIG_DISK_MIN_FREE=5
CONFIG_DISK_MIN_FREE=5
Expand Down
42 changes: 38 additions & 4 deletions mysql/mysql-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
# Sample: SKIP_DATABASES=(information_schema)
# SKIP_TABLES Array of tables to skip, prefixed with database
# Sample: SKIP_TABLES=(mysql.host)
# SKIP_TABLES_WILDCARD Array of wildcard table definitions to skip, without database prefix
# BE AWARE!! Matched tables will be skipped for all databases!!
# Sample: SKIP_TABLES_WILDCARD=('tmp_%')
# LOCAL_BKP_DIR The directory to put the backup in. It is not
# advised to use the /tmp or /var/tmp directory
# for security reasons.
Expand Down Expand Up @@ -477,8 +480,17 @@ if [[ $DEBUG -eq 1 ]]; then
for i in "${SKIP_TABLES[@]}"
do
echo " $i"
done
fi
done
fi
fi
if [[ $DEBUG -eq 1 ]]; then
if [ ${#SKIP_TABLES_WILDCARD[@]} -gt 0 ];then
echo -e "\nSkipping wildcard tables (For ALL databases):"
for i in "${SKIP_TABLES_WILDCARD[@]}"
do
echo " $i"
done
fi
fi

[[ $DEBUG -eq 1 ]] && echo -e "\nStarting backup...\n"
Expand Down Expand Up @@ -511,6 +523,7 @@ while read -r DB; do

# Create the skip string for the structure dump
SKIPSTRING=()
WILDCARD_TABLES=()
for i in "${SKIP_TABLES[@]}"
do
# Check if we have a database that is identical to a skipped one.
Expand All @@ -519,6 +532,18 @@ while read -r DB; do
SKIPSTRING+=("--ignore-table=$i")
fi
done
for i in "${SKIP_TABLES_WILDCARD[@]}"
do
tables=$(($BIN_MYSQL $LOGIN_OPTS -BNe "SELECT table_name FROM information_schema.tables WHERE table_schema = '${DB}' and table_name like '${i}';") 2>&1)
if [[ $? -eq 1 ]]; then
ERROR_REASONS+=("${wildcard_tables}")
else
for table in $tables; do
SKIPSTRING+=("--ignore-table=$table")
WILDCARD_TABLES+=( $table )
done
fi
done

# Get the tables and its type. Store it in an array.
# Using backticks around $DB for users who have dashes in there database / table names.
Expand Down Expand Up @@ -554,6 +579,7 @@ while read -r DB; do
table=${row% *}
type=${row##* }

SKIP=0
DUMP_OPTS=("$DB")
DUMP_OPTS+=("--no-create-info") # Do not write CREATE TABLES in the dump
DUMP_OPTS+=("--skip-triggers") # Do not include triggers, we have them in the structure
Expand All @@ -579,11 +605,19 @@ while read -r DB; do
SKIP=1
break
fi
else
SKIP=0
fi
done

if [[ $SKIP -eq 0 ]]; then
for i in "${WILDCARD_TABLES[@]}"
do
if [[ "$i" == "$table" ]];then
SKIP=1
break
fi
done
fi

if [[ $SKIP -eq 1 ]]; then
[[ $DEBUG -eq 1 ]] && printDebugStatus "SKIPPED" " $table"
else
Expand Down