Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename snapshot -> backup #301

Merged
merged 4 commits into from Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -48,7 +48,7 @@ Available commands:
observer Get information, update or configure the Home Assistant observer
os Operating System specific for updating, info and configuration imports
resolution Resolution center of Supervisor, show issues and suggest solutions
snapshots Create, restore and remove snapshot backups
backups Create, restore and remove backups
supervisor Monitor, control and configure the Home Assistant Supervisor
```

Expand Down
2 changes: 1 addition & 1 deletion client/helper.go
Expand Up @@ -19,7 +19,7 @@ import (
const DefaultTimeout = 30 * time.Second
const ContainerOperationTimeout = 10 * time.Minute
const ContainerDownloadTimeout = 1 * time.Hour
const SnapshotTimeout = 3 * time.Hour
const BackupTimeout = 3 * time.Hour

var client *resty.Client

Expand Down
52 changes: 52 additions & 0 deletions cmd/backups.go
@@ -0,0 +1,52 @@
package cmd

import (
"fmt"
"os"

helper "github.com/home-assistant/cli/client"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var backupsCmd = &cobra.Command{
Use: "backups",
Aliases: []string{"backup", "back", "backups", "bk", "snapshots", "snapshot", "snap", "shot", "sn"},
Short: "Create, restore and remove backups",
Long: `
Backups of your Home Assistant system, which you can create,
restore, and delete using this command.`,
Example: `
ha backups
ha backups new`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
for idx, arg := range os.Args {
if idx != 0 && (arg == "snapshots" || arg == "snapshot" || arg == "snap" || arg == "shot" || arg == "sn") {
cmd.PrintErrf("The use of '%s' is deprecated, please use 'backups' instead!\n", arg)
}
}
rootCmd.PersistentPreRun(cmd, args)
},
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("backups")

section := "backups"
command := ""
base := viper.GetString("endpoint")

resp, err := helper.GenericJSONGet(base, section, command)
if err != nil {
fmt.Println(err)
ExitWithError = true
} else {
ExitWithError = !helper.ShowJSONResponse(resp)
}
},
}

func init() {
log.Debug("Init backups")
// add cmd to root command
rootCmd.AddCommand(backupsCmd)
}
16 changes: 8 additions & 8 deletions cmd/snapshots_info.go → cmd/backups_info.go
Expand Up @@ -11,20 +11,20 @@ import (
"github.com/spf13/viper"
)

var snapshotsInfoCmd = &cobra.Command{
var backupsInfoCmd = &cobra.Command{
Use: "info [slug]",
Aliases: []string{"in", "inf"},
Short: "Provides information about the current available snapshots",
Short: "Provides information about the current available backups",
Long: `
When a Home Assistant snapshot is created, it will be available for restore.
This command gives you information about a specific snapshot.`,
When a Home Assistant backup is created, it will be available for restore.
This command gives you information about a specific backup.`,
Example: `
ha snapshots info c1a07617`,
ha backups info c1a07617`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("snapshots info")
log.WithField("args", args).Debug("backups info")

section := "snapshots"
section := "backups"
command := "{slug}/info"
base := viper.GetString("endpoint")

Expand Down Expand Up @@ -67,5 +67,5 @@ This command gives you information about a specific snapshot.`,
}

func init() {
snapshotsCmd.AddCommand(snapshotsInfoCmd)
backupsCmd.AddCommand(backupsInfoCmd)
}
28 changes: 14 additions & 14 deletions cmd/snapshots_new.go → cmd/backups_new.go
Expand Up @@ -9,22 +9,22 @@ import (
"github.com/spf13/viper"
)

var snapshotsNewCmd = &cobra.Command{
var backupsNewCmd = &cobra.Command{
Use: "new",
Aliases: []string{"create", "backup"},
Short: "Create a new Home Assistant snapshot backup",
Short: "Create a new Home Assistant backup",
Long: `
This command can be used to trigger the creation of a new Home Assistant
snapshot containing a backup of your Home Assistant system.`,
backup.`,
Example: `
ha snapshots new
ha snapshots new --addons core_ssh --addons core_mosquitto
ha snapshots new --folders homeassistant
ha backups new
ha backups new --addons core_ssh --addons core_mosquitto
ha backups new --folders homeassistant
`,
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("snapshots new")
log.WithField("args", args).Debug("backups new")

section := "snapshots"
section := "backups"
command := "new/full"
base := viper.GetString("endpoint")

Expand Down Expand Up @@ -57,7 +57,7 @@ snapshot containing a backup of your Home Assistant system.`,
}

ProgressSpinner.Start()
resp, err := helper.GenericJSONPostTimeout(base, section, command, options, helper.SnapshotTimeout)
resp, err := helper.GenericJSONPostTimeout(base, section, command, options, helper.BackupTimeout)
ProgressSpinner.Stop()
if err != nil {
fmt.Println(err)
Expand All @@ -69,10 +69,10 @@ snapshot containing a backup of your Home Assistant system.`,
}

func init() {
snapshotsNewCmd.Flags().StringP("name", "", "", "Name of the snapshot")
snapshotsNewCmd.Flags().StringP("password", "", "", "Password")
snapshotsNewCmd.Flags().StringArrayP("addons", "a", []string{}, "addons to backup, triggers a partial backup")
snapshotsNewCmd.Flags().StringArrayP("folders", "f", []string{}, "folders to backup, triggers a partial backup")
backupsNewCmd.Flags().StringP("name", "", "", "Name of the backup")
backupsNewCmd.Flags().StringP("password", "", "", "Password")
backupsNewCmd.Flags().StringArrayP("addons", "a", []string{}, "addons to backup, triggers a partial backup")
backupsNewCmd.Flags().StringArrayP("folders", "f", []string{}, "folders to backup, triggers a partial backup")

snapshotsCmd.AddCommand(snapshotsNewCmd)
backupsCmd.AddCommand(backupsNewCmd)
}
14 changes: 7 additions & 7 deletions cmd/snapshots_reload.go → cmd/backups_reload.go
Expand Up @@ -9,20 +9,20 @@ import (
"github.com/spf13/viper"
)

var snapshotsReloadCmd = &cobra.Command{
var backupsReloadCmd = &cobra.Command{
Use: "reload",
Aliases: []string{"refresh", "re"},
Short: "Reload the files on disk to check for new or removed snapshots",
Short: "Reload the files on disk to check for new or removed backups",
Long: `
If a snapshot has been manually placed inside the backup folder, or has been
If a backup has been manually placed inside the backup folder, or has been
removed manually, this command can trigger Home Assistant to re-read the files
on disk`,
Example: `
ha snapshots reload`,
ha backups reload`,
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("snapshots reload")
log.WithField("args", args).Debug("backups reload")

section := "snapshots"
section := "backups"
command := "reload"
base := viper.GetString("endpoint")

Expand All @@ -37,5 +37,5 @@ on disk`,
}

func init() {
snapshotsCmd.AddCommand(snapshotsReloadCmd)
backupsCmd.AddCommand(backupsReloadCmd)
}
16 changes: 8 additions & 8 deletions cmd/snapshots_remove.go → cmd/backups_remove.go
Expand Up @@ -11,20 +11,20 @@ import (
"github.com/spf13/viper"
)

var snapshotsRemoveCmd = &cobra.Command{
var backupsRemoveCmd = &cobra.Command{
Use: "remove [slug]",
Aliases: []string{"delete", "del", "rem", "rm"},
Short: "Deletes a snapshot backup from disk",
Short: "Deletes a backup from disk",
Long: `
Snapshots can take quite a bit of diskspace, this command allows you to
clean snapshots from disk.`,
Backups can take quite a bit of diskspace, this command allows you to
clean backups from disk.`,
Example: `
ha snapshots remove c1a07617`,
ha backups remove c1a07617`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("snapshots remove")
log.WithField("args", args).Debug("backups remove")

section := "snapshots"
section := "backups"
command := "{slug}"
base := viper.GetString("endpoint")

Expand Down Expand Up @@ -67,5 +67,5 @@ clean snapshots from disk.`,

func init() {

snapshotsCmd.AddCommand(snapshotsRemoveCmd)
backupsCmd.AddCommand(backupsRemoveCmd)
}
28 changes: 14 additions & 14 deletions cmd/snapshots_restore.go → cmd/backups_restore.go
Expand Up @@ -11,25 +11,25 @@ import (
"github.com/spf13/viper"
)

var snapshotsRestoreCmd = &cobra.Command{
var backupsRestoreCmd = &cobra.Command{
Use: "restore [slug]",
Short: "Restores a Home Assistant snapshot backup",
Short: "Restores a Home Assistant backup",
Long: `
When something goes wrong, this command allows you to restore a previously
take Home Assistant snapshot backup on your system.`,
take Home Assistant backup on your system.`,
Example: `
ha snapshots restore c1a07617
ha snapshots restore c1a07617 --addons core_ssh --addon core_mosquitto
ha snapshots restore c1a07617 --folders config`,
ha backups restore c1a07617
ha backups restore c1a07617 --addons core_ssh --addon core_mosquitto
ha backups restore c1a07617 --folders config`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("snapshots restore")
log.WithField("args", args).Debug("backups restore")

section := "snapshots/{slug}"
section := "backups/{slug}"
command := "restore/full"
base := viper.GetString("endpoint")

request := helper.GetJSONRequestTimeout(helper.SnapshotTimeout)
request := helper.GetJSONRequestTimeout(helper.BackupTimeout)

options := make(map[string]interface{})

Expand Down Expand Up @@ -103,10 +103,10 @@ take Home Assistant snapshot backup on your system.`,
}

func init() {
snapshotsRestoreCmd.Flags().StringP("password", "", "", "Password")
snapshotsRestoreCmd.Flags().BoolP("homeassistant", "", true, "Restore homeassistant (default true), triggers a partial backup when se to false")
snapshotsRestoreCmd.Flags().StringArrayP("addons", "a", []string{}, "addons to restore, triggers a partial backup")
snapshotsRestoreCmd.Flags().StringArrayP("folders", "f", []string{}, "folders to restore, triggers a partial backup")
backupsRestoreCmd.Flags().StringP("password", "", "", "Password")
backupsRestoreCmd.Flags().BoolP("homeassistant", "", true, "Restore homeassistant (default true), triggers a partial backup when se to false")
backupsRestoreCmd.Flags().StringArrayP("addons", "a", []string{}, "addons to restore, triggers a partial backup")
backupsRestoreCmd.Flags().StringArrayP("folders", "f", []string{}, "folders to restore, triggers a partial backup")

snapshotsCmd.AddCommand(snapshotsRestoreCmd)
backupsCmd.AddCommand(backupsRestoreCmd)
}
43 changes: 0 additions & 43 deletions cmd/snapshots.go

This file was deleted.