File: clone.go

package info (click to toggle)
golang-gopkg-lxc-go-lxc.v2 0.0%2Bgit20240606.27b3d11-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 444 kB
  • sloc: ansic: 582; makefile: 77
file content (48 lines) | stat: -rw-r--r-- 1,114 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright © 2013, 2014, The Go-LXC Authors. All rights reserved.
// Use of this source code is governed by a LGPLv2.1
// license that can be found in the LICENSE file.

//go:build linux && cgo
// +build linux,cgo

package main

import (
	"flag"
	"log"

	"github.com/lxc/go-lxc"
)

var (
	lxcpath string
	name    string
	backend lxc.BackendStore
)

func init() {
	flag.StringVar(&lxcpath, "lxcpath", lxc.DefaultConfigPath(), "Use specified container path")
	flag.StringVar(&name, "name", "rubik", "Name of the original container")
	flag.Var(&backend, "backend", "Backend type to use, possible values are [dir, zfs, btrfs, lvm, aufs, overlayfs, loopback, best]")
	flag.Parse()
}

func main() {
	c, err := lxc.NewContainer(name, lxcpath)
	if err != nil {
		log.Fatalf("ERROR: %s\n", err.Error())
	}
	defer c.Release()

	if backend == 0 {
		log.Fatalf("ERROR: %s\n", lxc.ErrUnknownBackendStore)
	}

	log.Printf("Cloning the container using %s backend...\n", backend)
	err = c.Clone(name+"_"+backend.String(), lxc.CloneOptions{
		Backend: backend,
	})
	if err != nil {
		log.Fatalf("ERROR: %s\n", err.Error())
	}
}