Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(PITR): embed mysqlbinlog (#1266)

h3n4ldbfc22f41865
diff --git a/resources/README.md b/resources/README.md
index d7dd8ac8e9..7bc60f78b1 100644
--- a/resources/README.md
+++ b/resources/README.md
@@ -21,3 +21,11 @@ We will embed MySQL binaries for testing. You need to run `go generate -tags mys
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
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
+
+### mysqlbinlog
+
+We embed mysqlbinlog for PITR. MySQL does not provide a separate mysqlbinlog binary, 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, 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, lib/libcrypto.1.1.dylib and lib/libssl.1.1.dylib.
diff --git a/resources/mysqlbinlog/mysqlbinlog_test.go b/resources/mysqlbinlog/mysqlbinlog_test.go
new file mode 100644
index 0000000000..b5d26d7bf6
--- /dev/null
+++ b/resources/mysqlbinlog/mysqlbinlog_test.go
@@ -0,0 +1,50 @@
+package mysqlbinlog
+
+import (
+ "fmt"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "runtime"
+ "testing"
+
+ "github.com/bytebase/bytebase/resources/utils"
+ "github.com/stretchr/testify/require"
+)
+
+// TestRunBinary tests whether mysqlbinlog can be started on the target platform
+// to check whether the lib extraction is correct.
+func TestRunBinary(t *testing.T) {
+ a := require.New(t)
+
+ var tarName string
+ var version string
+ fmt.Println(runtime.GOOS, runtime.GOARCH)
+ switch {
+ case runtime.GOOS == "darwin" && runtime.GOARCH == "arm64":
+ tarName = "mysqlbinlog-8.0.28-macos11-arm64.tar.gz"
+ version = "mysqlbinlog-8.0.28-macos11-arm64"
+ case runtime.GOOS == "linux" && runtime.GOARCH == "amd64":
+ tarName = "mysqlbinlog-8.0.28-linux-glibc-2.17-x86_64.tar.gz"
+ version = "mysqlbinlog-8.0.28-linux-glibc-2.17-x86_64"
+ default:
+ t.Fatalf("Unsupported combination of OS[%s] and ARCH[%s]", runtime.GOOS, runtime.GOARCH)
+ }
+
+ tarF, err := resources.Open(tarName)
+ a.NoError(err)
+
+ defer tarF.Close()
+
+ tmpDir := t.TempDir()
+ err = utils.ExtractTarGz(tarF, tmpDir)
+ a.NoError(err)
+
+ mysqlbinlogPath := filepath.Join(tmpDir, version, "bin", "mysqlbinlog")
+ cmd := exec.Command(mysqlbinlogPath, "-V")
+ cmd.Stdout = os.Stderr
+ cmd.Stderr = os.Stderr
+
+ err = cmd.Run()
+ a.NoError(err)
+}
diff --git a/resources/mysqlbinlog/resources_darwin.go b/resources/mysqlbinlog/resources_darwin.go
new file mode 100644
index 0000000000..1a0385ba57
--- /dev/null
+++ b/resources/mysqlbinlog/resources_darwin.go
@@ -0,0 +1,9 @@
+//go:build darwin && arm64
+// +build darwin,arm64
+
+package mysqlbinlog
+
+import "embed"
+
+//go:embed mysqlbinlog-8.0.28-macos11-arm64.tar.gz
+var resources embed.FS
diff --git a/resources/mysqlbinlog/resources_linux_x86_64.go b/resources/mysqlbinlog/resources_linux_x86_64.go
new file mode 100644
index 0000000000..30c4b4e4b5
--- /dev/null
+++ b/resources/mysqlbinlog/resources_linux_x86_64.go
@@ -0,0 +1,9 @@
+//go:build linux && amd64
+// +build linux,amd64
+
+package mysqlbinlog
+
+import "embed"
+
+//go:embed mysqlbinlog-8.0.28-linux-glibc-2.17-x86_64.tar.gz
+var resources embed.FS