Skip to content

Commit

Permalink
Merge pull request #107 from starkandwayne/mysql-replicas
Browse files Browse the repository at this point in the history
Added Read-only replicas support for mysql plugin
  • Loading branch information
geofffranks committed Feb 18, 2016
2 parents 7d0018c + d218525 commit 333646c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion plugin/mysql/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
// "mysql_user":"username-for-mysql",
// "mysql_password":"password-for-above-user",
// "mysql_host":"hostname-or-ip-of-mysql-server",
// "mysql_port":"port-above-mysql-server-listens-on"
// "mysql_port":"port-above-mysql-server-listens-on",
// "mysql_read_replica":"hostname-or-ip-of-mysql-replica-server" #OPTIONAL
// }
//
// BACKUP DETAILS
Expand Down Expand Up @@ -82,6 +83,7 @@ type MySQLConnectionInfo struct {
User string
Password string
Bin string
Replica string
}

func (p MySQLPlugin) Meta() PluginInfo {
Expand All @@ -95,6 +97,10 @@ func (p MySQLPlugin) Backup(endpoint ShieldEndpoint) error {
return err
}

if mysql.Replica != "" {
mysql.Host = mysql.Replica
}

cmd := fmt.Sprintf("%s/mysqldump --all-databases %s", mysql.Bin, connectionString(mysql))
DEBUG("Executing: `%s`", cmd)
return Exec(cmd, STDOUT)
Expand Down Expand Up @@ -156,6 +162,9 @@ func mysqlConnectionInfo(endpoint ShieldEndpoint) (*MySQLConnectionInfo, error)
}
DEBUG("MYSQLPORT: '%s'", port)

replica, _ := endpoint.StringValue("mysql_read_replica")
DEBUG("MYSQLREADREPLICA: '%s'", replica)

bin := "/var/vcap/packages/shield-mysql/bin"
DEBUG("MYSQLBINDIR: '%s'", bin)

Expand All @@ -165,5 +174,6 @@ func mysqlConnectionInfo(endpoint ShieldEndpoint) (*MySQLConnectionInfo, error)
User: user,
Password: password,
Bin: bin,
Replica: replica,
}, nil
}

0 comments on commit 333646c

Please sign in to comment.