Ubuntu 22.04
Sponsored Link

MySQL 8.0 : Use Clone Feature2022/09/28

 
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@dlp:~#
mysqld --version

/usr/sbin/mysqld Ver 8.0.30-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu))
root@dlp:~#
vi /etc/mysql/mysql.conf.d/mysqld.cnf
# add into [mysqld] section

[mysqld]
.....
.....
plugin-load=mysql_clone.so
# line 32 : if cloning from other hosts, change bind address

bind-address            = 0.0.0.0
mysqlx-bind-address     = 127.0.0.1

root@dlp:~#
systemctl restart mysql
# show plugins

root@dlp:~#
mysql -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@dlp:~#
mkdir /home/mysql_backup

root@dlp:~#
chown mysql. /home/mysql_backup

# writing to target directory for cloning is denied by AppArmor, so allow it before running

root@dlp:~#
vi /etc/apparmor.d/usr.sbin.mysqld
# add target directory to allow mysqld can write

/usr/sbin/mysqld {
  .....
  .....
  /home/mysql_backup/ r,
  /home/mysql_backup/** rwk,
}

root@dlp:~#
systemctl restart apparmor
# run getting clone
# if specified directory already exists on the filesystem, it will be error,
# so specify new directory for [directory = ***] section

root@dlp:~#
mysql -e "clone local data directory = '/home/mysql_backup/backup01/';"
root@dlp:~#
ll /home/mysql_backup/backup01

total 70692
drwxr-x--- 2 mysql mysql     4096 Sep 28 03:54 '#clone'/
drwxr-x--- 2 mysql mysql     4096 Sep 28 03:54 '#innodb_redo'/
drwxr-x--- 7 mysql mysql     4096 Sep 28 03:54  ./
drwxr-xr-x 3 mysql mysql     4096 Sep 28 03:54  ../
-rw-r----- 1 mysql mysql     4414 Sep 28 03:54  ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 Sep 28 03:54  ibdata1
drwxr-x--- 2 mysql mysql     4096 Sep 28 03:54  mysql/
-rw-r----- 1 mysql mysql 26214400 Sep 28 03:54  mysql.ibd
drwxr-x--- 2 mysql mysql     4096 Sep 28 03:54  sys/
drwxr-x--- 2 mysql mysql     4096 Sep 28 03:54  test_database/
-rw-r----- 1 mysql mysql 16777216 Sep 28 03:54  undo_001
-rw-r----- 1 mysql mysql 16777216 Sep 28 03:54  undo_002
[3] 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@dlp:~#
mysql


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


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.30:3306';
Query OK, 0 rows affected (0.00 sec)

mysql> clone instance from clone_user@10.0.0.30:3306 identified by 'password';
Query OK, 0 rows affected (0.45 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.30:3306 identified by 'password' data directory = '/home/mysql_backup/backup01/';
Matched Content