Skip to content
Merged
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
142 changes: 117 additions & 25 deletions bin/dbImport
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,7 @@ optionHelpCallback() {
# shellcheck disable=SC2317,SC2329 # if function is overridden
optionVersionCallback() {
# shellcheck disable=SC2154
echo "${SCRIPT_NAME} version 3.0"
echo "${SCRIPT_NAME} version 4.0"
exit 0
}

Expand Down Expand Up @@ -1906,6 +1906,12 @@ longDescriptionFunction() {
echo
echo -e " 2. import from S3"
echo -e " ${__HELP_EXAMPLE}dbImport --from-aws awsFile.tar.gz --target-dsn localhost fromDb toDb${__HELP_NORMAL}"
echo
echo -e " ${__HELP_TITLE}Changelog${__HELP_NORMAL}"
echo -e " ${__HELP_EXAMPLE}4.0 (2026-04-14)${__HELP_NORMAL}"
echo -e " - add support for tar.gz and tar.individual.sql.gz dump files"
echo -e " ${__HELP_EXAMPLE}3.0${__HELP_NORMAL}"
echo -e " - initial version"
Db::checkRequirements
}

Expand Down Expand Up @@ -2070,7 +2076,7 @@ fromDsnOptionLongDescription() {

optionVersionCallback() {
# shellcheck disable=SC2154
echo "${SCRIPT_NAME} version 3.0"
echo "${SCRIPT_NAME} version 4.0"
Db::checkRequirements
exit 0
}
Expand Down Expand Up @@ -2102,6 +2108,8 @@ declare optionTables=""
declare optionSkipSchema="0"
declare optionFromDsn=""
declare optionFromAws=""
declare optionReset="0"
declare optionDumpKind="auto"
declare optionHelp="0"
declare optionConfig="0"
declare optionBashFrameworkConfig=""
Expand Down Expand Up @@ -2146,6 +2154,12 @@ dbImportCommandParse() {
optionFromAws=""
local -i options_parse_optionParsedCountOptionFromAws
((options_parse_optionParsedCountOptionFromAws = 0)) || true
optionReset="0"
local -i options_parse_optionParsedCountOptionReset
((options_parse_optionParsedCountOptionReset = 0)) || true
optionDumpKind="auto"
local -i options_parse_optionParsedCountOptionDumpKind
((options_parse_optionParsedCountOptionDumpKind = 0)) || true
optionHelp="0"
local -i options_parse_optionParsedCountOptionHelp
((options_parse_optionParsedCountOptionHelp = 0)) || true
Expand Down Expand Up @@ -2203,7 +2217,7 @@ dbImportCommandParse() {
local options_parse_arg="$1"
local argOptDefaultBehavior=0
case "${options_parse_arg}" in
# Option 1/21
# Option 1/23
# optionCollationName alts --collation-name|-o
# type: String min 0 max 1
--collation-name | -o)
Expand All @@ -2222,7 +2236,7 @@ dbImportCommandParse() {
optionCollationName="$1"
;;

# Option 2/21
# Option 2/23
# optionTargetDsn alts --target-dsn|-t
# type: String min 0 max 1
--target-dsn | -t)
Expand All @@ -2241,7 +2255,7 @@ dbImportCommandParse() {
optionTargetDsn="$1"
;;

# Option 3/21
# Option 3/23
# optionCharacterSet alts --character-set|-c
# type: String min 0 max 1
--character-set | -c)
Expand All @@ -2260,7 +2274,7 @@ dbImportCommandParse() {
optionCharacterSet="$1"
;;

# Option 4/21
# Option 4/23
# optionProfile alts --profile|-p
# type: String min 0 max 1
--profile | -p)
Expand All @@ -2279,7 +2293,7 @@ dbImportCommandParse() {
optionProfile="$1"
;;

# Option 5/21
# Option 5/23
# optionTables alts --tables
# type: String min 0 max 1
--tables)
Expand All @@ -2300,7 +2314,7 @@ dbImportCommandParse() {

;;

# Option 6/21
# Option 6/23
# optionSkipSchema alts --skip-schema|-s
# type: Boolean min 0 max 1
--skip-schema | -s)
Expand All @@ -2314,7 +2328,7 @@ dbImportCommandParse() {
((++options_parse_optionParsedCountOptionSkipSchema))
;;

# Option 7/21
# Option 7/23
# optionFromDsn alts --from-dsn|-f
# type: String min 0 max 1
--from-dsn | -f)
Expand All @@ -2333,7 +2347,7 @@ dbImportCommandParse() {
optionFromDsn="$1"
;;

# Option 8/21
# Option 8/23
# optionFromAws alts --from-aws|-a
# type: String min 0 max 1
--from-aws | -a)
Expand All @@ -2352,7 +2366,45 @@ dbImportCommandParse() {
optionFromAws="$1"
;;

# Option 9/21
# Option 9/23
# optionReset alts --reset
# type: Boolean min 0 max 1
--reset)
# shellcheck disable=SC2034
optionReset="1"

if ((options_parse_optionParsedCountOptionReset >= 1 )); then
Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)"
return 1
fi
((++options_parse_optionParsedCountOptionReset))
;;

# Option 10/23
# optionDumpKind alts --dump-kind|-k
# type: String min 0 max 1
# authorizedValues: auto|sql|tar|tar.gz|gz|tar.individual.sql.gz
--dump-kind | -k)
shift
if (($# == 0)); then
Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified"
return 1
fi
if [[ ! "$1" =~ auto|sql|tar|tar.gz|gz|tar.individual.sql.gz ]]; then
Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(auto, sql, tar, tar.gz, gz, tar.individual.sql.gz)"
return 1
fi

if ((options_parse_optionParsedCountOptionDumpKind >= 1 )); then
Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)"
return 1
fi
((++options_parse_optionParsedCountOptionDumpKind))
# shellcheck disable=SC2034
optionDumpKind="$1"
;;

# Option 11/23
# optionHelp alts --help|-h
# type: Boolean min 0 max 1
--help | -h)
Expand All @@ -2368,7 +2420,7 @@ dbImportCommandParse() {

;;

# Option 10/21
# Option 12/23
# optionConfig alts --config
# type: Boolean min 0 max 1
--config)
Expand All @@ -2382,7 +2434,7 @@ dbImportCommandParse() {
((++options_parse_optionParsedCountOptionConfig))
;;

# Option 11/21
# Option 13/23
# optionBashFrameworkConfig alts --bash-framework-config
# type: String min 0 max 1
--bash-framework-config)
Expand All @@ -2403,7 +2455,7 @@ dbImportCommandParse() {

;;

# Option 12/21
# Option 14/23
# optionInfoVerbose alts --verbose|-v
# type: Boolean min 0 max 1
--verbose | -v)
Expand All @@ -2421,7 +2473,7 @@ dbImportCommandParse() {

;;

# Option 13/21
# Option 15/23
# optionDebugVerbose alts -vv
# type: Boolean min 0 max 1
-vv)
Expand All @@ -2439,7 +2491,7 @@ dbImportCommandParse() {

;;

# Option 14/21
# Option 16/23
# optionTraceVerbose alts -vvv
# type: Boolean min 0 max 1
-vvv)
Expand All @@ -2457,7 +2509,7 @@ dbImportCommandParse() {

;;

# Option 15/21
# Option 17/23
# optionLogLevel alts --log-level
# type: String min 0 max 1
# authorizedValues: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE
Expand Down Expand Up @@ -2485,7 +2537,7 @@ dbImportCommandParse() {

;;

# Option 16/21
# Option 18/23
# optionLogFile alts --log-file
# type: String min 0 max 1
--log-file)
Expand All @@ -2508,7 +2560,7 @@ dbImportCommandParse() {

;;

# Option 17/21
# Option 19/23
# optionDisplayLevel alts --display-level
# type: String min 0 max 1
# authorizedValues: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE
Expand Down Expand Up @@ -2536,7 +2588,7 @@ dbImportCommandParse() {

;;

# Option 18/21
# Option 20/23
# optionNoColor alts --no-color
# type: Boolean min 0 max 1
--no-color)
Expand All @@ -2554,7 +2606,7 @@ dbImportCommandParse() {

;;

# Option 19/21
# Option 21/23
# optionTheme alts --theme
# type: String min 0 max 1
# authorizedValues: default|default-force|noColor
Expand Down Expand Up @@ -2582,7 +2634,7 @@ dbImportCommandParse() {

;;

# Option 20/21
# Option 22/23
# optionVersion alts --version
# type: Boolean min 0 max 1
--version)
Expand All @@ -2598,7 +2650,7 @@ dbImportCommandParse() {

;;

# Option 21/21
# Option 23/23
# optionQuiet alts --quiet|-q
# type: Boolean min 0 max 1
--quiet | -q)
Expand Down Expand Up @@ -2696,6 +2748,8 @@ dbImportCommandParse() {








Expand Down Expand Up @@ -2727,7 +2781,7 @@ dbImportCommandHelp() {
# ------------------------------------------
# usage/options section
# ------------------------------------------
optionsAltList=("[--collation-name|-o <targetDsn>]" "[--target-dsn|-t <targetDsn>]" "[--character-set|-c <characterSet>]" "[--profile|-p <profile>]" "[--tables <tablesSeparatedByComma>]" "[--skip-schema|-s]" "[--from-dsn|-f <dsn>]" "[--from-aws|-a <awsFile>]" "[--help|-h]" "[--config]" "[--bash-framework-config <bash-framework-config>]" "[--verbose|-v]" "[-vv]" "[-vvv]" "[--log-level <log-level>]" "[--log-file <log-file>]" "[--display-level <display-level>]" "[--no-color]" "[--theme <theme>]" "[--version]" "[--quiet|-q]"
optionsAltList=("[--collation-name|-o <targetDsn>]" "[--target-dsn|-t <targetDsn>]" "[--character-set|-c <characterSet>]" "[--profile|-p <profile>]" "[--tables <tablesSeparatedByComma>]" "[--skip-schema|-s]" "[--from-dsn|-f <dsn>]" "[--from-aws|-a <awsFile>]" "[--reset]" "[--dump-kind|-k <dumpKind>]" "[--help|-h]" "[--config]" "[--bash-framework-config <bash-framework-config>]" "[--verbose|-v]" "[-vv]" "[-vvv]" "[--log-level <log-level>]" "[--log-file <log-file>]" "[--display-level <display-level>]" "[--no-color]" "[--theme <theme>]" "[--version]" "[--quiet|-q]"
)
Array::wrap2 " " 80 2 "${__HELP_TITLE_COLOR}USAGE:${__RESET_COLOR}" \
"dbImport" "${optionsAltList[@]}"
Expand Down Expand Up @@ -2798,6 +2852,36 @@ dbImportCommandHelp() {
Array::wrap2 ' ' 76 4 " " "db dump will be downloaded from s3 instead of using remote db." "The value <awsFile> is the name of the file without s3 location" "(Only .gz or tar.gz file are supported)." "This option is incompatible with -f|--from-dsn option." ""
echo


echo -e " ${__HELP_OPTION_COLOR}--reset${__HELP_NORMAL} {single}"
Array::wrap2 ' ' 76 4 " " "Reset the table before importing data using TRUNCATE TABLE or DROP TABLE before CREATE TABLE."
echo


echo -e " ${__HELP_OPTION_COLOR}--dump-kind${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-k <dumpKind>${__HELP_NORMAL} {single}"
Array::wrap2 ' ' 76 4 " " "Kind of dump to import." ""
echo

echo " Possible values: "
Array::wrap2 ' ' 76 8 " - ${__OPTION_COLOR}auto:${__RESET_COLOR} Deduce dump kind from filename:
${__HELP_EXAMPLE}.sql${__HELP_NORMAL} -> sql
${__HELP_EXAMPLE}.tar${__HELP_NORMAL} -> tar
${__HELP_EXAMPLE}.tar.gz or .tgz${__HELP_NORMAL} -> tar.gz
${__HELP_EXAMPLE}.gz${__HELP_NORMAL} -> gz"
echo
Array::wrap2 ' ' 76 8 " - ${__OPTION_COLOR}sql:${__RESET_COLOR} dump file is a .sql file."
echo
Array::wrap2 ' ' 76 8 " - ${__OPTION_COLOR}tar:${__RESET_COLOR} dump file is a .tar file containing multiple .sql files, one per table."
echo
Array::wrap2 ' ' 76 8 " - ${__OPTION_COLOR}tar.gz:${__RESET_COLOR} dump file is a .tar file gzipped containing multiple .sql files, one per table."
echo
Array::wrap2 ' ' 76 8 " - ${__OPTION_COLOR}gz:${__RESET_COLOR} dump file is a gz file containing a single .sql file."
echo
Array::wrap2 ' ' 76 8 " - ${__OPTION_COLOR}tar.individual.sql.gz:${__RESET_COLOR} dump file is a tar file containing multiple .sql.gz files, one per table."
echo

Array::wrap2 ' ' 76 6 " Default value: " "auto"
echo
echo
echo -e "${__HELP_TITLE_COLOR}GLOBAL OPTIONS:${__RESET_COLOR}"
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
Expand Down Expand Up @@ -2910,7 +2994,7 @@ dbImportCommandHelp() {
# ------------------------------------------
echo
echo -n -e "${__HELP_TITLE_COLOR}VERSION: ${__RESET_COLOR}"
echo "3.0"
echo "4.0"
# ------------------------------------------
# author section
# ------------------------------------------
Expand Down Expand Up @@ -3117,16 +3201,24 @@ if [[ -z "${optionFromAws}" ]]; then
fi
fi
Log::displayInfo "import remote to local from file ${remoteDbDumpTempFile}"
# shellcheck disable=SC2154
declare -a dbImportStreamOptions=(
--profile "${optionProfile}"
--target-dsn "${optionTargetDsn}"
--character-set "${targetCharacterSet}"
--dump-kind "${optionDumpKind}"
)
if [[ -n "${optionTables:-}" ]]; then
dbImportStreamOptions+=(
--tables "${optionTables}"
)
fi
# shellcheck disable=SC2154
if [[ "${optionReset}" = "1" ]]; then
dbImportStreamOptions+=(
--reset
)
fi
time (
"${CURRENT_DIR}/dbImportStream" \
"${dbImportStreamOptions[@]}" \
Expand Down
Loading
Loading