forked from cloudfoundry/bosh-backup-and-restore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployment_pre_backup_check.go
49 lines (40 loc) · 1.25 KB
/
deployment_pre_backup_check.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
42
43
44
45
46
47
48
49
package command
import (
"fmt"
"github.com/cloudfoundry-incubator/bosh-backup-and-restore/factory"
"github.com/cloudfoundry-incubator/bosh-backup-and-restore/orchestrator"
"github.com/urfave/cli"
)
type DeploymentPreBackupCheck struct{}
func NewDeploymentPreBackupCheckCommand() DeploymentPreBackupCheck {
return DeploymentPreBackupCheck{}
}
func (d DeploymentPreBackupCheck) Cli() cli.Command {
return cli.Command{
Name: "pre-backup-check",
Aliases: []string{"c"},
Usage: "Check a deployment can be backed up",
Action: d.Action,
}
}
func (d DeploymentPreBackupCheck) Action(c *cli.Context) error {
var deployment = c.Parent().String("deployment")
backupChecker, err := factory.BuildDeploymentBackupChecker(
c.Parent().String("target"),
c.Parent().String("username"),
c.Parent().String("password"),
c.Parent().String("ca-cert"),
c.GlobalBool("debug"),
c.Bool("with-manifest"))
if err != nil {
return processError(orchestrator.NewError(err))
}
backupable, checkErr := backupChecker.CanBeBackedUp(deployment)
if backupable {
fmt.Printf("Deployment '%s' can be backed up.\n", deployment)
return cli.NewExitError("", 0)
} else {
fmt.Printf("Deployment '%s' cannot be backed up.\n", deployment)
return processError(checkErr)
}
}