diff --git a/README.md b/README.md index d55418a..bd5cf65 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ vaultik snapshot verify VAULTIK_AGE_SECRET_KEY='AGE-SECRET-KEY-...' vaultik snapshot verify --deep # restore (requires the private key) -VAULTIK_AGE_SECRET_KEY='AGE-SECRET-KEY-...' vaultik restore /tmp/restored +VAULTIK_AGE_SECRET_KEY='AGE-SECRET-KEY-...' vaultik snapshot restore /tmp/restored # daily cron job: back up, keep a 4-week rolling window of snapshots # 0 3 * * * vaultik snapshot create --cron --prune --keep-newer-than 4w diff --git a/internal/cli/entry_test.go b/internal/cli/entry_test.go index 7a28690..c6ed0b8 100644 --- a/internal/cli/entry_test.go +++ b/internal/cli/entry_test.go @@ -18,7 +18,7 @@ func TestCLIEntry(t *testing.T) { } // 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 { found := false for _, cmd := range cmd.Commands() { @@ -38,7 +38,7 @@ func TestCLIEntry(t *testing.T) { t.Errorf("Failed to find snapshot command: %v", err) } else { // Check snapshot subcommands - expectedSubCommands := []string{"create", "list", "purge", "verify", "cleanup"} + expectedSubCommands := []string{"create", "list", "purge", "verify", "cleanup", "restore"} for _, expected := range expectedSubCommands { found := false for _, subcmd := range snapshotCmd.Commands() { diff --git a/internal/cli/root.go b/internal/cli/root.go index 267f97d..3818ffc 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -90,7 +90,6 @@ on the source system.`, // Add subcommands cmd.AddCommand( NewConfigCommand(), - NewRestoreCommand(), NewPruneCommand(), NewStoreCommand(), NewSnapshotCommand(), diff --git a/internal/cli/snapshot.go b/internal/cli/snapshot.go index e91cff4..cbba394 100644 --- a/internal/cli/snapshot.go +++ b/internal/cli/snapshot.go @@ -27,6 +27,7 @@ func NewSnapshotCommand() *cobra.Command { cmd.AddCommand(newSnapshotRemoveCommand()) cmd.AddCommand(newSnapshotPruneCommand()) cmd.AddCommand(newSnapshotCleanupCommand()) + cmd.AddCommand(newSnapshotRestoreCommand()) return cmd } diff --git a/internal/cli/restore.go b/internal/cli/snapshot_restore.go similarity index 88% rename from internal/cli/restore.go rename to internal/cli/snapshot_restore.go index dca4ebd..d4c78d9 100644 --- a/internal/cli/restore.go +++ b/internal/cli/snapshot_restore.go @@ -29,13 +29,13 @@ type RestoreApp struct { Shutdowner fx.Shutdowner } -// NewRestoreCommand creates the restore command -func NewRestoreCommand() *cobra.Command { +// newSnapshotRestoreCommand creates the 'snapshot restore' subcommand +func newSnapshotRestoreCommand() *cobra.Command { opts := &RestoreOptions{} cmd := &cobra.Command{ Use: "restore [paths...]", - Short: "Restore files from backup", + Short: "Restore files from a snapshot", Long: `Download and decrypt files from a backup snapshot. 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: # 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 - 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 - 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 - 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), RunE: func(cmd *cobra.Command, args []string) error { return runRestore(cmd, args, opts)