Merge branch 'master' into fix-file-backup

This commit is contained in:
Kuba Podgórski 2021-05-24 18:29:44 +02:00 committed by GitHub
commit a1e7755fe7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 27 deletions

View file

@ -16,7 +16,6 @@ package cmd
import (
"context"
"fmt"
"io"
"github.com/pilosa/pilosa/v2/ctl"
@ -24,36 +23,28 @@ import (
)
func newRestoreCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
c := ctl.NewRestoreCommand(stdin, stdout, stderr)
cmd := ctl.NewRestoreCommand(stdin, stdout, stderr)
restoreCmd := &cobra.Command{
Use: "restore [flags] PATH ",
Short: "restore a backup",
Use: "restore",
Short: "Restore from a backup",
Long: `
The restore command will take a backup archive and restore it to a new, clean cluster.
The Restore command will take a backup archive and restore it to a new, clean cluster.
`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return fmt.Errorf("data directory path required")
} else if len(args) > 1 {
return fmt.Errorf("too many command line arguments")
}
c.Path = args[0]
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
return c.Run(context.Background())
RunE: func(c *cobra.Command, args []string) error {
return cmd.Run(context.Background())
},
}
flags := restoreCmd.Flags()
flags.StringVarP(&c.Host, "host", "", "localhost:10101", "host:port of Pilosa.")
flags.StringVarP(&c.Path, "source", "s", "", "pilosa backup file")
flags.StringVarP(&cmd.Path, "source", "s", "", "pilosa backup file; specify '-' to restore from stdin tar stream")
flags.StringVar(&cmd.Host, "host", "localhost:10101", "host:port of Pilosa.")
ctl.SetTLSConfig(
flags, "",
&c.TLS.CertificatePath,
&c.TLS.CertificateKeyPath,
&c.TLS.CACertPath,
&c.TLS.SkipVerify,
&c.TLS.EnableClientVerification)
&cmd.TLS.CertificatePath,
&cmd.TLS.CertificateKeyPath,
&cmd.TLS.CACertPath,
&cmd.TLS.SkipVerify,
&cmd.TLS.EnableClientVerification,
)
return restoreCmd
}

View file

@ -18,6 +18,7 @@ import (
"archive/tar"
"compress/gzip"
"context"
"crypto/tls"
"errors"
"fmt"
"io"
@ -33,8 +34,8 @@ import (
// RestoreCommand represents a command for restoring a backup to
type RestoreCommand struct {
TLS server.TLSConfig
Host string
tlsConfig *tls.Config
Host string
// Filepath to the backup file.
Path string
@ -43,6 +44,7 @@ type RestoreCommand struct {
// Standard input/output
*pilosa.CmdIO
TLS server.TLSConfig
}
// NewRestoreCommand returns a new instance of RestoreCommand.
@ -53,7 +55,7 @@ func NewRestoreCommand(stdin io.Reader, stdout, stderr io.Writer) *RestoreComman
}
// Run executes the restore.
func (cmd *RestoreCommand) Run(ctx context.Context) error {
func (cmd *RestoreCommand) Run(ctx context.Context) (err error) {
logger := cmd.Logger()
// Validate arguments.
@ -67,12 +69,18 @@ func (cmd *RestoreCommand) Run(ctx context.Context) error {
if useStdin {
f = os.Stdin
} else {
f, err := os.Open(cmd.Path)
f, err = os.Open(cmd.Path)
if err != nil {
return (err)
}
defer f.Close()
}
// Parse TLS configuration for node-specific clients.
tls := cmd.TLSConfiguration()
if cmd.tlsConfig, err = server.GetTLSConfig(&tls, logger); err != nil {
return fmt.Errorf("parsing tls config: %w", err)
}
// Create a client to the server.
client, err := commandClient(cmd)
if err != nil {