Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3c5014e90b | |||
| 1cef099a37 | |||
| 292d582a45 |
@@ -68,6 +68,11 @@ to quickly create a Cobra application.`,
|
|||||||
"%s Completer combining dump files\n\r",
|
"%s Completer combining dump files\n\r",
|
||||||
style.Success(icon.Check),
|
style.Success(icon.Check),
|
||||||
)
|
)
|
||||||
|
fmt.Printf(
|
||||||
|
"%s Zipping file\n\r",
|
||||||
|
style.Success(icon.Info),
|
||||||
|
)
|
||||||
|
filename, _ = dump.ZipFile(filename)
|
||||||
timeElapsed := time.Since(start)
|
timeElapsed := time.Since(start)
|
||||||
fmt.Printf(
|
fmt.Printf(
|
||||||
"%s Dump file available at %s\r\nTook %s\n\r",
|
"%s Dump file available at %s\r\nTook %s\n\r",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package dump
|
package dump
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"archive/zip"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/charmbracelet/log"
|
"github.com/charmbracelet/log"
|
||||||
@@ -102,7 +103,7 @@ func (c *Client) Dump() error {
|
|||||||
lipgloss.NewStyle().Foreground(color.Yellow).Render(fmt.Sprint(c.databaseName)),
|
lipgloss.NewStyle().Foreground(color.Yellow).Render(fmt.Sprint(c.databaseName)),
|
||||||
)
|
)
|
||||||
|
|
||||||
_ = exec.Command(c.executable,
|
response, err := exec.Command(c.executable,
|
||||||
"--host="+c.hostname,
|
"--host="+c.hostname,
|
||||||
"--port="+strconv.Itoa(c.port),
|
"--port="+strconv.Itoa(c.port),
|
||||||
"--user="+c.username,
|
"--user="+c.username,
|
||||||
@@ -111,12 +112,16 @@ func (c *Client) Dump() error {
|
|||||||
"--no-data",
|
"--no-data",
|
||||||
"--skip-triggers",
|
"--skip-triggers",
|
||||||
"--result-file", filepath.Join(c.storagePath, c.databaseName+"-schema.sql"),
|
"--result-file", filepath.Join(c.storagePath, c.databaseName+"-schema.sql"),
|
||||||
c.databaseName).Run()
|
c.databaseName).CombinedOutput()
|
||||||
fmt.Printf("%s Removing definers\n\r",
|
if err != nil {
|
||||||
style.Success(icon.Info),
|
fmt.Printf(
|
||||||
)
|
"%s mysqldump error: %s\n\r",
|
||||||
|
style.Failure(icon.Cross),
|
||||||
// removeDefiners(filepath.Join(c.storagePath, c.databaseName+"-schema.sql"))
|
lipgloss.NewStyle().Foreground(color.Purple).Render(string(response)),
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
removeDefiners(filepath.Join(c.storagePath, c.databaseName+"-schema.sql"))
|
||||||
|
|
||||||
fmt.Printf(
|
fmt.Printf(
|
||||||
"%s Done dumping schema %s from %s\n\r",
|
"%s Done dumping schema %s from %s\n\r",
|
||||||
@@ -200,7 +205,8 @@ func removeDefiners(filename string) {
|
|||||||
|
|
||||||
outputFile, err := os.OpenFile(filename+".new", os.O_WRONLY|os.O_CREATE, 0666)
|
outputFile, err := os.OpenFile(filename+".new", os.O_WRONLY|os.O_CREATE, 0666)
|
||||||
_, _ = io.Copy(outputFile, engine.Wrap(inputFile))
|
_, _ = io.Copy(outputFile, engine.Wrap(inputFile))
|
||||||
|
_ = inputFile.Close()
|
||||||
|
_ = outputFile.Close()
|
||||||
err = util.MoveFile(filename+".new", filename)
|
err = util.MoveFile(filename+".new", filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf(
|
fmt.Printf(
|
||||||
@@ -240,3 +246,39 @@ func (c *Client) Combine() (string, error) {
|
|||||||
}
|
}
|
||||||
return filepath.Join(c.storagePath, c.databaseName+"-backup.sql"), nil
|
return filepath.Join(c.storagePath, c.databaseName+"-backup.sql"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ZipFile(filename string) (string, error) {
|
||||||
|
fmt.Println("creating zip archive")
|
||||||
|
//Create a new zip archive and named archive.zip
|
||||||
|
archive, err := os.Create(util.FileNameWithoutExt(filename) + ".zip")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
// this is to catch errors if any
|
||||||
|
}
|
||||||
|
defer archive.Close()
|
||||||
|
fmt.Println("archive file created successfully....")
|
||||||
|
|
||||||
|
//Create a new zip writer
|
||||||
|
zipWriter := zip.NewWriter(archive)
|
||||||
|
fmt.Println("opening .sql file")
|
||||||
|
|
||||||
|
f1, err := os.Open(filename)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer f1.Close()
|
||||||
|
fmt.Println("adding file to archive..")
|
||||||
|
w1, err := zipWriter.Create(filename)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if _, err := io.Copy(w1, f1); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Println("closing archive")
|
||||||
|
zipWriter.Close()
|
||||||
|
f1.Close()
|
||||||
|
_ = os.Remove(filename)
|
||||||
|
|
||||||
|
return util.FileNameWithoutExt(filename) + ".zip", nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func MoveFile(src, dst string) error {
|
func MoveFile(src, dst string) error {
|
||||||
@@ -39,9 +41,18 @@ func MoveFile(src, dst string) error {
|
|||||||
return fmt.Errorf("chmod error: %s", err)
|
return fmt.Errorf("chmod error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//err = in.Close()
|
||||||
|
//if err != nil {
|
||||||
|
// return fmt.Errorf("closing file failed: %s", err)
|
||||||
|
//}
|
||||||
|
//time.Sleep(time.Second * 10)
|
||||||
err = os.Remove(src)
|
err = os.Remove(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed removing original file: %s", err)
|
return fmt.Errorf("failed removing original file: %s", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FileNameWithoutExt(fileName string) string {
|
||||||
|
return strings.TrimSuffix(fileName, filepath.Ext(fileName))
|
||||||
|
}
|
||||||
|
|||||||
4
justfile
4
justfile
@@ -9,6 +9,10 @@ install:
|
|||||||
build:
|
build:
|
||||||
@echo -n "Building app ... "
|
@echo -n "Building app ... "
|
||||||
@go build {{flags}} -o bin/ && echo "OK" || echo "FAILED"
|
@go build {{flags}} -o bin/ && echo "OK" || echo "FAILED"
|
||||||
|
|
||||||
|
build-win:
|
||||||
|
@echo -n "Building app for windows ... "
|
||||||
|
@GOOS=windows GOARCH=amd64 go build {{flags}} -o bin/ && echo "OK" || echo "FAILED"
|
||||||
update:
|
update:
|
||||||
go get -u
|
go get -u
|
||||||
go mod tidy -v
|
go mod tidy -v
|
||||||
|
|||||||
Reference in New Issue
Block a user