Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: embed mysqldump (#2109)
h3n4ld1ca448991e6
diff --git a/resources/README.md b/resources/README.mdindex 2cf96e0e67..db7a5292e1 100644--- a/resources/README.md+++ b/resources/README.md@@ -22,10 +22,10 @@ macos11-arm64 used for MacOS Apple Silicon development (MD5 f1943053b12428e4c0e4### mysqlutil-We embed mysqlutil for PITR. MySQL does not provide separate mysql and mysqlbinlog binaries, and we need to extract our files from the MySQL distribution manually.+We embed mysqlutil for PITR. MySQL does not provide separate mysql, mysqldump and mysqlbinlog binaries, and we need to extract our files from the MySQL distribution manually.-linux-glibc2.17-x86_64 used for Linux (MD5 55a7759e25cc527416150c8181ce3f6d): https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.28-linux-glibc2.17-x86_64-minimal.tar.xz, extract bin/mysqlbinlog, bin/mysql, lib/private/libcrypto.so.1.1 and lib/private/libssl.so.1.1.+linux-glibc2.17-x86_64 used for Linux (MD5 55a7759e25cc527416150c8181ce3f6d): https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.28-linux-glibc2.17-x86_64-minimal.tar.xz, extract bin/mysqlbinlog, bin/mysql, bin/mysqldump, lib/private/libcrypto.so.1.1 and lib/private/libssl.so.1.1.-macos11-arm64 used for MacOS Apple Silicon development (MD5 f1943053b12428e4c0e4ed309a636fd0): https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.28-macos11-arm64.tar.gz, extract bin/mysqlbinlog, bin/mysql, lib/libcrypto.1.1.dylib and lib/libssl.1.1.dylib.+macos11-arm64 used for MacOS Apple Silicon development (MD5 f1943053b12428e4c0e4ed309a636fd0): https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.28-macos11-arm64.tar.gz, extract bin/mysqlbinlog, bin/mysql, bin/mysqldump, lib/libcrypto.1.1.dylib and lib/libssl.1.1.dylib.-macos11-x86_64 used for MacOS Intel Silicon development (MD5 b2d5b57edb92811040fd61c84f1c9d6f): https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.28-macos11-x86_64.tar.gz, extract bin/mysqlbinlog, bin/mysql, lib/libcrypto.1.1.dylib and lib/libssl.1.1.dylib.+macos11-x86_64 used for MacOS Intel Silicon development (MD5 b2d5b57edb92811040fd61c84f1c9d6f): https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.28-macos11-x86_64.tar.gz, extract bin/mysqlbinlog, bin/mysql, bin/mysqldump, lib/libcrypto.1.1.dylib and lib/libssl.1.1.dylib.diff --git a/resources/mysqlutil/mysqlutil.go b/resources/mysqlutil/mysqlutil.goindex 4d6c5bb478..0a0ff4096c 100644--- a/resources/mysqlutil/mysqlutil.go+++ b/resources/mysqlutil/mysqlutil.go@@ -20,12 +20,15 @@ const (MySQL binaryName = "mysql"// MySQLBinlog is the name of mysqlbinlog binary.MySQLBinlog binaryName = "mysqlbinlog"+ // MySQLDump is the name of mysqldump binary.+ MySQLDump binaryName = "mysqldump")// Instance involve the path of all binaries binary.type Instance struct {mysqlBinPath stringmysqlbinlogBinPath string+ mysqldumpBinPath string}// GetPath returns the binary path specified by `binName`.@@ -35,6 +38,8 @@ func (ins *Instance) GetPath(binName binaryName) string {return ins.mysqlBinPathcase MySQLBinlog:return ins.mysqlbinlogBinPath+ case MySQLDump:+ return ins.mysqldumpBinPath}return "UNKNOWN"}@@ -48,6 +53,8 @@ func (ins *Instance) Version(binName binaryName) (string, error) {cmd = exec.Command(ins.GetPath(MySQL), "-V")case MySQLBinlog:cmd = exec.Command(ins.GetPath(MySQLBinlog), "-V")+ case MySQLDump:+ cmd = exec.Command(ins.GetPath(MySQLDump), "-V")default:return "", fmt.Errorf("unknown binary name: %s", binName)}@@ -86,28 +93,39 @@ func Install(resourceDir string) (*Instance, error) {}}- // TODO(zp): remove this block in the next few months- // We change Dockerfile's base image from alpine to debian slim in v1.2.1,- // and add libncurses.so.5 and libtinfo.so.5 to make mysqlbinlog run successfully.- // So we need to reinstall mysqlutil if the users upgrade from an older version that missing these shared libraries.- libncursesPath := path.Join(mysqlutilDir, "lib", "private", "libncurses.so.5")- if _, err := os.Stat(libncursesPath); err != nil {- if !os.IsNotExist(err) {- return nil, fmt.Errorf("failed to check libncurses library path %q, error: %w", libncursesPath, err)- }- // Remove mysqlutil of old version and reinstall it- if err := os.RemoveAll(mysqlutilDir); err != nil {- return nil, fmt.Errorf("failed to remove the old version mysqlutil binary directory %q, error: %w", mysqlutilDir, err)- }- // Install the current version- if err := install(resourceDir, mysqlutilDir, tarName, version); err != nil {- return nil, fmt.Errorf("cannot install mysqlutil, error: %w", err)+ checks := []string{+ // TODO(zp): remove this line in the next few months+ // We change Dockerfile's base image from alpine to debian slim in v1.2.1,+ // and add libncurses.so.5 and libtinfo.so.5 to make mysqlbinlog run successfully.+ // So we need to reinstall mysqlutil if the users upgrade from an older version that missing these shared libraries.+ path.Join(mysqlutilDir, "lib", "private", "libncurses.so.5"),+ path.Join(mysqlutilDir, "lib", "private", "libtinfo.so.5"),++ // We embed mysqldump in version v1.2.3.+ path.Join(mysqlutilDir, "bin", "mysqldump"),+ }++ for _, fp := range checks {+ if _, err := os.Stat(fp); err != nil {+ if !os.IsNotExist(err) {+ return nil, fmt.Errorf("failed to check libncurses library path %q, error: %w", fp, err)+ }+ // Remove mysqlutil of old version and reinstall it+ if err := os.RemoveAll(mysqlutilDir); err != nil {+ return nil, fmt.Errorf("failed to remove the old version mysqlutil binary directory %q, error: %w", mysqlutilDir, err)+ }+ // Install the current version+ if err := install(resourceDir, mysqlutilDir, tarName, version); err != nil {+ return nil, fmt.Errorf("cannot install mysqlutil, error: %w", err)+ }+ break}}return &Instance{mysqlBinPath: filepath.Join(mysqlutilDir, "bin", "mysql"),mysqlbinlogBinPath: filepath.Join(mysqlutilDir, "bin", "mysqlbinlog"),+ mysqldumpBinPath: filepath.Join(mysqlutilDir, "bin", "mysqldump"),}, nil}diff --git a/resources/mysqlutil/mysqlutil_test.go b/resources/mysqlutil/mysqlutil_test.goindex a815069aca..23e301f9eb 100644--- a/resources/mysqlutil/mysqlutil_test.go+++ b/resources/mysqlutil/mysqlutil_test.go@@ -28,6 +28,11 @@ func TestRunBinary(t *testing.T) {_, err := ins.Version(MySQLBinlog)a.NoError(err)})++ t.Run("run mysqldump", func(t *testing.T) {+ _, err := ins.Version(MySQLDump)+ a.NoError(err)+ })}// TODO(zp): remove this test when remove the related block in mysqlutil.go.@@ -44,21 +49,28 @@ func TestReinstallOnLinuxAmd64(t *testing.T) {instance, err := Install(tmpDir)a.NoError(err)- libDir := filepath.Join(tmpDir, "mysqlutil-8.0.28-linux-glibc2.17-x86_64" /*Hard code, don't care about this*/, "lib", "private")+ baseDir := filepath.Join(tmpDir, "mysqlutil-8.0.28-linux-glibc2.17-x86_64" /*Hard code, don't care about this*/)+ binDir := filepath.Join(baseDir, "bin")+ libDir := filepath.Join(baseDir, "lib", "private")++ checks := []string{+ filepath.Join(libDir, "libncurses.so.5"),+ filepath.Join(libDir, "libtinfo.so.5"),+ filepath.Join(binDir, "mysqldump"),+ }- libncursesPath := filepath.Join(libDir, "libncurses.so.5")- libtinfoPath := filepath.Join(libDir, "libtinfo.so.5")mysqlPath := instance.GetPath(MySQL)- a.FileExists(libncursesPath)- err = os.RemoveAll(libncursesPath)- a.NoError(err)- a.NoFileExists(libncursesPath)+ for _, fp := range checks {+ a.FileExists(fp)- _, err = Install(tmpDir)- a.NoError(err)+ err = os.RemoveAll(fp)+ a.NoError(err)+ a.NoFileExists(fp)- a.FileExists(libncursesPath)- a.FileExists(libtinfoPath)- a.FileExists(mysqlPath)+ _, err = Install(tmpDir)+ a.NoError(err)+ a.FileExists(fp)+ a.FileExists(mysqlPath)+ }}diff --git a/resources/mysqlutil/resources_linux_arm64.go b/resources/mysqlutil/resources_linux_arm64.goindex c55597032b..4c2c098b43 100644--- a/resources/mysqlutil/resources_linux_arm64.go+++ b/resources/mysqlutil/resources_linux_arm64.go@@ -5,6 +5,6 @@ package mysqlutilimport "embed"-//TODO(zp): need test for arm64+//TODO(zp): We cheat go build here, we don't provide mysqlutil on linux arm64 now.//go:embed mysqlutil-8.0.28-linux-glibc2.17-x86_64.tar.gzvar resources embed.FS