Skip to content

Commit

Permalink
Merge branch 'release/0.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
syaiful6 committed May 10, 2023
2 parents 3e1082f + d94afd5 commit d3e6c35
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ This project has beed forked from [gobackup](https://github.com/huacnlee/gobacku

## Installation

Currently we don't provides binary release, you need to compile it from source yourself.

- Clone this repository: `git clone https://github.com/syaiful6/payung.git`
- Build the binary: `make build`
- Copy the output binary: `payung` to your PATH: `sudo cp payung /usr/local/bin`
You can download our current build in this repository's [release page](https://github.com/syaiful6/payung/releases) and place executable in your $PATH, ie: `/usr/local/bin/`.

## Configuration

Expand Down
9 changes: 6 additions & 3 deletions database/mariabackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package database

import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -169,14 +170,16 @@ func (ctx *MariaBackup) takeBackup(options []string) error {
if err != nil {
return fmt.Errorf("-> Create dump command line error: %s", err)
}
var errOut bytes.Buffer
mariabackup.Stderr = &errOut
stdoutPipe, err := mariabackup.StdoutPipe()
if err != nil {
return fmt.Errorf("-> Can't pipe stdout error: %s", err)
}

err = mariabackup.Start()
if err != nil {
return fmt.Errorf("-> can't start mariabackup error: %s", err)
return fmt.Errorf("-> can't start mariabackup error: %s. stderr: %s", err, errOut.String())
}
dumpFilePath := path.Join(ctx.dumpPath, "mariabackup.xb")
ext, r, err := compressor.CompressTo(ctx.model, bufio.NewReader(stdoutPipe))
Expand All @@ -186,7 +189,7 @@ func (ctx *MariaBackup) takeBackup(options []string) error {
dumpFilePath = dumpFilePath + ext
f, err := os.Create(dumpFilePath)
if err != nil {
return fmt.Errorf("-> error: can't create file for database dump: %s", err)
return fmt.Errorf("-> error: can't create file for database dump: %s, stderr:", err)
}
defer f.Close()
_, err = io.Copy(f, r)
Expand All @@ -195,7 +198,7 @@ func (ctx *MariaBackup) takeBackup(options []string) error {
}

if err = mariabackup.Wait(); err != nil {
return fmt.Errorf("-> Dump error: %s", err)
return fmt.Errorf("-> Dump error: %s, stderr: %s", err, errOut.String())
}

logger.Info("dump path:", ctx.dumpPath)
Expand Down
5 changes: 4 additions & 1 deletion database/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package database

import (
"bufio"
"bytes"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -86,6 +87,8 @@ func (ctx *MySQL) dump() error {
if err != nil {
return fmt.Errorf("-> Create dump command line error: %s", err)
}
var errOut bytes.Buffer
mysqldump.Stderr = &errOut
stdoutPipe, err := mysqldump.StdoutPipe()
if err != nil {
return fmt.Errorf("-> Can't pipe stdout error: %s", err)
Expand Down Expand Up @@ -113,7 +116,7 @@ func (ctx *MySQL) dump() error {
}

if err = mysqldump.Wait(); err != nil {
return fmt.Errorf("-> Dump error: %s", err)
return fmt.Errorf("-> Dump error: %s, stderr: %s", err, errOut.String())
}

logger.Info("dump path:", ctx.dumpPath)
Expand Down
5 changes: 4 additions & 1 deletion database/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package database

import (
"bufio"
"bytes"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -82,6 +83,8 @@ func (ctx *PostgreSQL) dump() error {
if err != nil {
return err
}
var errOut bytes.Buffer
pgDump.Stderr = &errOut
stdoutPipe, err := pgDump.StdoutPipe()
if err != nil {
return fmt.Errorf("-> Can't pipe stdout error: %s", err)
Expand Down Expand Up @@ -109,7 +112,7 @@ func (ctx *PostgreSQL) dump() error {
}

if err = pgDump.Wait(); err != nil {
return fmt.Errorf("-> Dump error: %s", err)
return fmt.Errorf("-> Dump error: %s, stderr: %s", err, errOut.String())
}

logger.Info("dump path:", ctx.dumpPath)
Expand Down
10 changes: 10 additions & 0 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func (ctx Model) run() (err error) {
return
}

ctx.cleanUpDump()

err = storage.Run(ctx.Config, backupPackage)
if err != nil {
logger.Error(err)
Expand All @@ -97,6 +99,14 @@ func (ctx Model) run() (err error) {
return
}

func (ctx Model) cleanUpDump() {
logger.Info("Cleanup dump folder: " + ctx.Config.DumpPath + "/\n")
err := os.RemoveAll(ctx.Config.DumpPath)
if err != nil {
logger.Error("Cleanup temp dir "+ctx.Config.DumpPath+" error:", err)
}
}

// Cleanup model temp files
func (ctx Model) cleanup() {
logger.Info("Cleanup temp: " + ctx.Config.TempPath + "/\n")
Expand Down

0 comments on commit d3e6c35

Please sign in to comment.