-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds support for creating hot (default) and cold backups of the instance Signed-off-by: Obed N Munoz <[email protected]>
- Loading branch information
Showing
6 changed files
with
180 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ func New() (*cli.App, error) { | |
&composeCommand, | ||
&sshCommand, | ||
&stopCommand, | ||
&saveCommand, | ||
}, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cli | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/govm-project/govm/engines/docker" | ||
log "github.com/sirupsen/logrus" | ||
cli "github.com/urfave/cli/v2" | ||
) | ||
|
||
// nolint: gochecknoglobals | ||
var saveCommand = cli.Command{ | ||
Name: "save", | ||
Aliases: []string{"snapshot"}, | ||
Usage: "Saves a GoVM Instance", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "out", | ||
Value: "backup.img", | ||
Usage: "Path to backup file", | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "stopvm", | ||
Value: false, | ||
Usage: "Stop the VM during snapshot", | ||
}, | ||
}, | ||
Action: func(ctx *cli.Context) error { | ||
if ctx.NArg() <= 0 { | ||
err := errors.New("missing GoVM Instance name") | ||
fmt.Println(err) | ||
fmt.Printf("USAGE:\n govm stop [command options] [name]\n") | ||
os.Exit(1) | ||
} | ||
|
||
namespace := ctx.String("namespace") | ||
name := ctx.Args().First() | ||
backupFile := ctx.String("out") | ||
stopVM := ctx.Bool("stopvm") | ||
|
||
engine := docker.Engine{} | ||
engine.Init() | ||
err := engine.Save(namespace, name, backupFile, stopVM) | ||
if err != nil { | ||
log.Fatalf("Error when saving the GoVM Instance %v: %v", name, err) | ||
} | ||
|
||
log.Printf("GoVM Instance %v has been successfully stopped", name) | ||
|
||
return nil | ||
}, | ||
} |