github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/cmd/podman/checkpoint.go (about) 1 package main 2 3 import ( 4 "github.com/containers/libpod/cmd/podman/cliconfig" 5 "github.com/containers/libpod/pkg/adapter" 6 "github.com/containers/libpod/pkg/rootless" 7 "github.com/pkg/errors" 8 "github.com/spf13/cobra" 9 ) 10 11 var ( 12 checkpointCommand cliconfig.CheckpointValues 13 checkpointDescription = ` 14 podman container checkpoint 15 16 Checkpoints one or more running containers. The container name or ID can be used. 17 ` 18 _checkpointCommand = &cobra.Command{ 19 Use: "checkpoint [flags] CONTAINER [CONTAINER...]", 20 Short: "Checkpoints one or more containers", 21 Long: checkpointDescription, 22 RunE: func(cmd *cobra.Command, args []string) error { 23 checkpointCommand.InputArgs = args 24 checkpointCommand.GlobalFlags = MainGlobalOpts 25 checkpointCommand.Remote = remoteclient 26 return checkpointCmd(&checkpointCommand) 27 }, 28 Args: func(cmd *cobra.Command, args []string) error { 29 return checkAllLatestAndCIDFile(cmd, args, false, false) 30 }, 31 Example: `podman container checkpoint --keep ctrID 32 podman container checkpoint --all 33 podman container checkpoint --leave-running --latest`, 34 } 35 ) 36 37 func init() { 38 checkpointCommand.Command = _checkpointCommand 39 checkpointCommand.SetHelpTemplate(HelpTemplate()) 40 checkpointCommand.SetUsageTemplate(UsageTemplate()) 41 42 flags := checkpointCommand.Flags() 43 flags.BoolVarP(&checkpointCommand.Keep, "keep", "k", false, "Keep all temporary checkpoint files") 44 flags.BoolVarP(&checkpointCommand.LeaveRunning, "leave-running", "R", false, "Leave the container running after writing checkpoint to disk") 45 flags.BoolVar(&checkpointCommand.TcpEstablished, "tcp-established", false, "Checkpoint a container with established TCP connections") 46 flags.BoolVarP(&checkpointCommand.All, "all", "a", false, "Checkpoint all running containers") 47 flags.BoolVarP(&checkpointCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of") 48 flags.StringVarP(&checkpointCommand.Export, "export", "e", "", "Export the checkpoint image to a tar.gz") 49 flags.BoolVar(&checkpointCommand.IgnoreRootfs, "ignore-rootfs", false, "Do not include root file-system changes when exporting") 50 markFlagHiddenForRemoteClient("latest", flags) 51 } 52 53 func checkpointCmd(c *cliconfig.CheckpointValues) error { 54 if rootless.IsRootless() { 55 return errors.New("checkpointing a container requires root") 56 } 57 58 runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand) 59 if err != nil { 60 return errors.Wrapf(err, "could not get runtime") 61 } 62 63 defer runtime.DeferredShutdown(false) 64 return runtime.Checkpoint(c) 65 }