mysqldump: add --set-gtid-purged=COMMENTED to mysqldump command

The backup file taken from a charm-managed mysql instance contains
"@@GLOBAL.GTID_PURGED" variable at the beginning, which causes
restore operation to fail with the following message: "Cannot
update GTID_PURGED with the Group Replication plugin running".
The workaround for this issue is to supply "--set-gtid-purged=OFF"
to command, which omits the "GTID_PURGED" from the mysqldump output.

This patch fixes the issue by adding "--set-gtid-purged=COMMENTED"
to mysqldump command, which causes  mysqldump to emit the GTID_PURGED
variable as a commented out line. In this way, we don't lose the
GTID_PURGED variable information which may be needed in some scenarios
and can be un-commented out before restoring if needed.

Closes-bug: 1989975
Change-Id: Ie3b71a60e4c7afda48114a53cce9cf713b933d71
This commit is contained in:
Mustafa Kemal Gilor 2022-09-26 13:41:09 +03:00
parent cc500be2d1
commit 82ebc349fa
No known key found for this signature in database
GPG Key ID: FAF50F1C5306E2AC
2 changed files with 5 additions and 1 deletions

View File

@ -1756,7 +1756,8 @@ class MySQLInnoDBClusterCharm(charms_openstack.charm.OpenStackCharm):
bucmd = ["/usr/bin/mysqldump", "-u", _user,
"--triggers", "--routines", "--events",
"--ignore-table=mysql.event"]
"--ignore-table=mysql.event",
"--set-gtid-purged=COMMENTED"]
if databases is not None:
_filename = os.path.join(
backup_dir,

View File

@ -1502,6 +1502,7 @@ class TestMySQLInnoDBClusterCharm(test_utils.PatchHelper):
mock.call(
["/usr/bin/mysqldump", "-u", "root", "--triggers",
"--routines", "--events", "--ignore-table=mysql.event",
"--set-gtid-purged=COMMENTED",
"--result-file", _filename, "--all-databases"]),
mock.call(["/usr/bin/gzip", _filename])]
@ -1517,6 +1518,7 @@ class TestMySQLInnoDBClusterCharm(test_utils.PatchHelper):
mock.call(
["/usr/bin/mysqldump", "-u", "root", "-ppass", "--triggers",
"--routines", "--events", "--ignore-table=mysql.event",
"--set-gtid-purged=COMMENTED",
"--result-file", _filename, "--databases", _dbs]),
mock.call(["/usr/bin/gzip", _filename])]
self.assertEqual(midbc.mysqldump(_path, databases=_dbs),
@ -1531,6 +1533,7 @@ class TestMySQLInnoDBClusterCharm(test_utils.PatchHelper):
mock.call(
["/usr/bin/mysqldump", "-u", "root", "-ppass", "--triggers",
"--routines", "--events", "--ignore-table=mysql.event",
"--set-gtid-purged=COMMENTED",
"--result-file", _filename, "--databases"].extend(
_dbs.split(","))),
mock.call(["/usr/bin/gzip", _filename])]