fixup! feat: backup revolution
This commit is contained in:
parent
3ff37ddb87
commit
6a7e4973d7
|
@ -66,6 +66,33 @@ func retrieveBackupBotContainer(cl *dockerClient.Client) (types.Container, error
|
|||
return targetContainer, nil
|
||||
}
|
||||
|
||||
// runBackupCmdRemote runs a backup related command on a remote backupbot container.
|
||||
func runBackupCmdRemote(cl *dockerClient.Client, backupCmd string, containerID string, execEnv []string) error {
|
||||
execBackupListOpts := types.ExecConfig{
|
||||
AttachStderr: true,
|
||||
AttachStdin: true,
|
||||
AttachStdout: true,
|
||||
Cmd: []string{"/usr/bin/backup", "--", backupCmd},
|
||||
Detach: false,
|
||||
Env: execEnv,
|
||||
Tty: true,
|
||||
}
|
||||
|
||||
logrus.Debugf("running backup %s on %s with exec config %v", backupCmd, containerID, execBackupListOpts)
|
||||
|
||||
// FIXME: avoid instantiating a new CLI
|
||||
dcli, err := command.NewDockerCli()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := container.RunExec(dcli, cl, containerID, &execBackupListOpts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var appBackupListCommand = cli.Command{
|
||||
Name: "list",
|
||||
Aliases: []string{"ls"},
|
||||
|
@ -121,25 +148,7 @@ var appBackupListCommand = cli.Command{
|
|||
execEnv = append(execEnv, fmt.Sprintf("INCLUDE_PATH=%s", includePath))
|
||||
}
|
||||
|
||||
execBackupListOpts := types.ExecConfig{
|
||||
AttachStderr: true,
|
||||
AttachStdin: true,
|
||||
AttachStdout: true,
|
||||
Cmd: []string{"/usr/bin/backup", "--", "ls"},
|
||||
Detach: false,
|
||||
Env: execEnv,
|
||||
Tty: true,
|
||||
}
|
||||
|
||||
logrus.Debugf("running backup list on %s with exec config %v", targetContainer.ID, execBackupListOpts)
|
||||
|
||||
// FIXME: avoid instantiating a new CLI
|
||||
dcli, err := command.NewDockerCli()
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := container.RunExec(dcli, cl, targetContainer.ID, &execBackupListOpts); err != nil {
|
||||
if err := runBackupCmdRemote(cl, "ls", targetContainer.ID, execEnv); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -202,26 +211,7 @@ var appBackupDownloadCommand = cli.Command{
|
|||
execEnv = append(execEnv, fmt.Sprintf("INCLUDE_PATH=%s", includePath))
|
||||
}
|
||||
|
||||
execBackupListOpts := types.ExecConfig{
|
||||
AttachStderr: true,
|
||||
AttachStdin: true,
|
||||
AttachStdout: true,
|
||||
Cmd: []string{"/usr/bin/backup", "--", "download"},
|
||||
Detach: false,
|
||||
Env: execEnv,
|
||||
Tty: true,
|
||||
}
|
||||
|
||||
logrus.Debugf("running backup download on %s with exec config %v", targetContainer.ID, execBackupListOpts)
|
||||
|
||||
// FIXME: avoid instantiating a new CLI
|
||||
dcli, err := command.NewDockerCli()
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = container.RunExec(dcli, cl, targetContainer.ID, &execBackupListOpts)
|
||||
if err != nil {
|
||||
if err := runBackupCmdRemote(cl, "download", targetContainer.ID, execEnv); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -286,25 +276,8 @@ var appBackupCreateCommand = cli.Command{
|
|||
logrus.Debugf("including RESTIC_REPO=%s in backupbot exec invocation", resticRepo)
|
||||
execEnv = append(execEnv, fmt.Sprintf("RESTIC_REPO=%s", resticRepo))
|
||||
}
|
||||
execBackupListOpts := types.ExecConfig{
|
||||
AttachStderr: true,
|
||||
AttachStdin: true,
|
||||
AttachStdout: true,
|
||||
Cmd: []string{"/usr/bin/backup", "--", "create"},
|
||||
Detach: false,
|
||||
Env: execEnv,
|
||||
Tty: true,
|
||||
}
|
||||
|
||||
logrus.Debugf("running backup create on %s with exec config %v", targetContainer.ID, execBackupListOpts)
|
||||
|
||||
// FIXME: avoid instantiating a new CLI
|
||||
dcli, err := command.NewDockerCli()
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := container.RunExec(dcli, cl, targetContainer.ID, &execBackupListOpts); err != nil {
|
||||
if err := runBackupCmdRemote(cl, "create", targetContainer.ID, execEnv); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -361,25 +334,8 @@ var appBackupSnapshotsCommand = cli.Command{
|
|||
logrus.Debugf("including SNAPSHOT=%s in backupbot exec invocation", snapshot)
|
||||
execEnv = append(execEnv, fmt.Sprintf("SNAPSHOT=%s", snapshot))
|
||||
}
|
||||
execBackupListOpts := types.ExecConfig{
|
||||
AttachStderr: true,
|
||||
AttachStdin: true,
|
||||
AttachStdout: true,
|
||||
Cmd: []string{"/usr/bin/backup", "--", "snapshots"},
|
||||
Detach: false,
|
||||
Env: execEnv,
|
||||
Tty: true,
|
||||
}
|
||||
|
||||
logrus.Debugf("running backup snapshot list on %s with exec config %v", targetContainer.ID, execBackupListOpts)
|
||||
|
||||
// FIXME: avoid instantiating a new CLI
|
||||
dcli, err := command.NewDockerCli()
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := container.RunExec(dcli, cl, targetContainer.ID, &execBackupListOpts); err != nil {
|
||||
if err := runBackupCmdRemote(cl, "snapshots", targetContainer.ID, execEnv); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue