Skip to content

Commit

Permalink
Merge pull request #1408 from Fizic/dev
Browse files Browse the repository at this point in the history
Implementation of the new binlog-server command
  • Loading branch information
teem0n committed Feb 6, 2023
2 parents bcac63d + 9a64ede commit 7c803f3
Show file tree
Hide file tree
Showing 9 changed files with 563 additions and 51 deletions.
47 changes: 47 additions & 0 deletions cmd/mysql/binlog_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package mysql

import (
"time"

"github.com/spf13/cobra"
"github.com/wal-g/tracelog"
"github.com/wal-g/wal-g/internal"
"github.com/wal-g/wal-g/internal/databases/mysql"
"github.com/wal-g/wal-g/utility"
)

const (
binlogServerShortDescription = "Create server for backup slaves"
untilFlagShortDescr = "time in RFC3339 for PITR"
)

var untilTS string

var (
binlogServerCmd = &cobra.Command{
Use: "binlog-server",
Short: binlogServerShortDescription,
Args: cobra.NoArgs,
PreRun: func(cmd *cobra.Command, args []string) {
internal.RequiredSettings[internal.MysqlBinlogServerHost] = true
internal.RequiredSettings[internal.MysqlBinlogServerPort] = true
internal.RequiredSettings[internal.MysqlBinlogServerUser] = true
internal.RequiredSettings[internal.MysqlBinlogServerPassword] = true
internal.RequiredSettings[internal.MysqlBinlogServerID] = true
internal.RequiredSettings[internal.MysqlBinlogServerReplicaSource] = true
err := internal.AssertRequiredSettingsSet()
tracelog.ErrorLogger.FatalOnError(err)
},
Run: func(cmd *cobra.Command, args []string) {
mysql.HandleBinlogServer(untilTS)
},
}
)

func init() {
binlogServerCmd.PersistentFlags().StringVar(&untilTS,
"until",
utility.TimeNowCrossPlatformUTC().Format(time.RFC3339),
untilFlagShortDescr)
cmd.AddCommand(binlogServerCmd)
}
24 changes: 23 additions & 1 deletion docs/MySQL.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ To place binlogs in the specified directory during binlog-fetch or binlog-replay
Set this variable to True if you are planning to take base backup from replica and binlog backup from master.
If base and binlogs backups are taken from the same host, this variable should be left False (default).

* `WALG_MYSQL_BINLOG_SERVER_HOST`
* `WALG_MYSQL_BINLOG_SERVER_PORT`
* `WALG_MYSQL_BINLOG_SERVER_USER`
* `WALG_MYSQL_BINLOG_SERVER_PASSWORD`

To configure the data to connect the replica to for binlog server.

* `WALG_MYSQL_BINLOG_SERVER_ID`

To configure the server id of the binlog server. Should be unique for each replica.

* `WALG_MYSQL_BINLOG_SERVER_REPLICA_SOURCE`

To configure the connection string for the replica that connects to the binlog server. Format ```user:password@host/dbname```

> **Operations with binlogs**: If you'd like to do binlog operations with wal-g don't forget to [activate the binary log](https://mariadb.com/kb/en/activating-the-binary-log/) by starting mysql/mariadb with [--log-bin](https://mariadb.com/kb/en/replication-and-binary-log-server-system-variables/#log_bin) and [--log-basename](https://mariadb.com/kb/en/mysqld-options/#-log-basename)=\[name\].

Expand Down Expand Up @@ -89,7 +104,6 @@ Sends (not yet archived) binlogs to storage. Typically run in CRON.
wal-g binlog-push
```


When `WALG_MYSQL_CHECK_GTIDS` is set wal-g will try to be upload only binlogs which GTID sets contains events that
wasn't seen before. This is done by parsing binlogs and peeking first PREVIOUS_GTIDS_EVENT that holds GTID set of
all executed transactions at the moment this particular binlog file created.
Expand Down Expand Up @@ -150,6 +164,14 @@ This may be useful to achieve exact clones of the same database in scenarios whe
wal-g binlog-replay --since LATEST --until "2006-01-02T15:04:05Z07:00" --until-binlog-last-modified-time "2006-01-02T15:04:05Z07:00"
```

### ``binlog-server``

Runs mysql server implementation which can be used to fetch binlogs from storage and send them to MySQL slave by replication protocol.

```bash
wal-g binlog-server
```

Typical configurations
-----

Expand Down
15 changes: 7 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ require (
github.com/cyberdelia/lzo v0.0.0-20171006181345-d85071271a6f
github.com/denisenkom/go-mssqldb v0.10.0
github.com/docker/docker v1.13.1
github.com/go-mysql-org/go-mysql v1.4.1-0.20220126055159-3566d1e608ea
github.com/go-mysql-org/go-mysql v1.7.0
github.com/go-redis/redis v6.15.6+incompatible
github.com/go-sql-driver/mysql v1.5.0
github.com/go-sql-driver/mysql v1.6.0
github.com/gofrs/flock v0.8.0
github.com/golang/mock v1.4.4
github.com/google/uuid v1.2.0
github.com/google/uuid v1.3.0
github.com/greenplum-db/gp-common-go-libs v1.0.4
github.com/hashicorp/golang-lru v0.5.4
github.com/jackc/pgconn v1.6.5-0.20200823013804-5db484908cf7
Expand All @@ -40,7 +40,7 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.0
github.com/stretchr/testify v1.7.1
github.com/stretchr/testify v1.8.0
github.com/ulikunitz/xz v0.5.8
github.com/wal-g/json v0.3.1
github.com/wal-g/tracelog v0.0.0-20190824100002-0ab2b054ff30
Expand All @@ -63,7 +63,7 @@ require (
github.com/prometheus/client_golang v1.12.1
github.com/prometheus/client_model v0.2.0
golang.org/x/mod v0.3.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
gopkg.in/yaml.v3 v3.0.1
)

require (
Expand Down Expand Up @@ -124,18 +124,17 @@ require (
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/pelletier/go-toml v1.7.0 // indirect
github.com/philhofer/fwd v1.0.0 // indirect
github.com/pingcap/errors v0.11.5-0.20201126102027-b0a155152ca3 // indirect
github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63 // indirect
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/satori/go.uuid v1.2.0 // indirect
github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc // indirect
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726 // indirect
github.com/siddontang/go-log v0.0.0-20180807004314-8d05993dda07 // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/tinylib/msgp v1.1.0 // indirect
github.com/willf/bitset v1.1.10 // indirect
Expand Down

0 comments on commit 7c803f3

Please sign in to comment.