diff --git a/README.md b/README.md index b645d7360..86d805c06 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ Make sure that you install somewhere in your `$PATH`. 1. Run: ``` - ark restore create nginx-backup + ark restore create --from-backup nginx-backup ``` 1. Run: diff --git a/docs/cli-reference/ark_create_restore.md b/docs/cli-reference/ark_create_restore.md index 38614a58d..4035a16f8 100644 --- a/docs/cli-reference/ark_create_restore.md +++ b/docs/cli-reference/ark_create_restore.md @@ -8,7 +8,17 @@ Create a restore Create a restore ``` -ark create restore BACKUP [flags] +ark create restore [RESTORE_NAME] --from-backup BACKUP_NAME [flags] +``` + +### Examples + +``` + # create a restore named "restore-1" from backup "backup-1" + ark restore create restore-1 --from-backup backup-1 + + # create a restore with a default name ("backup-1-") from backup "backup-1" + ark restore create --from-backup backup-1 ``` ### Options @@ -16,6 +26,7 @@ ark create restore BACKUP [flags] ``` --exclude-namespaces stringArray namespaces to exclude from the restore --exclude-resources stringArray resources to exclude from the restore, formatted as resource.group, such as storageclasses.storage.k8s.io + --from-backup string backup to restore from -h, --help help for restore --include-cluster-resources optionalBool[=true] include cluster-scoped resources in the restore --include-namespaces stringArray namespaces to include in the restore (use '*' for all namespaces) (default *) diff --git a/docs/cli-reference/ark_restore_create.md b/docs/cli-reference/ark_restore_create.md index c91056bfa..f83787cad 100644 --- a/docs/cli-reference/ark_restore_create.md +++ b/docs/cli-reference/ark_restore_create.md @@ -8,7 +8,17 @@ Create a restore Create a restore ``` -ark restore create BACKUP [flags] +ark restore create [RESTORE_NAME] --from-backup BACKUP_NAME [flags] +``` + +### Examples + +``` + # create a restore named "restore-1" from backup "backup-1" + ark restore create restore-1 --from-backup backup-1 + + # create a restore with a default name ("backup-1-") from backup "backup-1" + ark restore create --from-backup backup-1 ``` ### Options @@ -16,6 +26,7 @@ ark restore create BACKUP [flags] ``` --exclude-namespaces stringArray namespaces to exclude from the restore --exclude-resources stringArray resources to exclude from the restore, formatted as resource.group, such as storageclasses.storage.k8s.io + --from-backup string backup to restore from -h, --help help for create --include-cluster-resources optionalBool[=true] include cluster-scoped resources in the restore --include-namespaces stringArray namespaces to include in the restore (use '*' for all namespaces) (default *) diff --git a/docs/cloud-common.md b/docs/cloud-common.md index c228104ca..786f52d8b 100644 --- a/docs/cloud-common.md +++ b/docs/cloud-common.md @@ -37,7 +37,7 @@ After you set up the Ark server, try these examples: 1. Restore your lost resources: ```bash - ark restore create nginx-backup + ark restore create --from-backup nginx-backup ``` ### Snapshot example (with PersistentVolumes) @@ -67,7 +67,7 @@ After you set up the Ark server, try these examples: 1. Restore your lost resources: ```bash - ark restore create nginx-backup + ark restore create --from-backup nginx-backup ``` [0]: aws-config.md diff --git a/docs/use-cases.md b/docs/use-cases.md index 5fb6c6b49..7263079c9 100644 --- a/docs/use-cases.md +++ b/docs/use-cases.md @@ -23,7 +23,7 @@ If you periodically back up your cluster's resources, you are able to return to 4. Create a restore with your most recent Ark Backup: ``` - ark restore create - + ark restore create --from-backup - ``` ## Cluster migration @@ -45,7 +45,7 @@ Heptio Ark can help you port your resources from one cluster to another, as long 4. *(Cluster 2)* Once you have confirmed that the right Backup (``) is now present, you can restore everything with: ``` -ark restore create +ark restore create --from-backup ``` [0]: #disaster-recovery diff --git a/pkg/cmd/cli/restore/create.go b/pkg/cmd/cli/restore/create.go index d5212c124..e5597bfef 100644 --- a/pkg/cmd/cli/restore/create.go +++ b/pkg/cmd/cli/restore/create.go @@ -38,8 +38,13 @@ func NewCreateCommand(f client.Factory, use string) *cobra.Command { o := NewCreateOptions() c := &cobra.Command{ - Use: use + " BACKUP", + Use: use + " [RESTORE_NAME] --from-backup BACKUP_NAME", Short: "Create a restore", + Example: ` # create a restore named "restore-1" from backup "backup-1" + ark restore create restore-1 --from-backup backup-1 + + # create a restore with a default name ("backup-1-") from backup "backup-1" + ark restore create --from-backup backup-1`, Run: func(c *cobra.Command, args []string) { cmd.CheckError(o.Validate(c, args, f)) cmd.CheckError(o.Complete(args)) @@ -56,6 +61,7 @@ func NewCreateCommand(f client.Factory, use string) *cobra.Command { type CreateOptions struct { BackupName string + RestoreName string RestoreVolumes flag.OptionalBool Labels flag.Map IncludeNamespaces flag.StringArray @@ -80,6 +86,7 @@ func NewCreateOptions() *CreateOptions { } func (o *CreateOptions) BindFlags(flags *pflag.FlagSet) { + flags.StringVar(&o.BackupName, "from-backup", "", "backup to restore from") flags.Var(&o.IncludeNamespaces, "include-namespaces", "namespaces to include in the restore (use '*' for all namespaces)") flags.Var(&o.ExcludeNamespaces, "exclude-namespaces", "namespaces to exclude from the restore") flags.Var(&o.NamespaceMappings, "namespace-mappings", "namespace mappings from name in the backup to desired restored name in the form src1:dst1,src2:dst2,...") @@ -97,8 +104,12 @@ func (o *CreateOptions) BindFlags(flags *pflag.FlagSet) { } func (o *CreateOptions) Validate(c *cobra.Command, args []string, f client.Factory) error { - if len(args) != 1 { - return errors.New("you must specify only one argument, the backup's name") + if len(o.BackupName) == 0 { + return errors.New("--from-backup is required") + } + + if len(args) > 1 { + return errors.New("you may specify at most one argument, the restore's name") } if err := output.ValidateFlags(c); err != nil { @@ -111,7 +122,7 @@ func (o *CreateOptions) Validate(c *cobra.Command, args []string, f client.Facto } o.client = client - _, err = o.client.ArkV1().Backups(f.Namespace()).Get(args[0], metav1.GetOptions{}) + _, err = o.client.ArkV1().Backups(f.Namespace()).Get(o.BackupName, metav1.GetOptions{}) if err != nil { return err } @@ -120,7 +131,12 @@ func (o *CreateOptions) Validate(c *cobra.Command, args []string, f client.Facto } func (o *CreateOptions) Complete(args []string) error { - o.BackupName = args[0] + if len(args) == 1 { + o.RestoreName = args[0] + } else { + o.RestoreName = fmt.Sprintf("%s-%s", o.BackupName, time.Now().Format("20060102150405")) + } + return nil } @@ -133,7 +149,7 @@ func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error { restore := &api.Restore{ ObjectMeta: metav1.ObjectMeta{ Namespace: f.Namespace(), - Name: fmt.Sprintf("%s-%s", o.BackupName, time.Now().Format("20060102150405")), + Name: o.RestoreName, Labels: o.Labels.Data(), }, Spec: api.RestoreSpec{