dbImport

1. Help

Command: bin/dbImport --help

SYNOPSIS:
    Import source db into target db using eventual table filter.

USAGE: dbImport [OPTIONS] [ARGUMENTS]
USAGE: dbImport [--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]

ARGUMENTS:
  fromDbName {single} (mandatory)    The name of the source/remote database.
  [<targetDbName> {single}]    The name of the target database
    Default value: <fromDbName>(without extension)


TARGET OPTIONS:
  --collation-name, -o <targetDsn> {single}
    Change the collation name used during database creation.
  --target-dsn, -t <targetDsn> {single}
    Dsn to use for target database.
    Default value: default.local
  --character-set, -c <characterSet> {single}
    Change the character set used during database creation.

PROFILE OPTIONS:
  --profile, -p <profile> {single}
    The name of the profile to use in order to
    include or exclude tables.
  --tables <tablesSeparatedByComma> {single}
    Import only table specified in the list.
    If aws mode, ignore profile option.


SOURCE OPTIONS:
  --skip-schema, -s {single}
    Avoids to import the schema.
  --from-dsn, -f <dsn> {single}
    target mysql server
  --from-aws, -a <awsFile> {single}
    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.

  --reset {single}
    Reset the table before importing data using TRUNCATE TABLE or DROP TABLE
    before CREATE TABLE.
  --dump-kind, -k <dumpKind> {single}
    Kind of dump to import.

    Possible values: 
      - auto: Deduce dump kind from filename:     .sql             -> sql
            .tar             -> tar     .tar.gz or .tgz  -> tar.gz
            .gz              -> gz
      - sql: dump file is a .sql file.
      - tar: dump file is a .tar file containing multiple .sql files, one pe
        r table.
      - tar.gz: dump file is a .tar file gzipped containing multiple .sql fi
        les, one per table.
      - gz: dump file is a gz file containing a single .sql file.
      - tar.individual.sql.gz: dump file is a tar file containing multiple .
        sql.gz files, one per table.
    Default value: auto

GLOBAL OPTIONS:
  --help, -h {single}
    Displays this command help
  --config {single}
    Displays configuration
  --bash-framework-config <bash-framework-config> {single}
    Use alternate bash framework configuration.
  --verbose, -v {single}
    Info level verbose mode (alias of --display-level INFO)
  -vv {single}
    Debug level verbose mode (alias of --display-level DEBUG)
  -vvv {single}
    Trace level verbose mode (alias of --display-level TRACE)
  --log-level <log-level> {single}
    Set log level
    Possible values: 
      - OFF
      - ERR
      - ERROR
      - WARN
      - WARNING
      - INFO
      - DEBUG
      - TRACE
    Default value: OFF
  --log-file <log-file> {single}
    Set log file
    Default value: /logs/bash.log
  --display-level <display-level> {single}
    Set display level
    Possible values: 
      - OFF
      - ERR
      - ERROR
      - WARN
      - WARNING
      - INFO
      - DEBUG
      - TRACE
    Default value: INFO
  --no-color {single}
    Produce monochrome output. alias of --theme noColor.
  --theme <theme> {single}
    Choose color theme - default-force means colors will be produced even if
    command is piped.
    Possible values: 
      - default
      - default-force
      - noColor
    Default value: default
  --version {single}
    Print version information and quit.
  --quiet, -q {single}
    Quiet mode, doesn't display any output.


DESCRIPTION:
  Data Source Name (DSN)
    Default dsn directory:
      /bash/conf/dsn

    User dsn directory:
      /home/www-data/.bash-tools/dsn
      Allows to override dsn defined in "Default dsn directory"

    List of available dsn:
      - default.local
      - default.remote
      - localhost-root

    Aws s3 location:
      s3://example.com/exports/

  Profiles
    Default profiles directory:
      /bash/conf/dbImportProfiles

    User profiles directory:
      /home/www-data/.bash-tools/dbImportProfiles
      Allows to override profiles defined in "Default profiles directory"

    List of available profiles:
      - all
      - default
      - none

  Examples
    1. from one database to another one
    dbImport --from-dsn localhost --target-dsn remote fromDb toDb

    2. import from S3
    dbImport --from-aws awsFile.tar.gz --target-dsn localhost fromDb toDb

  Changelog
    4.0 (2026-04-14)
      - add support for tar.gz and tar.individual.sql.gz dump files
    3.0
      - initial version

VERSION: 4.0

AUTHOR: [François Chastanet](https://github.com/fchastanet)

SOURCE FILE: https://github.com/fchastanet/bash-tools-framework/tree/master/src/_binaries/Database/dbImport/dbImport-binary.yaml

LICENSE: MIT License
Copyright (c) 2020-now François Chastanet

2. Usage

Import default source dsn/db ExampleDbName into default target dsn/db ExampleDbName

dbImport ExampleDbName

Ability to import db from dump stored on aws the dump file should have this name <fromDbName>.tar.gz and stored on AWS location defined by S3_BASE_URL env variable (see src/_binaries/Database/dbImport/testsData/.env file)

dbImport --from-aws ExampleDbName.tar.gz

It allows also to dump from source database and import it into target database. Providing –profile option dumps only the tables selected. Providing –tables option imports only the tables selected.

The following command will dump full structure and data of fromDb but will insert only the data from tableA and tableB, full structure will be inserted too. Second call to this command skip the dump as dump has been saved the first time. Note that table A and table B are truncated on target database before being imported.

dbImport --from-dsn default.remote --target-dsn default.local -p all \
  fromDb targetDB --tables tableA,tableB
Or, if you want, you can alternatively use the GitHub discussion Q&A for feedback and questions.