| 1 | // Copyright © 2013, 2014, The Go-LXC Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a LGPLv2.1 |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | //go:build linux && cgo |
| 6 | // +build linux,cgo |
| 7 | |
| 8 | package main |
| 9 | |
| 10 | import ( |
| 11 | "flag" |
| 12 | "log" |
| 13 | |
| 14 | "github.com/lxc/go-lxc" |
| 15 | ) |
| 16 | |
| 17 | var ( |
| 18 | lxcpath string |
| 19 | directory string |
| 20 | name string |
| 21 | stop bool |
| 22 | verbose bool |
| 23 | ) |
| 24 | |
| 25 | func init() { |
| 26 | flag.StringVar(&lxcpath, "lxcpath", lxc.DefaultConfigPath(), "Use specified container path") |
| 27 | flag.StringVar(&name, "name", "rubik", "Name of the container") |
| 28 | flag.StringVar(&directory, "directory", "/tmp/rubik", "directory to save the checkpoint in") |
| 29 | flag.BoolVar(&verbose, "verbose", false, "Verbose output") |
| 30 | flag.BoolVar(&stop, "stop", false, "Stop the container after checkpointing.") |
| 31 | flag.Parse() |
| 32 | } |
| 33 | |
| 34 | func main() { |
| 35 | c, err := lxc.NewContainer(name, lxcpath) |
| 36 | if err != nil { |
| 37 | log.Fatalf("ERROR: %s\n", err.Error()) |
| 38 | } |
| 39 | defer c.Release() |
| 40 | |
| 41 | if verbose { |
| 42 | c.SetVerbosity(lxc.Verbose) |
| 43 | } |
| 44 | |
| 45 | options := lxc.CheckpointOptions{ |
| 46 | Directory: directory, |
| 47 | Verbose: verbose, |
| 48 | Stop: stop, |
| 49 | } |
| 50 | |
| 51 | if err := c.Checkpoint(options); err != nil { |
| 52 | log.Printf("ERROR: %s\n", err.Error()) |
| 53 | } |
| 54 | } |