Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-18762

Support easy restore of partial backup

Details

    Description

      This came up in an InnoDB Birds of a Feather session.

      mariabackup --export is internally executing FLUSH TABLES…EXPORT on the backed-up files to allow the files to be imported to another server instance. But it does not appear to generate a script file that could be conveniently executed by the user in order to import the tables.

      It would be nice to have a sequence of SQL statements and shell commands for importing the exported tables. Maybe we could generate several files:

      1. create.sql with CREATE OR REPLACE TABLE…;ALTER TABLE…DISCARD TABLESPACE statements (not needed starting with MDEV-26137 in MariaDB Server 11.2)
      2. move.sh or move.bat for moving the files to the data directory
      3. import.sql containing the ALTER TABLE…IMPORT TABLESPACE statements.

      Attachments

        Issue Links

          Activity

            I think that implementing MDEV-26137 will simplify this.

            marko Marko Mäkelä added a comment - I think that implementing MDEV-26137 will simplify this.

            So with MDEV-26137 closed, were are we with this one now?

            We had yet another customer ask about

            "Need STEPS to restore single database from mariabackup"

            just today.

            So nine related support cases, of which five are still active, and I'm pretty sure that there are more that are not even linked to this MDEV yet, esp. from pre-2019 ...

            hholzgra Hartmut Holzgraefe added a comment - So with MDEV-26137 closed, were are we with this one now? We had yet another customer ask about "Need STEPS to restore single database from mariabackup" just today. So nine related support cases, of which five are still active, and I'm pretty sure that there are more that are not even linked to this MDEV yet, esp. from pre-2019 ...

            With MDEV-26137 now allowing import from .ibd/.cfg/.frm file with no prior existing table things have become much easier, and creating proper CREATE TABLE statements is no longer needed.

            With that restoring a single database, or a specific subset of tables, now has become as easy as "just copy the related table files from a backup directory prepared with "--export" option, and ALTER...IMPORT them into the desired target datbase(s).

            With that we can probably also close this one as "fixed in 11.2.1", too, same as MDEV-26137

            hholzgra Hartmut Holzgraefe added a comment - With MDEV-26137 now allowing import from .ibd/.cfg/.frm file with no prior existing table things have become much easier, and creating proper CREATE TABLE statements is no longer needed. With that restoring a single database, or a specific subset of tables, now has become as easy as "just copy the related table files from a backup directory prepared with "--export" option, and ALTER...IMPORT them into the desired target datbase(s). With that we can probably also close this one as "fixed in 11.2.1", too, same as MDEV-26137
            serg Sergei Golubchik added a comment - - edited

            okay, thanks. I'm tentatively closing it then. Can be reopened, if people will think that MDEV-26137 wasn't enough

            serg Sergei Golubchik added a comment - - edited okay, thanks. I'm tentatively closing it then. Can be reopened, if people will think that MDEV-26137 wasn't enough
            ycp Yuchen Pei added a comment - - edited

            How it works, tested using mtr:

            1. start an mtr server:
            mtr --mysqld=--innodb --mysqld=--partition --start-and-exit && ./client/mysql -uroot -S./mysql-test/var/tmp/mysqld.1.sock test
            2. create a table and insert some values:

            MariaDB [test]> create table t1 (c int) engine=innodb;
            Query OK, 0 rows affected (0.012 sec)
             
            MariaDB [test]> insert into t1 values (42), (32);
            Query OK, 2 rows affected (0.014 sec)
            Records: 2  Duplicates: 0  Warnings: 0

            3. run mariabackup (is the first command needed?)

            ./extra/mariabackup/mariabackup --backup --target-dir=/tmp/mb/ --databases=test --tables=t1 --socket=./mysql-test/var/tmp/mysqld.1.sock --user=root
            ./extra/mariabackup/mariabackup --prepare --export --target-dir=/tmp/mb/ --databases=test --tables=t1 --socket=./mysql-test/var/tmp/mysqld.1.sock --user=root
               

            4. start a fresh mtr server, with an empty test database:
            mtr --mysqld=--innodb --mysqld=--partition --start-and-exit && ./client/mysql -uroot -S./mysql-test/var/tmp/mysqld.1.sock test

            MariaDB [test]> show tables;
            Empty set (0.001 sec)
               

            5. copy the tablespace files

            cp /tmp/mb/test/t1.* ./mysql-test/var/mysqld.1/data/test/
               

            6. import the table and check it worked:

            MariaDB [test]> alter table t1 import tablespace;
            Query OK, 0 rows affected (0.016 sec)
             
            MariaDB [test]> show create table t1;
            +-------+-----------------------------------------------------------------------------------------------------------------+
            | Table | Create Table                                                                                                    |
            +-------+-----------------------------------------------------------------------------------------------------------------+
            | t1    | CREATE TABLE `t1` (
              `c` int(11) DEFAULT NULL
            ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci |
            +-------+-----------------------------------------------------------------------------------------------------------------+
            1 row in set (0.001 sec)
             
            MariaDB [test]> select * from t1;
            +------+
            | c    |
            +------+
            |   42 |
            |   32 |
            +------+
            2 rows in set (0.003 sec)
               

            ycp Yuchen Pei added a comment - - edited How it works, tested using mtr: 1. start an mtr server: mtr --mysqld=--innodb --mysqld=--partition --start-and-exit && ./client/mysql -uroot -S./mysql-test/var/tmp/mysqld.1.sock test 2. create a table and insert some values: MariaDB [test]> create table t1 (c int) engine=innodb; Query OK, 0 rows affected (0.012 sec)   MariaDB [test]> insert into t1 values (42), (32); Query OK, 2 rows affected (0.014 sec) Records: 2 Duplicates: 0 Warnings: 0 3. run mariabackup (is the first command needed?) ./extra/mariabackup/mariabackup --backup --target-dir=/tmp/mb/ --databases=test --tables=t1 --socket=./mysql-test/var/tmp/mysqld.1.sock --user=root ./extra/mariabackup/mariabackup --prepare --export --target-dir=/tmp/mb/ --databases=test --tables=t1 --socket=./mysql-test/var/tmp/mysqld.1.sock --user=root 4. start a fresh mtr server, with an empty test database: mtr --mysqld=--innodb --mysqld=--partition --start-and-exit && ./client/mysql -uroot -S./mysql-test/var/tmp/mysqld.1.sock test MariaDB [test]> show tables; Empty set (0.001 sec) 5. copy the tablespace files cp /tmp/mb/test/t1.* ./mysql-test/var/mysqld.1/data/test/ 6. import the table and check it worked: MariaDB [test]> alter table t1 import tablespace; Query OK, 0 rows affected (0.016 sec)   MariaDB [test]> show create table t1; +-------+-----------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+-----------------------------------------------------------------------------------------------------------------+ | t1 | CREATE TABLE `t1` ( `c` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci | +-------+-----------------------------------------------------------------------------------------------------------------+ 1 row in set (0.001 sec)   MariaDB [test]> select * from t1; +------+ | c | +------+ | 42 | | 32 | +------+ 2 rows in set (0.003 sec)

            People

              ycp Yuchen Pei
              marko Marko Mäkelä
              Votes:
              13 Vote for this issue
              Watchers:
              21 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.