Bug #99677 Clone Plugin won't backup empty database
Submitted: 24 May 2020 14:35 Modified: 29 Jun 2020 8:40
Reporter: chen chen (OCA) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Clone Plugin Severity:S3 (Non-critical)
Version:8.0.20 OS:Linux
Assigned to: CPU Architecture:x86

[24 May 2020 14:35] chen chen
Description:
Clone Plugin won't backup empty database

Here is the step

mysql> select @@version;
+-----------+
| @@version |
+-----------+
| 8.0.20    |
+-----------+
1 row in set (0.10 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| slowtech           |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> show tables from slowtech;
Empty set (0.85 sec)

mysql> show create database slowtech;
+----------+------------------------------------------------------------------------------------------------------------------------------------+
| Database | Create Database                                                                                                                    |
+----------+------------------------------------------------------------------------------------------------------------------------------------+
| slowtech | CREATE DATABASE `slowtech` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */ |
+----------+------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> clone local data directory='/data/mysql/3307';
Query OK, 0 rows affected (3.16 sec)

Then i check the backup directory

# ll /data/mysql/3307
total 172996
drwxr-x--- 2 mysql mysql       89 May 24 22:31 #clone
-rw-r----- 1 mysql mysql     3646 May 24 22:31 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 May 24 22:31 ibdata1
-rw-r----- 1 mysql mysql 50331648 May 24 22:31 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 May 24 22:31 ib_logfile1
drwxr-x--- 2 mysql mysql        6 May 24 22:31 mysql
-rw-r----- 1 mysql mysql 25165824 May 24 22:31 mysql.ibd
drwxr-x--- 2 mysql mysql       28 May 24 22:31 sys
-rw-r----- 1 mysql mysql 10485760 May 24 22:31 undo_001
-rw-r----- 1 mysql mysql 11534336 May 24 22:31 undo_002

There is no slowtech database.

The same thing happened remote cloning.

How to repeat:
as stated above
[25 May 2020 12:25] MySQL Verification Team
Hi Mr. chen,

Thank you for your bug report.

However, I have to ask you some question.

You seem to have specified the already existing directory as a target directory. Can you please, elaborate it. If you have not specified your current datadir, then you have cloned successfully, since that directory is full.

Next, I hope that your user has BACKUP_ADMIN privilege.

Last, but not least, does user `mysql` has writing rights from /data directory up to and including the final directory.

That would be all for the start.
[26 May 2020 22:40] chen chen
That is easy to reproduce, i start from scratch.

[root@node1 ~]# mkdir -p /backup
[root@node1 ~]# chown mysql.mysql /backup/
[root@node1 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        24G   18G  6.3G  74% /
devtmpfs        227M     0  227M   0% /dev
tmpfs           237M     0  237M   0% /dev/shm
tmpfs           237M   21M  216M   9% /run
tmpfs           237M     0  237M   0% /sys/fs/cgroup
/dev/sda1       197M   97M  100M  50% /boot
tmpfs            48M     0   48M   0% /run/user/0

[root@node1 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 50
Server version: 8.0.20 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show tables from slowtech;
Empty set (0.30 sec)

[root@node1 ~]# mysql -uclone_user -pclone_pass
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 49
Server version: 8.0.20 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show grants;
+-----------------------------------------------+
| Grants for clone_user@%                       |
+-----------------------------------------------+
| GRANT USAGE ON *.* TO `clone_user`@`%`        |
| GRANT BACKUP_ADMIN ON *.* TO `clone_user`@`%` |
+-----------------------------------------------+
2 rows in set (0.00 sec)

mysql> clone local data directory='/backup/3307';
Query OK, 0 rows affected (12.02 sec)

[root@node1 ~]# ll /backup/3307/
total 159748
drwxr-x--- 2 mysql mysql       89 May 27 06:37 #clone
-rw-r----- 1 mysql mysql     3646 May 27 06:37 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 May 27 06:37 ibdata1
-rw-r----- 1 mysql mysql 50331648 May 27 06:37 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 May 27 06:37 ib_logfile1
drwxr-x--- 2 mysql mysql        6 May 27 06:37 mysql
-rw-r----- 1 mysql mysql 25165824 May 27 06:37 mysql.ibd
drwxr-x--- 2 mysql mysql       28 May 27 06:37 sys
-rw-r----- 1 mysql mysql 10485760 May 27 06:37 undo_001
-rw-r----- 1 mysql mysql 14680064 May 27 06:37 undo_002
[27 May 2020 12:37] MySQL Verification Team
Hi Mr. chen,

I have run your test case on my machine and you are correct.

Empty databases are not cloned. I do not know whether it is by intention, in which case this would be a documentation bug.

Verified as reported.
[29 Jun 2020 8:40] Erlend Dahl
Posted by developer:

[4 Jun 2020 4:36] Debarun Banerjee

"CLONE PLUGIN WON'T BACKUP EMPTY DATABASE" - I find problem in the bug
heading :) Clone is not a backup tool. The only issue could be if the empty
database is not cloned. How to validate it ? Easy, just start mysqld server
using the cloned directory and check.
 
mysql> clone local data directory='/data/mysql/3307';
Query OK, 0 rows affected (3.16 sec)
 
"Then i check the backup directory ..." - Let's call it "cloned directory"
and let's not try to count files/directories there :) Only person who can
read it is the mysqld server.
 
So, let's just start the server with the "cloned directory" and check ...
 
mysqld --datadir= '/data/mysql/3307'
 
mysql -u root
 
mysql> show databases;
| information_schema |
| mysql              |
| performance_schema |
| slowtech           |
| sys                |
 
Wow! slowtech is there.
 
mysql> use slowtech;
Database changed
mysql>
 
So, we can only conclude that slowtech is actually cloned. Now Let's look at
the data directory...
 
ll /data/mysql/3307
 
drwxr-x---  2 mysql mysql     4096 Jun  4 16:44  slowtech/
 
So the directory also have appeared.
 
What is happening under the hood is apparent by looking at the server log
while starting mysqld ...
 
2020-06-04T11:14:41.828769Z 1 [Note] [MY-011977] [InnoDB] Clone Fixup: check
and create schema directory
...
2020-06-04T11:14:41.831196Z 0 [Note] [MY-011977] [InnoDB] Clone: Fixed
Schema: slowtech task: 0
 
So, I think we should agree that there is no real issue here.
[29 Jun 2020 13:07] MySQL Verification Team
Thank you, Erlend ......