2022-05-23 16:26:27 +00:00
|
|
|
package control
|
2022-01-25 11:57:58 +00:00
|
|
|
|
|
|
|
import (
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/services/control"
|
2022-01-25 11:57:58 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
restoreFilepathFlag = "path"
|
|
|
|
restoreIgnoreErrorsFlag = "no-errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
var restoreShardCmd = &cobra.Command{
|
|
|
|
Use: "restore",
|
|
|
|
Short: "Restore objects from shard",
|
|
|
|
Long: "Restore objects from shard to a file",
|
|
|
|
Run: restoreShard,
|
|
|
|
}
|
|
|
|
|
|
|
|
func restoreShard(cmd *cobra.Command, _ []string) {
|
2022-05-24 08:22:23 +00:00
|
|
|
pk := key.Get(cmd)
|
2022-01-25 11:57:58 +00:00
|
|
|
|
|
|
|
body := new(control.RestoreShardRequest_Body)
|
2022-05-23 16:26:27 +00:00
|
|
|
body.SetShardID(getShardID(cmd))
|
2022-01-25 11:57:58 +00:00
|
|
|
|
|
|
|
p, _ := cmd.Flags().GetString(restoreFilepathFlag)
|
|
|
|
body.SetFilepath(p)
|
|
|
|
|
|
|
|
ignore, _ := cmd.Flags().GetBool(restoreIgnoreErrorsFlag)
|
|
|
|
body.SetIgnoreErrors(ignore)
|
|
|
|
|
|
|
|
req := new(control.RestoreShardRequest)
|
|
|
|
req.SetBody(body)
|
|
|
|
|
2022-05-23 16:26:27 +00:00
|
|
|
signRequest(cmd, pk, req)
|
2022-01-25 11:57:58 +00:00
|
|
|
|
2022-05-23 16:26:27 +00:00
|
|
|
cli := getClient(cmd, pk)
|
2022-01-25 11:57:58 +00:00
|
|
|
|
2022-03-11 15:24:11 +00:00
|
|
|
var resp *control.RestoreShardResponse
|
2022-05-23 16:26:27 +00:00
|
|
|
var err error
|
2022-03-11 15:24:11 +00:00
|
|
|
err = cli.ExecRaw(func(client *client.Client) error {
|
|
|
|
resp, err = control.RestoreShard(client, req)
|
|
|
|
return err
|
|
|
|
})
|
2022-05-18 11:03:40 +00:00
|
|
|
common.ExitOnErr(cmd, "rpc error: %w", err)
|
2022-01-25 11:57:58 +00:00
|
|
|
|
2022-05-23 16:26:27 +00:00
|
|
|
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
2022-01-25 11:57:58 +00:00
|
|
|
|
|
|
|
cmd.Println("Shard has been restored successfully.")
|
|
|
|
}
|
|
|
|
|
|
|
|
func initControlRestoreShardCmd() {
|
2022-10-17 15:37:15 +00:00
|
|
|
initControlFlags(restoreShardCmd)
|
2022-01-25 11:57:58 +00:00
|
|
|
|
|
|
|
flags := restoreShardCmd.Flags()
|
2022-05-23 16:26:27 +00:00
|
|
|
flags.String(shardIDFlag, "", "Shard ID in base58 encoding")
|
2022-01-25 11:57:58 +00:00
|
|
|
flags.String(restoreFilepathFlag, "", "File to read objects from")
|
|
|
|
flags.Bool(restoreIgnoreErrorsFlag, false, "Skip invalid/unreadable objects")
|
|
|
|
|
|
|
|
_ = restoreShardCmd.MarkFlagRequired(shardIDFlag)
|
|
|
|
_ = restoreShardCmd.MarkFlagRequired(restoreFilepathFlag)
|
|
|
|
_ = restoreShardCmd.MarkFlagRequired(controlRPC)
|
|
|
|
}
|