Created
January 26, 2020 22:56
-
-
Save rogersguedes/8401e37c5a03ba370981f10a208db94c to your computer and use it in GitHub Desktop.
This scripts generate a mysqldump commands to backup a MySQL database into two separate files. One for tables creation only and other for for data insertion;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
discendingTime(){ | |
date '+%Y.%m.%d.%H.%M.%S' | |
} | |
TIME_NOW=$(discendingTime) | |
HOST=$1 | |
PORT=$2 | |
USER=$3 | |
DATABASE=$4 | |
DB_FILE=$5-${DATABASE}-${TIME_NOW} | |
EXCLUDED_TABLES=( | |
) | |
IGNORED_TABLES_STRING='' | |
for TABLE in "${EXCLUDED_TABLES[@]}" | |
do : | |
IGNORED_TABLES_STRING+=" --ignore-table=${DATABASE}.${TABLE}" | |
done | |
echo "# Dump structure" | |
echo "mysqldump --host=${HOST} --port=${PORT} --user=${USER} -p --single-transaction --no-data ${DATABASE} > ${DB_FILE}-DDL.sql" | |
echo "# Dump content" | |
echo "mysqldump --complete-insert --host=${HOST} --port=${PORT} --user=${USER} -p ${DATABASE} --no-create-info ${IGNORED_TABLES_STRING} > ${DB_FILE}-DATA.sql" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment