3
0
mirror of https://kolaente.dev/konrad/docker-db-backup.git synced 2026-01-09 12:40:07 +01:00

feat: restructure writing to the file

This commit is contained in:
kolaente
2021-12-05 13:24:06 +01:00
parent 861824dbfe
commit 3fc3b8cb18

35
save.go
View File

@@ -4,21 +4,14 @@ import (
"bytes"
"context"
"fmt"
"io"
"os"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/stdcopy"
"io"
"os"
)
func runAndSaveCommandInContainer(filename string, c *client.Client, container *types.ContainerJSON, command string, args ...string) error {
f, err := os.Create(filename)
if err != nil {
return err
}
defer f.Close()
ctx := context.Background()
config := types.ExecConfig{
@@ -48,27 +41,23 @@ func runAndSaveCommandInContainer(filename string, c *client.Client, container *
outputDone <- err
}()
select {
case err := <-outputDone:
if err != nil {
return err
}
break
case <-ctx.Done():
return ctx.Err()
}
_, err = c.ContainerExecInspect(ctx, r.ID)
err = <-outputDone
if err != nil {
fmt.Printf(errBuf.String())
return err
}
_, err = io.Copy(f, &outBuf)
_, err = c.ContainerExecInspect(ctx, r.ID)
if err != nil {
return err
}
return nil
f, err := os.Create(filename)
if err != nil {
return err
}
defer f.Close()
_, err = io.Copy(f, &outBuf)
return err
}