mirror of
https://github.com/containers/podman.git
synced 2025-06-21 17:38:12 +08:00
Add --all and --latest to checkpoint/restore
This add the convenience options --all and --latest to the subcommands checkpoint and restore. Signed-off-by: Adrian Reber <areber@redhat.com>
This commit is contained in:

committed by
Adrian Reber

parent
c10ac01395
commit
e8d69030b6
@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
||||||
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/containers/libpod/pkg/rootless"
|
"github.com/containers/libpod/pkg/rootless"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
@ -22,6 +23,11 @@ var (
|
|||||||
Name: "keep, k",
|
Name: "keep, k",
|
||||||
Usage: "keep all temporary checkpoint files",
|
Usage: "keep all temporary checkpoint files",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "all, a",
|
||||||
|
Usage: "checkpoint all running containers",
|
||||||
|
},
|
||||||
|
LatestFlag,
|
||||||
}
|
}
|
||||||
checkpointCommand = cli.Command{
|
checkpointCommand = cli.Command{
|
||||||
Name: "checkpoint",
|
Name: "checkpoint",
|
||||||
@ -45,21 +51,14 @@ func checkpointCmd(c *cli.Context) error {
|
|||||||
defer runtime.Shutdown(false)
|
defer runtime.Shutdown(false)
|
||||||
|
|
||||||
keep := c.Bool("keep")
|
keep := c.Bool("keep")
|
||||||
args := c.Args()
|
|
||||||
if len(args) < 1 {
|
if err := checkAllAndLatest(c); err != nil {
|
||||||
return errors.Errorf("you must provide at least one container name or id")
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastError error
|
containers, lastError := getAllOrLatestContainers(c, runtime, libpod.ContainerStateRunning, "running")
|
||||||
for _, arg := range args {
|
|
||||||
ctr, err := runtime.LookupContainer(arg)
|
for _, ctr := range containers {
|
||||||
if err != nil {
|
|
||||||
if lastError != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, lastError)
|
|
||||||
}
|
|
||||||
lastError = errors.Wrapf(err, "error looking up container %q", arg)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err = ctr.Checkpoint(context.TODO(), keep); err != nil {
|
if err = ctr.Checkpoint(context.TODO(), keep); err != nil {
|
||||||
if lastError != nil {
|
if lastError != nil {
|
||||||
fmt.Fprintln(os.Stderr, lastError)
|
fmt.Fprintln(os.Stderr, lastError)
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
||||||
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/containers/libpod/pkg/rootless"
|
"github.com/containers/libpod/pkg/rootless"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
@ -22,6 +23,14 @@ var (
|
|||||||
Name: "keep, k",
|
Name: "keep, k",
|
||||||
Usage: "keep all temporary checkpoint files",
|
Usage: "keep all temporary checkpoint files",
|
||||||
},
|
},
|
||||||
|
// restore --all would make more sense if there would be
|
||||||
|
// dedicated state for container which are checkpointed.
|
||||||
|
// TODO: add ContainerStateCheckpointed
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "all, a",
|
||||||
|
Usage: "restore all checkpointed containers",
|
||||||
|
},
|
||||||
|
LatestFlag,
|
||||||
}
|
}
|
||||||
restoreCommand = cli.Command{
|
restoreCommand = cli.Command{
|
||||||
Name: "restore",
|
Name: "restore",
|
||||||
@ -45,21 +54,14 @@ func restoreCmd(c *cli.Context) error {
|
|||||||
defer runtime.Shutdown(false)
|
defer runtime.Shutdown(false)
|
||||||
|
|
||||||
keep := c.Bool("keep")
|
keep := c.Bool("keep")
|
||||||
args := c.Args()
|
|
||||||
if len(args) < 1 {
|
if err := checkAllAndLatest(c); err != nil {
|
||||||
return errors.Errorf("you must provide at least one container name or id")
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastError error
|
containers, lastError := getAllOrLatestContainers(c, runtime, libpod.ContainerStateRunning, "checkpointed")
|
||||||
for _, arg := range args {
|
|
||||||
ctr, err := runtime.LookupContainer(arg)
|
for _, ctr := range containers {
|
||||||
if err != nil {
|
|
||||||
if lastError != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, lastError)
|
|
||||||
}
|
|
||||||
lastError = errors.Wrapf(err, "error looking up container %q", arg)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err = ctr.Restore(context.TODO(), keep); err != nil {
|
if err = ctr.Restore(context.TODO(), keep); err != nil {
|
||||||
if lastError != nil {
|
if lastError != nil {
|
||||||
fmt.Fprintln(os.Stderr, lastError)
|
fmt.Fprintln(os.Stderr, lastError)
|
||||||
|
Reference in New Issue
Block a user