Move restore to snapshot restore subcommand
Renames the top-level `restore` command to `vaultik snapshot restore` for consistency with `vaultik snapshot create`. The factory follows the sibling pattern (newSnapshotRestoreCommand) and its file is renamed to snapshot_restore.go to match.
This commit is contained in:
@@ -78,7 +78,7 @@ vaultik snapshot verify <snapshot-id>
|
|||||||
VAULTIK_AGE_SECRET_KEY='AGE-SECRET-KEY-...' vaultik snapshot verify --deep <snapshot-id>
|
VAULTIK_AGE_SECRET_KEY='AGE-SECRET-KEY-...' vaultik snapshot verify --deep <snapshot-id>
|
||||||
|
|
||||||
# restore (requires the private key)
|
# restore (requires the private key)
|
||||||
VAULTIK_AGE_SECRET_KEY='AGE-SECRET-KEY-...' vaultik restore <snapshot-id> /tmp/restored
|
VAULTIK_AGE_SECRET_KEY='AGE-SECRET-KEY-...' vaultik snapshot restore <snapshot-id> /tmp/restored
|
||||||
|
|
||||||
# daily cron job: back up, keep a 4-week rolling window of snapshots
|
# daily cron job: back up, keep a 4-week rolling window of snapshots
|
||||||
# 0 3 * * * vaultik snapshot create --cron --prune --keep-newer-than 4w
|
# 0 3 * * * vaultik snapshot create --cron --prune --keep-newer-than 4w
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func TestCLIEntry(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verify all subcommands are registered
|
// Verify all subcommands are registered
|
||||||
expectedCommands := []string{"config", "snapshot", "store", "restore", "prune", "info", "version", "remote", "database"}
|
expectedCommands := []string{"config", "snapshot", "store", "prune", "info", "version", "remote", "database"}
|
||||||
for _, expected := range expectedCommands {
|
for _, expected := range expectedCommands {
|
||||||
found := false
|
found := false
|
||||||
for _, cmd := range cmd.Commands() {
|
for _, cmd := range cmd.Commands() {
|
||||||
@@ -38,7 +38,7 @@ func TestCLIEntry(t *testing.T) {
|
|||||||
t.Errorf("Failed to find snapshot command: %v", err)
|
t.Errorf("Failed to find snapshot command: %v", err)
|
||||||
} else {
|
} else {
|
||||||
// Check snapshot subcommands
|
// Check snapshot subcommands
|
||||||
expectedSubCommands := []string{"create", "list", "purge", "verify", "cleanup"}
|
expectedSubCommands := []string{"create", "list", "purge", "verify", "cleanup", "restore"}
|
||||||
for _, expected := range expectedSubCommands {
|
for _, expected := range expectedSubCommands {
|
||||||
found := false
|
found := false
|
||||||
for _, subcmd := range snapshotCmd.Commands() {
|
for _, subcmd := range snapshotCmd.Commands() {
|
||||||
|
|||||||
@@ -90,7 +90,6 @@ on the source system.`,
|
|||||||
// Add subcommands
|
// Add subcommands
|
||||||
cmd.AddCommand(
|
cmd.AddCommand(
|
||||||
NewConfigCommand(),
|
NewConfigCommand(),
|
||||||
NewRestoreCommand(),
|
|
||||||
NewPruneCommand(),
|
NewPruneCommand(),
|
||||||
NewStoreCommand(),
|
NewStoreCommand(),
|
||||||
NewSnapshotCommand(),
|
NewSnapshotCommand(),
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ func NewSnapshotCommand() *cobra.Command {
|
|||||||
cmd.AddCommand(newSnapshotRemoveCommand())
|
cmd.AddCommand(newSnapshotRemoveCommand())
|
||||||
cmd.AddCommand(newSnapshotPruneCommand())
|
cmd.AddCommand(newSnapshotPruneCommand())
|
||||||
cmd.AddCommand(newSnapshotCleanupCommand())
|
cmd.AddCommand(newSnapshotCleanupCommand())
|
||||||
|
cmd.AddCommand(newSnapshotRestoreCommand())
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,13 +29,13 @@ type RestoreApp struct {
|
|||||||
Shutdowner fx.Shutdowner
|
Shutdowner fx.Shutdowner
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRestoreCommand creates the restore command
|
// newSnapshotRestoreCommand creates the 'snapshot restore' subcommand
|
||||||
func NewRestoreCommand() *cobra.Command {
|
func newSnapshotRestoreCommand() *cobra.Command {
|
||||||
opts := &RestoreOptions{}
|
opts := &RestoreOptions{}
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "restore <snapshot-id> <target-dir> [paths...]",
|
Use: "restore <snapshot-id> <target-dir> [paths...]",
|
||||||
Short: "Restore files from backup",
|
Short: "Restore files from a snapshot",
|
||||||
Long: `Download and decrypt files from a backup snapshot.
|
Long: `Download and decrypt files from a backup snapshot.
|
||||||
|
|
||||||
This command will restore files from the specified snapshot to the target directory.
|
This command will restore files from the specified snapshot to the target directory.
|
||||||
@@ -46,16 +46,16 @@ Requires the VAULTIK_AGE_SECRET_KEY environment variable to be set with the age
|
|||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
# Restore entire snapshot
|
# Restore entire snapshot
|
||||||
vaultik restore myhost_docs_2025-01-01T12:00:00Z /restore
|
vaultik snapshot restore myhost_docs_2025-01-01T12:00:00Z /restore
|
||||||
|
|
||||||
# Restore specific file
|
# Restore specific file
|
||||||
vaultik restore myhost_docs_2025-01-01T12:00:00Z /restore /home/user/important.txt
|
vaultik snapshot restore myhost_docs_2025-01-01T12:00:00Z /restore /home/user/important.txt
|
||||||
|
|
||||||
# Restore specific directory
|
# Restore specific directory
|
||||||
vaultik restore myhost_docs_2025-01-01T12:00:00Z /restore /home/user/documents/
|
vaultik snapshot restore myhost_docs_2025-01-01T12:00:00Z /restore /home/user/documents/
|
||||||
|
|
||||||
# Restore and verify all files
|
# Restore and verify all files
|
||||||
vaultik restore --verify myhost_docs_2025-01-01T12:00:00Z /restore`,
|
vaultik snapshot restore --verify myhost_docs_2025-01-01T12:00:00Z /restore`,
|
||||||
Args: cobra.MinimumNArgs(2),
|
Args: cobra.MinimumNArgs(2),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return runRestore(cmd, args, opts)
|
return runRestore(cmd, args, opts)
|
||||||
Reference in New Issue
Block a user