MySQL 8.0 : Use Clone Feature2022/07/06 |
Use Clone Feature to take MySQL backup which has been implemented on MySQL 8.0.17.
|
|
[1] | Clone feature is not enabled by default, so enable it. |
[root@www ~]#
vi /etc/my.cnf.d/mysql-server.cnf # add into [mysqld] section [mysqld] ..... .....
plugin-load=mysql_clone.so
[root@www ~]#
systemctl restart mysqld
# show plugins [root@www ~]# mysql -u root -p -e "select plugin_name, plugin_status, plugin_type from information_schema.plugins where plugin_name = 'clone';" Enter password: +-------------+---------------+-------------+ | plugin_name | plugin_status | plugin_type | +-------------+---------------+-------------+ | clone | ACTIVE | CLONE | +-------------+---------------+-------------+ |
[2] | Get Clone in a directory on localhost. |
# create a directory for clone data [root@www ~]# mkdir /home/mysql_backup [root@www ~]# chown mysql. /home/mysql_backup # run getting clone # if specified directory already exists on the filesystem, it will be error, # so specify new directory for [directory = ***] section [root@www ~]# mysql -u root -p -e "clone local data directory = '/home/mysql_backup/backup01/';"
ll /home/mysql_backup/backup01 total 180228 drwxr-x---. 2 mysql mysql 89 Jul 6 16:31 '#clone' -rw-r-----. 1 mysql mysql 4073 Jul 6 16:31 ib_buffer_pool -rw-r-----. 1 mysql mysql 12582912 Jul 6 16:31 ibdata1 -rw-r-----. 1 mysql mysql 50331648 Jul 6 16:31 ib_logfile0 -rw-r-----. 1 mysql mysql 50331648 Jul 6 16:31 ib_logfile1 drwxr-x---. 2 mysql mysql 6 Jul 6 16:31 mysql -rw-r-----. 1 mysql mysql 25165824 Jul 6 16:31 mysql.ibd drwxr-x---. 2 mysql mysql 28 Jul 6 16:31 sys drwxr-x---. 2 mysql mysql 28 Jul 6 16:31 test_database -rw-r-----. 1 mysql mysql 16777216 Jul 6 16:31 undo_001 -rw-r-----. 1 mysql mysql 16777216 Jul 6 16:31 undo_002 |
[3] | If SELinux is enabled, it needs to change policies for target directory. If you get clone data under [/home] like this example, change like follows. |
[root@www ~]#
vi mysqld-clone.te # create new module mysqld-clone 1.0; require { type mysqld_t; type user_home_dir_t; class dir { add_name create remove_name write }; class file { create getattr open read unlink write }; } #============= mysqld_t ============== allow mysqld_t user_home_dir_t:dir { add_name create remove_name write }; allow mysqld_t user_home_dir_t:file { create getattr open read unlink write }; checkmodule -m -M -o mysqld-clone.mod mysqld-clone.te [root@www ~]# semodule_package --outfile mysqld-clone.pp --module mysqld-clone.mod [root@www ~]# semodule -i mysqld-clone.pp |
[4] | To use [CLONE INSTANCE FROM], it's possible to get clone from a remote host directly. On Official documents, clone source is called [Donor] and clone target is called [Recipient]. |
# on Donor Host, create a user and add [BACKUP_ADMIN] privilege for clone [root@www ~]# mysql -u root -p Enter password: mysql> create user 'clone_user'@'%' identified by 'password'; Query OK, 0 rows affected (0.09 sec) mysql> grant BACKUP_ADMIN on *.* to 'clone_user'@'%'; Query OK, 0 rows affected (0.10 sec) # on Recipient Host, create a user and add [CLONE_ADMIN] privilege for clone [root@node01 ~]# mysql -u root -p Enter password: mysql> create user 'clone_user'@'%' identified by 'password'; Query OK, 0 rows affected (0.11 sec) mysql> grant CLONE_ADMIN on *.* to 'clone_user'@'%'; Query OK, 0 rows affected (0.04 sec) # on Recipient Host, run Clone job # before clone, set [set global clone_valid_donor_list = (Donor IP address:port)] # clone data is copied under [/var/lib/mysql] mysql> set global clone_valid_donor_list = '10.0.0.31:3306'; Query OK, 0 rows affected (0.00 sec) mysql> clone instance from clone_user@10.0.0.31:3306 identified by 'password'; Query OK, 0 rows affected (2.64 sec) # confirm clone status # OK if [STATE] is [Completed] mysql> select STATE from performance_schema.clone_status; +-----------+ | STATE | +-----------+ | Completed | +-----------+ 1 row in set (0.00 sec) # if specify cloned target directory, add [data directory = '***'] # but then it needs to set suitable permission to the target directory like [2], [3] mysql> clone instance from clone_user@10.0.0.31:3306 identified by 'password' data directory = '/home/mysql_backup/backup01/'; |
Sponsored Link |