Skip to content

[Feature Request]: mo-dump supports dumping database and table definitions only without data #10091

Closed

Description

@aronchanisme

Is there an existing issue for the same feature request?

  • I have checked the existing issues.

Is your feature request related to a problem?

Currently mo-dump supports 2 ways of dumping. One is dumping data with ddl and insert statements, and the other is dumping data with ddl and load statements along with csv data files. However mo-dump does not yet support dumping the definitions of database and/or tables only, without any data.

Describe the feature you'd like

mo-dump supports dumping database and table definitions only without data

Describe implementation you've considered

Support statement like this, with a --nodata option which indicates export database/table structure only.

mo-dump -u dump -p xxx -h 127.0.0.1 -P 6001 -db testdb --no-data > /tm/testdb.sql
mo-dump -u dump -p xxx -h 127.0.0.1 -P 6001 -db testdb --tbl testtable --no-data > /tm/testdb-testtable.sql

Documentation, Adoption, Use Case, Migration Strategy

https://docs.matrixorigin.cn/en/0.7.0/MatrixOne/Develop/export-data/modump/#constraints

Additional information

image

Activity

  1. added this to the V0.8.0 milestone on Jun 16, 2023
  2. added
    priority/p1
    on Jul 3, 2023
  3. added
    attention/doc-influence
    on Jul 5, 2023
  4. modified the milestones: 1.0.0, 1.1.0 on Aug 19, 2023
  5. added
    source/on-demand
    on Aug 28, 2023
  6. xmh1011 commented on Oct 16, 2023

    @xmh1011
    Contributor

    I'll try it.

  7. xmh1011 commented on Oct 16, 2023

    @xmh1011
    Contributor

    What is the data format supposed to be exported? Like SHOW TABLES and SHOW COLUMNS ?

  8. xmh1011 commented on Oct 27, 2023

    @xmh1011
    Contributor

    I think this issue can be closed now.

  9. aronchanisme commented on Oct 30, 2023

    @aronchanisme
    ContributorAuthor

    1 Test date: 2023/10/30

    2 MO commit id:

    root@test0:/data/mo/20231030_1050/matrixone# mo_ctl get_cid 
    2023-10-30 11:04:35.405 UTC+0800    [INFO]    Try get mo commit id
    commit 0175397c3d933aff66b3fa950f85d92fc05cab2c
    Author: LiuBo <[email protected]>
    Date:   Mon Oct 30 10:22:47 2023 +0800
    
        [bug] util: fix a user case in address manager. (#12273)
        
    2023-10-30 11:04:35.482 UTC+0800    [INFO]    Get commit id succeeded

    3 Test process and result:

    3.1 Test case 1 : tpch_1g

    3.1.1 Step 1. Load tpch 1g data into a newly installed mo with latest commit id
    3.1.2 Step 2. Execute below command to export the whole database with all tables
    command:

    mkdir -p /data/mo-backup/20231030_1058
    cd /data/mo/20231030_1050/matrixone
    ./mo-dump  -h 127.0.0.1 -P 6001 -p 111 -u dump  -db tpch_1g --no-data > /data/mo-backup/20231030_1058/tpch_1g_nodata_test.sql
    ls -lth /data/mo-backup/20231030_1058/tpch_1g_nodata_test.sql
    cat /data/mo-backup/20231030_1058/tpch_1g_nodata_test.sql
    cat /data/mo-backup/20231030_1058/tpch_1g_nodata_test.sql | grep -i 'create table'
    cat /data/mo-backup/20231030_1058/tpch_1g_nodata_test.sql | grep -i 'create table' | wc -l 
    mo_ctl sql 'show tables in tpch_1g;'

    results:
    8 tables are exported with tpch_1g database definition, which meets our expectation.
    image

    3.1.3 Step 3. Execute below command to export a few table within tpch_1g
    command:

    mkdir -p /data/mo-backup/20231030_1058
    cd /data/mo/20231030_1050/matrixone
    ./mo-dump  -h 127.0.0.1 -P 6001 -p 111 -u dump  -db tpch_1g -tbl nation,part,customer --no-data > /data/mo-backup/20231030_1058/tpch_1g_nodata_test_2.sql
    ls -lth /data/mo-backup/20231030_1058/tpch_1g_nodata_test_2.sql
    cat /data/mo-backup/20231030_1058/tpch_1g_nodata_test_2.sql
    cat /data/mo-backup/20231030_1058/tpch_1g_nodata_test_2.sql | grep -i 'create table'
    cat /data/mo-backup/20231030_1058/tpch_1g_nodata_test_2.sql | grep -i 'create table' | wc -l 
    mo_ctl sql 'show tables in tpch_1g;'

    results:
    3 tables are exported with no database definition, which meets our expectation.
    image
    image

    3.1.4 Step 4. Restore the database using the backups with no-data
    command:

    mo_ctl sql 'drop database tpch_1g;'
    mo_ctl sql 'show databases;'
    mo_ctl sql /data/mo-backup/20231030_1058/tpch_1g_nodata_test.sql
    mo_ctl sql 'show databases;'
    mo_ctl sql 'show tables in tpch_1g;'
    mo_ctl sql  "select 'nation' as table_name, count(*) from tpch_1g.nation union select 'region' as table_name, count(*) from tpch_1g.region union select 'part' as table_name, count(*) from tpch_1g.part union select 'supplier' as table_name, count(*) from tpch_1g.supplier union select 'partsupp' as table_name, count(*) from tpch_1g.partsupp union select 'customer' as table_name, count(*) from tpch_1g.customer union select 'orders' as table_name, count(*) from tpch_1g.orders union select 'lineitem' as table_name, count(*) from tpch_1g.lineitem;"

    results:
    tpch_1g database is created with all 8 tables in it and no data are loaded into any of these tables, which meets our expectation.
    image
    image
    image
    image
    image

    3.1.4 Step 4. Restore the tables using the backups with no-data
    command:

    # add database definition to the backup files
    sed -i '1iuse test;'  /data/mo-backup/20231030_1058/tpch_1g_nodata_test_2.sql
    sed -i '1icreate database if not exists test;' /data/mo-backup/20231030_1058/tpch_1g_nodata_test_2.sql
    cat /data/mo-backup/20231030_1058/tpch_1g_nodata_test_2.sql
    mo_ctl sql 'show databases'
    mo_ctl sql /data/mo-backup/20231030_1058/tpch_1g_nodata_test_2.sql
    mo_ctl sql 'show databases; show tables in test;'
    mo_ctl sql "select 'nation' as table_name, count(*) as count from test.nation union select 'part' as table_name, count(*) as count from test.part union select 'customer' as table_name, count(*) as count from test.customer;"

    result:
    image
    image
    image
    image

    3 tables nation, part and customer are created in test database with no data, which meets our expectation.

    **3.2 ** Test case 2: create some sample data
    Steps are similar, with data defined as below, which can be used as bvt case

    3.2.1 prepare data

    -- test_data.sql
    create database if not exists `modump_nodata_test`;
    use `modump_nodata_test`;
    create table `t1` (id int);
    insert into `t1` values (1),(2),(3);
    select * from `t1`;
    create table `t2` (name varchar(10));
    insert into `t2` values ('A'),('B'),('C');
    select * from `t2`;

    mo_ctl sql 'test_data.sql'

    3.2.2 backup test:

    BK_PATH=/data/mo-backup/20231030_1058
    MO_PATH=/data/mo/20231030_1050/matrixone
    cd ${MO_PATH}
    ./mo-dump -h 127.0.0.1 -P 6001 -u dump -p 111 -db modump_nodata_test --no-data > ${BK_PATH}/test_1.sql
    ./mo-dump -h 127.0.0.1 -P 6001 -u dump -p 111 -db modump_nodata_test --tbl t1,t2 --no-data > ${BK_PATH}/test_2.sql
    cat ${BK_PATH}/test_1.sql
    cat ${BK_PATH}/test_2.sql

    3.2.3 restore test

    mo_ctl sql 'drop database if exists `modump_nodata_test`;'
    mo_ctl sql 'show databases;'
    mo_ctl sql "${BK_PATH}/test_1.sql"
    mo_ctl sql "show databases; show tables in modump_nodata_test; select 't1' as table_name, count(*) from modump_nodata_test.t1 union select 't2' as table_name, count(*) from modump_nodata_test.t2;"
    
    
    mo_ctl sql 'show databases;'
    sed -i '1iuse modump_nodata_test_2;'  ${BK_PATH}/test_2.sql
    sed -i '1icreate database if not exists modump_nodata_test_2;' ${BK_PATH}/test_2.sql
    cat ${BK_PATH}/test_2.sql
    mo_ctl sql 'show databases;'
    mo_ctl sql "${BK_PATH}/test_2.sql"
    mo_ctl sql "show databases; show tables in modump_nodata_test; select 't1' as table_name, count(*) from modump_nodata_test.t1 union select 't2' as table_name, count(*) from modump_nodata_test.t2;"

    Results: the result meets our expectation
    image
    image
    image
    image
    image
    image
    image
    image
    image
    image

  10. aronchanisme commented on Oct 30, 2023

    @aronchanisme
    ContributorAuthor

    PS: Since mo-tested does not yet support executing external commands like mo-dump but not sql statement , bvt case is not added as of now. Will cover the test case in MO release test workflow in the future.
    https://github.com/matrixorigin/mo-nightly-regression/actions/workflows/mo-release-test-standalone.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

attention/doc-influencekind/featurepriority/p1source/on-demand

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions