Skip to content
This repository has been archived by the owner on Jul 4, 2022. It is now read-only.

Commit

Permalink
Merge pull request #51 from taku-k/feat/option-default-mycnf
Browse files Browse the repository at this point in the history
Add --defaults-file option for backup and restore commands
  • Loading branch information
taku-k authored Jul 25, 2017
2 parents bf5bf87 + 630cae3 commit 0a11fbe
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/base/xtrabackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type XtrabackupConfig struct {
InsecureAuth bool
Parallel int
UseMemory string
DefaultsFile string
}

type RestoreXtrabackupConfig struct {
Expand All @@ -35,6 +36,7 @@ type RestoreXtrabackupConfig struct {
IncDir string
Parallel int
UseMemory string
DefaultsFile string
}

func MakeXtrabackupConfig() *XtrabackupConfig {
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func init() {

f.StringVarP(&db, "db", "d", "", "DB name")
f.BoolVar(&useInnobackupex, "use-innobackupex", false, "Using innobackupex binary instead of xtrabackup.")
f.StringVar(&xtrabackupCfg.DefaultsFile, "defaults-file", xtrabackupCfg.DefaultsFile, "Read default MySQL options from the given file.")
}

// Backup commands flags
Expand Down
14 changes: 11 additions & 3 deletions pkg/utils/exec/xtrabackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ type backupCmd struct {

var xtrabackup = backupCmd{
fullTmpl: strings.TrimSpace(`
{{ .XtrabackupBinPath }} \
{{ .XtrabackupBinPath }} \{{ if .DefaultsFile }}
--defaults-file={{ .DefaultsFile }} \
{{- end }}
--host {{ .Host }} \
--port {{ .Port }} \
--user {{ .User }} \{{ if .Password }}
Expand All @@ -38,7 +40,9 @@ var xtrabackup = backupCmd{
--parallel {{ .Parallel }}
`),
incTmpl: strings.TrimSpace(`
{{ .XtrabackupBinPath }} \
{{ .XtrabackupBinPath }} \{{ if .DefaultsFile }}
--defaults-file={{ .DefaultsFile }} \
{{- end }}
--host {{ .Host }} \
--port {{ .Port }} \
--user {{ .User }} \{{ if .Password }}
Expand All @@ -56,7 +60,9 @@ var xtrabackup = backupCmd{
--parallel {{ .Parallel }}
`),
restoreTmpl: strings.TrimSpace(`
{{ .XtrabackupBinPath }} \
{{ .XtrabackupBinPath }} \{{ if .DefaultsFile }}
--defaults-file={{ .DefaultsFile }} \
{{- end }}
--target-dir base \{{ if not .IsLast }}
--apply-log-only \
{{- end }}{{ if .IncDir }}
Expand Down Expand Up @@ -145,6 +151,7 @@ func PrepareBaseBackup(
UseInnobackupex: cfg.UseInnobackupex,
IsLast: isLast,
UseMemory: cfg.UseMemory,
DefaultsFile: cfg.DefaultsFile,
}
return _prepareBackup(ctx, rcfg)
}
Expand All @@ -163,6 +170,7 @@ func PrepareIncBackup(
IsLast: isLast,
IncDir: fmt.Sprintf("inc%d", inc),
UseMemory: cfg.UseMemory,
DefaultsFile: cfg.DefaultsFile,
}
return _prepareBackup(ctx, rcfg)
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/utils/exec/xtrabackup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ func TestBuildFullBackupCmd(t *testing.T) {
LsnTempDir: "/tmp/test",
InsecureAuth: true,
Parallel: 1,
DefaultsFile: "/etc/mysql/my.cnf",
},
[]string{"sh", "-c", strings.TrimSpace(`
xtrabackup \
--defaults-file=/etc/mysql/my.cnf \
--host 127.0.0.1 \
--port 3306 \
--user user \
Expand All @@ -47,9 +49,11 @@ xtrabackup \
User: "user",
LsnTempDir: "/tmp/test",
Parallel: 1,
DefaultsFile: "/etc/mysql/my.cnf",
},
[]string{"sh", "-c", strings.TrimSpace(`
/usr/bin/xtrabackup \
--defaults-file=/etc/mysql/my.cnf \
--host 127.0.0.1 \
--port 3306 \
--user user \
Expand Down Expand Up @@ -85,11 +89,13 @@ func TestBuildIncBackupCmd(t *testing.T) {
LsnTempDir: "/tmp/test",
ToLsn: "100",
Parallel: 1,
DefaultsFile: "/etc/mysql/my.cnf",
}
cmd, err := BuildIncBackupCmd(context.Background(), cfg)

expected := []string{"sh", "-c", strings.TrimSpace(`
xtrabackup \
--defaults-file=/etc/mysql/my.cnf \
--host 127.0.0.1 \
--port 3306 \
--user user \
Expand Down Expand Up @@ -120,19 +126,23 @@ func TestPrepareBackupCmd(t *testing.T) {
XtrabackupBinPath: "xtrabackup",
IsLast: true,
Parallel: 4,
DefaultsFile: "/etc/mysql/my.cnf",
},
[]string{"sh", "-c", strings.TrimSpace(`
xtrabackup \
--defaults-file=/etc/mysql/my.cnf \
--target-dir base \
--parallel 4 \
--prepare`)},
}, {
&base.RestoreXtrabackupConfig{
XtrabackupBinPath: "xtrabackup",
IsLast: false,
DefaultsFile: "/etc/mysql/my.cnf",
},
[]string{"sh", "-c", strings.TrimSpace(`
xtrabackup \
--defaults-file=/etc/mysql/my.cnf \
--target-dir base \
--apply-log-only \
--prepare`)},
Expand All @@ -141,9 +151,11 @@ xtrabackup \
XtrabackupBinPath: "xtrabackup",
IsLast: true,
IncDir: "inc1",
DefaultsFile: "/etc/mysql/my.cnf",
},
[]string{"sh", "-c", strings.TrimSpace(`
xtrabackup \
--defaults-file=/etc/mysql/my.cnf \
--target-dir base \
--incremental-dir inc1 \
--prepare`)},
Expand All @@ -153,9 +165,11 @@ xtrabackup \
IsLast: false,
IncDir: "inc1",
UseMemory: "2GB",
DefaultsFile: "/etc/mysql/my.cnf",
},
[]string{"sh", "-c", strings.TrimSpace(`
xtrabackup \
--defaults-file=/etc/mysql/my.cnf \
--target-dir base \
--apply-log-only \
--incremental-dir inc1 \
Expand Down

0 comments on commit 0a11fbe

Please sign in to comment.