Skip to content

Commit

Permalink
Add help subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
katie31 committed Aug 16, 2017
1 parent c255a21 commit c7632da
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 23 deletions.
22 changes: 21 additions & 1 deletion cmd/wal-g/main.go
Expand Up @@ -44,6 +44,26 @@ func main() {
command := all[0]
dirArc := all[1]

// Usage strings for supported commands
if dirArc == "-h" {
switch command {
case "backup-fetch":
fmt.Printf("usage:\twal-g backup-fetch output_directory backup_name\n\twal-g backup-fetch output_directory LATEST\n\n")
os.Exit(0)
case "backup-push":
fmt.Printf("usage:\twal-g backup-push backup_directory\n\n")
os.Exit(0)
case "wal-fetch":
fmt.Printf("usage:\twal-g wal-fetch wal_name file_name\n\t wal_name: name of WAL archive\n\t file_name: name of file to be written to\n\n")
os.Exit(0)
case "wal-push":
fmt.Printf("usage:\twal-g wal-push archive_path\n\n")
os.Exit(0)
default:
l.Fatalf("Command '%s' is unsupported by WAL-G.\n\n", command)
}
}

var backupName string
if len(all) == 3 {
backupName = all[2]
Expand Down Expand Up @@ -137,7 +157,7 @@ func main() {
log.Fatalf("%+v\n", err)
}

// Check name for backwards compatability. Will check for `pg_control` if WALG version of backup.
// Check name for backwards compatibility. Will check for `pg_control` if WALG version of backup.
re := regexp.MustCompile(`^([^_]+._{1}[^_]+._{1})`)
match := re.FindString(*bk.Name)

Expand Down
3 changes: 3 additions & 0 deletions decompress.go
Expand Up @@ -20,7 +20,10 @@ func (r *RaskyReader) Read(p []byte) (int, error) {
return io.ReadFull(r.R, p)
}

// Uncompressed is used to log compression ratio.
var Uncompressed uint32

// Compressed is used to log compression ratio.
var Compressed uint32

// CheckType grabs the file extension from PATH.
Expand Down
21 changes: 9 additions & 12 deletions extract.go
Expand Up @@ -9,10 +9,10 @@ import (
)

func min(a, b int) int {
if a < b {
return a
}
return b
if a < b {
return a
}
return b
}

// EmptyWriteIgnorer handles 0 byte write in LZ4 package
Expand Down Expand Up @@ -105,10 +105,9 @@ func ExtractAll(ti TarInterpreter, files []ReaderMaker) error {
}
}()


// Set maximum number of goroutines spun off by ExtractAll
var con int

conc, ok := os.LookupEnv("WALG_MAXCONCURRENCY")
if ok {
con, _ = strconv.Atoi(conc)
Expand All @@ -121,11 +120,10 @@ func ExtractAll(ti TarInterpreter, files []ReaderMaker) error {
concurrent <- Empty{}
}


for i, val := range files {
<- concurrent
<-concurrent
go func(i int, val ReaderMaker) {
defer func () {
defer func() {
concurrent <- Empty{}
sem <- Empty{}
}()
Expand All @@ -139,7 +137,7 @@ func ExtractAll(ti TarInterpreter, files []ReaderMaker) error {
go func() {
collectLow <- tarHandler(pw, val)
}()

// Collect errors returned by extractOne.
collectTop := make(chan error)

Expand All @@ -162,11 +160,10 @@ func ExtractAll(ti TarInterpreter, files []ReaderMaker) error {
collectAll <- err
}
}

}(i, val)
}


for i := 0; i < len(files); i++ {
<-sem
}
Expand Down
1 change: 1 addition & 0 deletions structs.go
Expand Up @@ -39,6 +39,7 @@ func init() {
EXCLUDE["pg_subtrans"] = Empty{}
}

// Empty is used for channel signaling.
type Empty struct{}

// TarBundle represents one completed directory.
Expand Down
10 changes: 5 additions & 5 deletions testTools/readerMaker.go
Expand Up @@ -6,16 +6,16 @@ import (
"os"
)

// HttpReaderMaker decompresses lzop tarballs from
// HTTPReaderMaker decompresses lzop tarballs from
// the passed in url.
type HttpReaderMaker struct {
type HTTPReaderMaker struct {
Client *http.Client
Key string
FileFormat string
}

func (h *HttpReaderMaker) Format() string { return h.FileFormat }
func (h *HttpReaderMaker) Path() string { return h.Key }
func (h *HTTPReaderMaker) Format() string { return h.FileFormat }
func (h *HTTPReaderMaker) Path() string { return h.Key }

// FileReaderMaker decompresses lzop tarballs from
// the passed in file.
Expand All @@ -29,7 +29,7 @@ func (f *FileReaderMaker) Path() string { return f.Key }

// Reader creates a new request to grab the data generated
// by the random bytes generator.
func (h *HttpReaderMaker) Reader() (io.ReadCloser, error) {
func (h *HTTPReaderMaker) Reader() (io.ReadCloser, error) {
get, err := http.NewRequest("GET", h.Key, nil)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion testTools/tarballMaker.go
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/katie31/wal-g"
)

// FileTarMaker creates a new FileTarBall
// FileTarBallMaker creates a new FileTarBall
// with the directory that files should be
// extracted to.
type FileTarBallMaker struct {
Expand Down
3 changes: 0 additions & 3 deletions upload_test.go
Expand Up @@ -103,9 +103,6 @@ func TestConfigure(t *testing.T) {

}

/**
* Tests that client is valid and created a new tar uploader.
*/
func TestValidUploader(t *testing.T) {
mockSvc := &mockS3Client{}

Expand Down
5 changes: 4 additions & 1 deletion walk.go
Expand Up @@ -10,14 +10,17 @@ import (
"strings"
)

type ZeroReader struct {}
// ZeroReader generates a slice of zeroes. Used to pad
// tar in cases where length of file changes.
type ZeroReader struct{}

func (z *ZeroReader) Read(p []byte) (int, error) {
zeroes := make([]byte, len(p))
n := copy(p, zeroes)
return n, nil

}

// TarWalker walks files provided by the passed in directory
// and creates compressed tar members labeled as `part_00i.tar.lzo`.
//
Expand Down

0 comments on commit c7632da

Please sign in to comment.