|
|
|
@@ -99,8 +99,8 @@ func (c *Client) Dump() error {
|
|
|
|
// Construct schema output
|
|
|
|
// Construct schema output
|
|
|
|
fmt.Printf("%s Dumping schema %s from %s\n\r",
|
|
|
|
fmt.Printf("%s Dumping schema %s from %s\n\r",
|
|
|
|
style.Success(icon.Info),
|
|
|
|
style.Success(icon.Info),
|
|
|
|
lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname),
|
|
|
|
|
|
|
|
lipgloss.NewStyle().Foreground(color.Yellow).Render(fmt.Sprint(c.databaseName)),
|
|
|
|
lipgloss.NewStyle().Foreground(color.Yellow).Render(fmt.Sprint(c.databaseName)),
|
|
|
|
|
|
|
|
lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
response, err := exec.Command(c.executable,
|
|
|
|
response, err := exec.Command(c.executable,
|
|
|
|
@@ -126,15 +126,15 @@ func (c *Client) Dump() error {
|
|
|
|
fmt.Printf(
|
|
|
|
fmt.Printf(
|
|
|
|
"%s Done dumping schema %s from %s\n\r",
|
|
|
|
"%s Done dumping schema %s from %s\n\r",
|
|
|
|
style.Success(icon.Check),
|
|
|
|
style.Success(icon.Check),
|
|
|
|
lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname),
|
|
|
|
|
|
|
|
lipgloss.NewStyle().Foreground(color.Yellow).Render(fmt.Sprint(c.databaseName)),
|
|
|
|
lipgloss.NewStyle().Foreground(color.Yellow).Render(fmt.Sprint(c.databaseName)),
|
|
|
|
|
|
|
|
lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
// Construct data output
|
|
|
|
// Construct data output
|
|
|
|
|
|
|
|
|
|
|
|
fmt.Printf("%s Dumping data %s from %s\n\r",
|
|
|
|
fmt.Printf("%s Dumping data %s from %s\n\r",
|
|
|
|
style.Success(icon.Info),
|
|
|
|
style.Success(icon.Info),
|
|
|
|
lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname),
|
|
|
|
|
|
|
|
lipgloss.NewStyle().Foreground(color.Yellow).Render(fmt.Sprint(c.databaseName)),
|
|
|
|
lipgloss.NewStyle().Foreground(color.Yellow).Render(fmt.Sprint(c.databaseName)),
|
|
|
|
|
|
|
|
lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
_ = exec.Command(c.executable,
|
|
|
|
_ = exec.Command(c.executable,
|
|
|
|
@@ -151,15 +151,15 @@ func (c *Client) Dump() error {
|
|
|
|
fmt.Printf(
|
|
|
|
fmt.Printf(
|
|
|
|
"%s Done dumping data %s from %s\n\r",
|
|
|
|
"%s Done dumping data %s from %s\n\r",
|
|
|
|
style.Success(icon.Check),
|
|
|
|
style.Success(icon.Check),
|
|
|
|
lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname),
|
|
|
|
|
|
|
|
lipgloss.NewStyle().Foreground(color.Yellow).Render(fmt.Sprint(c.databaseName)),
|
|
|
|
lipgloss.NewStyle().Foreground(color.Yellow).Render(fmt.Sprint(c.databaseName)),
|
|
|
|
|
|
|
|
lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Construct routines/triggers output
|
|
|
|
// Construct routines/triggers output
|
|
|
|
fmt.Printf("%s Dumping routines %s from %s\n\r",
|
|
|
|
fmt.Printf("%s Dumping routines %s from %s\n\r",
|
|
|
|
style.Success(icon.Info),
|
|
|
|
style.Success(icon.Info),
|
|
|
|
lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname),
|
|
|
|
|
|
|
|
lipgloss.NewStyle().Foreground(color.Yellow).Render(fmt.Sprint(c.databaseName)),
|
|
|
|
lipgloss.NewStyle().Foreground(color.Yellow).Render(fmt.Sprint(c.databaseName)),
|
|
|
|
|
|
|
|
lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
_ = exec.Command(c.executable,
|
|
|
|
_ = exec.Command(c.executable,
|
|
|
|
@@ -189,7 +189,7 @@ func removeDefiners(filename string) {
|
|
|
|
// Regex 1: .*(DEFINER=[a-zA-Z0-9\x60%@]+).* (Used by procedures/funcs)
|
|
|
|
// Regex 1: .*(DEFINER=[a-zA-Z0-9\x60%@]+).* (Used by procedures/funcs)
|
|
|
|
// Regex 2: .*(\/\*\!50003.*!50003+).* (Used by triggers)
|
|
|
|
// Regex 2: .*(\/\*\!50003.*!50003+).* (Used by triggers)
|
|
|
|
// Regex 3: (\/\*\!50013.*DEFINER \*\/) (Used in schema)
|
|
|
|
// Regex 3: (\/\*\!50013.*DEFINER \*\/) (Used in schema)
|
|
|
|
// TODO: Add routine body to strip definers.
|
|
|
|
|
|
|
|
expressions := make([]string, 3)
|
|
|
|
expressions := make([]string, 3)
|
|
|
|
expressions[0] = `s/(^.*)(.DEFINER=[a-zA-Z0-9\x60%@]+)(.*)/$1$3/g`
|
|
|
|
expressions[0] = `s/(^.*)(.DEFINER=[a-zA-Z0-9\x60%@]+)(.*)/$1$3/g`
|
|
|
|
expressions[1] = `s/(.*)(\/\*\!50003.*!50003+)(.*)/$1$3/g`
|
|
|
|
expressions[1] = `s/(.*)(\/\*\!50003.*!50003+)(.*)/$1$3/g`
|
|
|
|
@@ -248,37 +248,46 @@ func (c *Client) Combine() (string, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func ZipFile(filename string) (string, error) {
|
|
|
|
func ZipFile(filename string) (string, error) {
|
|
|
|
fmt.Println("creating zip archive")
|
|
|
|
|
|
|
|
//Create a new zip archive and named archive.zip
|
|
|
|
//Create a new zip archive and named archive.zip
|
|
|
|
archive, err := os.Create(util.FileNameWithoutExt(filename) + ".zip")
|
|
|
|
archive, err := os.Create(util.FileNameWithoutExt(filename) + ".zip")
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
panic(err)
|
|
|
|
// this is to catch errors if any
|
|
|
|
// this is to catch errors if any
|
|
|
|
}
|
|
|
|
}
|
|
|
|
defer archive.Close()
|
|
|
|
defer archive.Close()
|
|
|
|
fmt.Println("archive file created successfully....")
|
|
|
|
_, file := filepath.Split(filename)
|
|
|
|
|
|
|
|
|
|
|
|
//Create a new zip writer
|
|
|
|
//Create a new zip writer
|
|
|
|
zipWriter := zip.NewWriter(archive)
|
|
|
|
zipWriter := zip.NewWriter(archive)
|
|
|
|
fmt.Println("opening .sql file")
|
|
|
|
fmt.Printf(
|
|
|
|
|
|
|
|
"%s Opening .sql file\n\r",
|
|
|
|
|
|
|
|
style.Success(icon.Info),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
f1, err := os.Open(filename)
|
|
|
|
f1, err := os.Open(filename)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
defer f1.Close()
|
|
|
|
defer f1.Close()
|
|
|
|
fmt.Println("adding file to archive..")
|
|
|
|
fmt.Printf(
|
|
|
|
w1, err := zipWriter.Create(filename)
|
|
|
|
"%s Adding file to archive\n\r",
|
|
|
|
|
|
|
|
style.Success(icon.Info),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
w1, err := zipWriter.Create(file)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if _, err := io.Copy(w1, f1); err != nil {
|
|
|
|
if _, err := io.Copy(w1, f1); err != nil {
|
|
|
|
panic(err)
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Println("closing archive")
|
|
|
|
fmt.Printf(
|
|
|
|
|
|
|
|
"%s Closing archive\n\r",
|
|
|
|
|
|
|
|
style.Success(icon.Info),
|
|
|
|
|
|
|
|
)
|
|
|
|
zipWriter.Close()
|
|
|
|
zipWriter.Close()
|
|
|
|
f1.Close()
|
|
|
|
f1.Close()
|
|
|
|
_ = os.Remove(filename)
|
|
|
|
os.Remove(filename)
|
|
|
|
|
|
|
|
|
|
|
|
return util.FileNameWithoutExt(filename) + ".zip", nil
|
|
|
|
return util.FileNameWithoutExt(filename) + ".zip", nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|