| 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 | name string |
| 20 | backend lxc.BackendStore |
| 21 | ) |
| 22 | |
| 23 | func init() { |
| 24 | flag.StringVar(&lxcpath, "lxcpath", lxc.DefaultConfigPath(), "Use specified container path") |
| 25 | flag.StringVar(&name, "name", "rubik", "Name of the original container") |
| 26 | flag.Var(&backend, "backend", "Backend type to use, possible values are [dir, zfs, btrfs, lvm, aufs, overlayfs, loopback, best]") |
| 27 | flag.Parse() |
| 28 | } |
| 29 | |
| 30 | func main() { |
| 31 | c, err := lxc.NewContainer(name, lxcpath) |
| 32 | if err != nil { |
| 33 | log.Fatalf("ERROR: %s\n", err.Error()) |
| 34 | } |
| 35 | defer c.Release() |
| 36 | |
| 37 | if backend == 0 { |
| 38 | log.Fatalf("ERROR: %s\n", lxc.ErrUnknownBackendStore) |
| 39 | } |
| 40 | |
| 41 | log.Printf("Cloning the container using %s backend...\n", backend) |
| 42 | err = c.Clone(name+"_"+backend.String(), lxc.CloneOptions{ |
| 43 | Backend: backend, |
| 44 | }) |
| 45 | if err != nil { |
| 46 | log.Fatalf("ERROR: %s\n", err.Error()) |
| 47 | } |
| 48 | } |