-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargs.go
More file actions
49 lines (45 loc) · 1.28 KB
/
Copy pathargs.go
File metadata and controls
49 lines (45 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package mysqlcommon
import (
"strconv"
"github.com/nixrajput/siphon/internal/driver"
)
// BuildDumpArgs assembles the mysqldump argument vector for a backup. The
// binary name itself is supplied by the caller (mysqldump vs mariadb-dump).
func BuildDumpArgs(p driver.Profile, opt driver.BackupOpts) []string {
args := []string{
"-h", p.Host,
"-P", strconv.Itoa(p.Port),
"-u", p.User,
"--single-transaction",
"--routines",
"--triggers",
"--events",
"--no-tablespaces",
"--skip-comments",
p.Database,
}
if opt.SchemaOnly {
args = append(args, "--no-data")
}
if opt.DataOnly {
args = append(args, "--no-create-info")
}
args = append(args, opt.IncludeTables...)
for _, t := range opt.ExcludeTables {
args = append(args, "--ignore-table="+p.Database+"."+t)
}
return args
}
// BuildRestoreArgs assembles the mysql client argument vector for a restore.
// The dump file is authoritative for shape; the restore client just pipes it
// in. Clean is a no-op here because mysqldump output already emits
// DROP TABLE IF EXISTS / CREATE TABLE, making the restore idempotent.
func BuildRestoreArgs(p driver.Profile, _ driver.RestoreOpts) []string {
return []string{
"-h", p.Host,
"-P", strconv.Itoa(p.Port),
"-u", p.User,
"--default-character-set=utf8mb4",
p.Database,
}
}