Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit d38a948

Browse files
committed
Gzip files
Signed-off-by: JoshVanL <[email protected]>
1 parent d612a62 commit d38a948

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

pkg/tarmak/snapshot/consul/consul.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (c *Consul) Save() error {
6666
cmdArgs := append(envCmd,
6767
strings.Split(fmt.Sprintf(consulCmd, "save", hostPath), " ")...)
6868
cmdArgs = append(cmdArgs,
69-
strings.Split(fmt.Sprintf(snapshot.TarCCmd, hostPath), " ")...)
69+
strings.Split(fmt.Sprintf(snapshot.GZipCCmd, hostPath), " ")...)
7070

7171
err = c.sshCmd(
7272
aliases[0],
@@ -96,11 +96,10 @@ func (c *Consul) Restore() error {
9696
hostPath := fmt.Sprintf("/tmp/consul-snapshot-%s.snap",
9797
time.Now().Format(snapshot.TimeLayout))
9898

99-
cmdArgs := strings.Split(fmt.Sprintf(snapshot.TarXCmd, hostPath), " ")
100-
//cmdArgs := strings.Split(snapshot.TarXCmd, " ")
101-
//cmdArgs = append(cmdArgs,
102-
// append(envCmd,
103-
// strings.Split(fmt.Sprintf(consulCmd, "restore", hostPath), " ")...)...)
99+
cmdArgs := strings.Split(fmt.Sprintf(snapshot.GZipDCmd, hostPath, hostPath), " ")
100+
cmdArgs = append(cmdArgs,
101+
append(envCmd,
102+
strings.Split(fmt.Sprintf(consulCmd, "restore", hostPath), " ")...)...)
104103

105104
var result *multierror.Error
106105
var errLock sync.Mutex

pkg/tarmak/snapshot/etcd/etcd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (e *Etcd) Save() error {
8585
cmdArgs := append(e.template(envCmd, store),
8686
strings.Split(fmt.Sprintf(etcdctlCmd, "save", hostPath), " ")...)
8787
cmdArgs = append(cmdArgs,
88-
strings.Split(fmt.Sprintf(snapshot.TarCCmd, hostPath), " ")...)
88+
strings.Split(fmt.Sprintf(snapshot.GZipCCmd, hostPath), " ")...)
8989

9090
err = e.sshCmd(
9191
aliases[0],

pkg/tarmak/snapshot/snapshot.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ import (
1616

1717
const (
1818
TimeLayout = "2006-01-02_15-04-05"
19-
TarCCmd = "tar -czPf - %s"
20-
//TarXCmd = "cat | tar -xz | cat > /tmp/foo" //| cat > %s"
21-
TarXCmd = "cat > %s"
19+
GZipCCmd = "gzip -c %s;"
20+
GZipDCmd = "cat > %s.gz; gzip -d %s.gz;"
2221
)
2322

2423
func Prepare(tarmak interfaces.Tarmak, role string) (aliases []string, err error) {
@@ -79,6 +78,7 @@ func ReadTarFromStream(dest string, stream io.Reader, result *multierror.Error,
7978

8079
return
8180
}
81+
defer f.Close()
8282

8383
if _, err := io.Copy(f, gzr); err != nil {
8484

@@ -91,8 +91,7 @@ func ReadTarFromStream(dest string, stream io.Reader, result *multierror.Error,
9191
}
9292

9393
func WriteTarToStream(src string, stream io.WriteCloser, result *multierror.Error, errLock sync.Mutex) {
94-
//defer stream.Close()
95-
94+
defer stream.Close()
9695
f, err := os.Open(src)
9796
if err != nil {
9897

@@ -102,8 +101,11 @@ func WriteTarToStream(src string, stream io.WriteCloser, result *multierror.Erro
102101

103102
return
104103
}
104+
defer f.Close()
105105

106106
gzw := gzip.NewWriter(stream)
107+
defer gzw.Close()
108+
107109
if _, err := io.Copy(gzw, f); err != nil {
108110

109111
errLock.Lock()

0 commit comments

Comments
 (0)