-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
helper "github.com/home-assistant/cli/client" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var backupFreezeCmd = &cobra.Command{ | ||
Use: "freeze", | ||
Aliases: []string{"frz"}, | ||
Short: "Freeze supervisor for external backup", | ||
Long: ` | ||
This command tells Supervisor to prepare Home Assistant and addons for a backup | ||
or snapshot taken by external software. Caller should call thaw when done.`, | ||
Example: ` | ||
ha backups freeze --timeout 300`, | ||
ValidArgsFunction: cobra.NoFileCompletions, | ||
Args: cobra.NoArgs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
log.WithField("args", args).Debug("backups freeze") | ||
|
||
section := "backups" | ||
command := "freeze" | ||
|
||
options := make(map[string]interface{}) | ||
|
||
timeout, err := cmd.Flags().GetInt("timeout") | ||
if timeout != 0 && err == nil && cmd.Flags().Changed("timeout") { | ||
options["timeout"] = timeout | ||
} | ||
|
||
resp, err := helper.GenericJSONPost(section, command, options) | ||
if err != nil { | ||
fmt.Println(err) | ||
ExitWithError = true | ||
} else { | ||
ExitWithError = !helper.ShowJSONResponse(resp) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
backupFreezeCmd.Flags().Int("timeout", 0, "Seconds before freeze times out and thaw begins") | ||
backupFreezeCmd.RegisterFlagCompletionFunc("timeout", cobra.NoFileCompletions) | ||
backupsCmd.AddCommand(backupFreezeCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
helper "github.com/home-assistant/cli/client" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var backupsThawCmd = &cobra.Command{ | ||
Use: "thaw", | ||
Aliases: []string{"th"}, | ||
Short: "Thaw supervisor after an external backup", | ||
Long: ` | ||
End a freeze initiated by the freeze command after an external backup or snapshot | ||
has completed.`, | ||
Example: ` | ||
ha backups thaw`, | ||
ValidArgsFunction: cobra.NoFileCompletions, | ||
Args: cobra.NoArgs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
log.WithField("args", args).Debug("backups thaw") | ||
|
||
section := "backups" | ||
command := "thaw" | ||
|
||
resp, err := helper.GenericJSONPost(section, command, nil) | ||
if err != nil { | ||
fmt.Println(err) | ||
ExitWithError = true | ||
} else { | ||
ExitWithError = !helper.ShowJSONResponse(resp) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
backupsCmd.AddCommand(backupsThawCmd) | ||
} |