Skip to content
Snippets Groups Projects
Commit 5d6cd5b8 authored by ale's avatar ale
Browse files

add backup/restore commands to radioctl

parent a7addea3
Branches
No related tags found
No related merge requests found
...@@ -587,6 +587,73 @@ func (cmd *showMountCommand) Run(args []string) { ...@@ -587,6 +587,73 @@ func (cmd *showMountCommand) Run(args []string) {
printMount(m) printMount(m)
} }
// Backup mount configuration.
type backupCommand struct {
BaseCommand
}
func newBackupCommand() *backupCommand {
return &backupCommand{
BaseCommand{
UsageLine: "backup",
Short: "Backup mount configuration",
Long: `
Dump the autoradio configuration to stdout, in a format that is
understood by the "restore" command.
`,
},
}
}
func (cmd *backupCommand) Run(args []string) {
if len(args) != 0 {
log.Fatal("Too many arguments")
}
mounts, err := getClient().ListMounts()
if err != nil {
log.Fatalf("ERROR: %v", err)
}
if err := json.NewEncoder(os.Stdout).Encode(mounts); err != nil {
log.Fatalf("ERROR: %v", err)
}
}
// Restore mount configuration.
type restoreCommand struct {
BaseCommand
}
func newRestoreCommand() *restoreCommand {
return &restoreCommand{
BaseCommand{
UsageLine: "restore",
Short: "Restore mount configuration",
Long: `
Read a configuration dump from standard input and restore it.
`,
},
}
}
func (cmd *restoreCommand) Run(args []string) {
if len(args) != 0 {
log.Fatal("Too many arguments")
}
var mounts []*autoradio.Mount
if err := json.NewDecoder(os.Stdin).Decode(&mounts); err != nil {
log.Fatalf("ERROR: %v", err)
}
client := getClient()
for _, m := range mounts {
if err := client.SetMount(m); err != nil {
log.Printf("ERROR: creating mount %s: %v", m.Name, err)
}
}
}
var cmdr = &commander.Command{ var cmdr = &commander.Command{
UsageLine: "radioctl <command> [<args>...]", UsageLine: "radioctl <command> [<args>...]",
Short: "Manage `autoradio' configuration", Short: "Manage `autoradio' configuration",
...@@ -611,6 +678,8 @@ func init() { ...@@ -611,6 +678,8 @@ func init() {
addCommand(newDeleteMountCommand()) addCommand(newDeleteMountCommand())
addCommand(newListMountsCommand()) addCommand(newListMountsCommand())
addCommand(newShowMountCommand()) addCommand(newShowMountCommand())
addCommand(newBackupCommand())
addCommand(newRestoreCommand())
flag.Usage = usage flag.Usage = usage
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment