CentOS 7
Sponsored Link

MySQL 8.0 : Use Clone Feature2020/01/23

 
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.
# MySQL version

[root@www ~]#
/opt/rh/rh-mysql80/root/usr/libexec/mysqld --version

/opt/rh/rh-mysql80/root/usr/libexec/mysqld Ver 8.0.17 for Linux on x86_64 (Source distribution)
[root@www ~]#
vi /etc/opt/rh/rh-mysql80/my.cnf.d/mysql-server.cnf
# add into [mysqld] section

[mysqld]
.....
.....
plugin-load=mysql_clone.so
[root@www ~]#
systemctl restart rh-mysql80-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/';"
[root@www ~]#
ll /home/mysql_backup/backup01

total 166916
drwxr-x---. 2 mysql mysql       89 Jan 22 19:35 #clone
-rw-r-----. 1 mysql mysql     3777 Jan 22 19:35 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 Jan 22 19:35 ibdata1
-rw-r-----. 1 mysql mysql 50331648 Jan 22 19:35 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 Jan 22 19:35 ib_logfile1
drwxr-x---. 2 mysql mysql        6 Jan 22 19:35 mysql
-rw-r-----. 1 mysql mysql 24117248 Jan 22 19:35 mysql.ibd
drwxr-x---. 2 mysql mysql       28 Jan 22 19:35 sys
drwxr-x---. 2 mysql mysql       28 Jan 22 19:35 test_database
-rw-r-----. 1 mysql mysql 10485760 Jan 22 19:35 undo_001
-rw-r-----. 1 mysql mysql 10485760 Jan 22 19:35 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 ~]#
restorecon -v /home/mysql_backup

[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 };

[root@www ~]#
checkmodule -m -M -o mysqld-clone.mod mysqld-clone.te

checkmodule: loading policy configuration from mysqld-clone.te
checkmodule: policy configuration loaded
checkmodule: writing binary representation (version 19) to mysqld-clone.mod
[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/opt/rh/rh-mysql80/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/';
Matched Content