restore

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cli.Command{
	Name:      "restore",
	Usage:     "Restore soft-deleted GCS objects",
	ArgsUsage: "[URL ...]",
	Action: func(ctx context.Context, cmd *cli.Command) error {
		if cmd.Args().Len() < 1 {
			return fmt.Errorf("%w: restore command requires at least 1 argument (gs://bucket/object#generation)", utils.ErrInvalidArgs)
		}

		client, err := utils.NewClient(ctx)
		if err != nil {
			return fmt.Errorf("failed to create GCS client: %w", err)
		}
		defer client.Close()

		for _, arg := range cmd.Args().Slice() {
			if !strings.HasPrefix(arg, "gs://") {
				return fmt.Errorf("%w: %s", utils.ErrOnlyGCS, arg)
			}
			bucket, object, generation, err := utils.ParseGCSPath(arg)
			if err != nil {
				return err
			}
			if generation == 0 {
				return fmt.Errorf("%w: %s", utils.ErrGenerationRequired, arg)
			}

			_, err = utils.RetryObject(utils.RetryBucket(client, bucket), object).Generation(generation).Restore(ctx, nil)
			if err != nil {
				return fmt.Errorf("failed to restore %s: %w", arg, err)
			}
			fmt.Printf("Successfully restored %s\n", arg)
		}

		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL