-
Notifications
You must be signed in to change notification settings - Fork 23
/
backup.go
41 lines (32 loc) · 861 Bytes
/
backup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package directory
import (
"os"
"path"
"github.com/aserto-dev/topaz/pkg/cli/cc"
"github.com/aserto-dev/topaz/pkg/cli/clients"
"github.com/fatih/color"
"github.com/pkg/errors"
)
type BackupCmd struct {
File string `arg:"" default:"backup.tar.gz" help:"absolute file path to make backup to"`
clients.DirectoryConfig
}
const defaultFileName = "backup.tar.gz"
func (cmd *BackupCmd) Run(c *cc.CommonCtx) error {
if !c.IsServing(cmd.Host) {
return errors.Wrap(cc.ErrNotServing, cmd.Host)
}
dirClient, err := clients.NewDirectoryClient(c, &cmd.DirectoryConfig)
if err != nil {
return err
}
if cmd.File == defaultFileName {
currentDir, err := os.Getwd()
if err != nil {
return err
}
cmd.File = path.Join(currentDir, defaultFileName)
}
color.Green(">>> backup to %s", cmd.File)
return dirClient.V3.Backup(c.Context, cmd.File)
}