Example #1
0
/*
 * Export the container under @dir.  It will look like:
 * dir/
 *     metadata.yaml
 *     rootfs/
 */
func (d *lxdContainer) exportToDir(snap, dir string) error {
	if snap != "" && d.c.Running() {
		return fmt.Errorf("Cannot export a running container as image")
	}

	source := shared.VarPath("lxc", d.name, "metadata.yaml")
	dest := fmt.Sprintf("%s/metadata.yaml", dir)
	if shared.PathExists(source) {
		if err := shared.CopyFile(dest, source); err != nil {
			return err
		}
	}

	if snap != "" {
		source = snapshotRootfsDir(d, snap)
	} else {
		source = shared.VarPath("lxc", d.name, "rootfs")
	}

	// rsync the rootfs
	err := exec.Command("rsync", "-a", "--devices", source, dir).Run()
	if err != nil {
		return err
	}

	// unshift
	if !d.isPrivileged() {
		rootfs := fmt.Sprintf("%s/rootfs", dir)
		err = d.idmapset.UnshiftRootfs(rootfs)
	}
	return err
}
Example #2
0
func collectMigrationLogFile(c *lxc.Container, imagesDir string, method string) error {
	t := time.Now().Format(time.RFC3339)
	newPath := shared.LogPath(c.Name(), fmt.Sprintf("migration_%s_%s.log", method, t))
	return shared.CopyFile(newPath, filepath.Join(imagesDir, fmt.Sprintf("%s.log", method)))
}