Select Git revision
HepialLexer.java
VirtTarOut.go 1.31 KiB
package exec
import (
"fmt"
"os/exec"
"strings"
"errors"
)
const (
virtTarOutBinary = "virt-tar-out"
)
// Checks virt-tar-out is available.
func CheckVirtCopyOut() error {
output, err := exec.Command(virtTarOutBinary, "--version").Output()
if err != nil {
return errors.New(virtTarOutBinary+" is required but not found. On Ubuntu/Debian, it can be installed with \"sudo apt-get install guestfish\".")
}
out := string(output)
lines := strings.Split(out, "\n")
fields := strings.Split(lines[0], " ")
if len(fields) < 2 {
return errors.New("Failed extracting "+virtTarOutBinary+" version number!")
}
cmd := fields[0]
if cmd != virtTarOutBinary {
return errors.New(virtTarOutBinary+" is required, but not found.")
}
return nil
}
// Runs virt-tar-in which unarchive a local archive into a directory (vmDir) inside the VM disk.
// Runs virt-copy-out which recursively extract a directory from the VM's
// filesystem (vmDir) into a tar archive.
func CopyFromVM(vmDiskFile, vmDir, tarFile string) error {
cmd := exec.Command(virtTarOutBinary, "-a", vmDiskFile, vmDir, tarFile)
stdoutStderr, err := cmd.CombinedOutput()
if err != nil {
output := fmt.Sprintf("[%s]", stdoutStderr)
msg := "Failed reading \""+vmDir+"\" in qcow ("+vmDiskFile+"): "+output
log.Error(msg)
return errors.New(msg)
}
return nil
}