-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a v2 snapshot when running etcdutl migrate command
Signed-off-by: Benjamin Wang <[email protected]>
- Loading branch information
Showing
5 changed files
with
236 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2025 The etcd Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package etcdutl | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"go.etcd.io/etcd/pkg/v3/cobrautl" | ||
"go.etcd.io/etcd/server/v3/storage/backend" | ||
"go.etcd.io/etcd/server/v3/storage/datadir" | ||
) | ||
|
||
var createV2SnapDataDir string | ||
|
||
// NewV2SnapshotCommand returns the cobra command for "v2snapshot". | ||
// TODO: remove the command in 3.8 | ||
func NewV2SnapshotCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "v2snapshot <subcommand>", | ||
Short: "Manages etcd node v2snapshots", | ||
} | ||
cmd.AddCommand(newV2SnapshotCreateCommand()) | ||
return cmd | ||
} | ||
|
||
func newV2SnapshotCreateCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "create", | ||
Short: "Create a new v2 snapshot file", | ||
Run: v2SnapshotCreateFunc, | ||
} | ||
cmd.Flags().StringVar(&createV2SnapDataDir, "data-dir", "", "Required. Path to the etcd data directory.") | ||
cmd.MarkFlagRequired("data-dir") | ||
cmd.MarkFlagDirname("data-dir") | ||
return cmd | ||
} | ||
|
||
func v2SnapshotCreateFunc(_ *cobra.Command, _ []string) { | ||
be := backend.NewDefaultBackend(GetLogger(), filepath.Join(datadir.ToSnapDir(createV2SnapDataDir), "db")) | ||
defer be.Close() | ||
|
||
if err := createV2SnapshotFromV3Store(createV2SnapDataDir, be); err != nil { | ||
cobrautl.ExitWithError(cobrautl.ExitError, err) | ||
} | ||
fmt.Println("Created a v2 snapshot file.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters