Merge pull request #342 from skriss/refactor-restore-cmd
add --from-backup flag to ark restore create & allow restore namingpull/344/head
commit
7c7bfb06b4
|
@ -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:
|
||||
|
|
|
@ -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-<timestamp>") 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 *)
|
||||
|
|
|
@ -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-<timestamp>") 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 *)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <SCHEDULE NAME>-<TIMESTAMP>
|
||||
ark restore create --from-backup <SCHEDULE NAME>-<TIMESTAMP>
|
||||
```
|
||||
|
||||
## 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 (`<BACKUP-NAME>`) is now present, you can restore everything with:
|
||||
```
|
||||
ark restore create <BACKUP-NAME>
|
||||
ark restore create --from-backup <BACKUP-NAME>
|
||||
```
|
||||
|
||||
[0]: #disaster-recovery
|
||||
|
|
|
@ -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-<timestamp>") 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{
|
||||
|
|
Loading…
Reference in New Issue