#!/bin/bash # # (c) 2017 GUEST.it s.r.l. # License: GPLv3 https://www.gnu.org/licenses/gpl.txt # # Sample usage: # 1) Export VM and create a raw images (one for each disks) in a single step # wget --http-user= --http-password= https://your.xen.server.host/export?uuid= -O - | tar --to-command=./xva_conv.sh -xf - # # If you need to convert the image (qcow2, ZFS block device, ...) # qm importdisk [OPTIONS] # # qm importdisk is not needed if you'll use raw images, just move the exported disks in proper place # TMP_LASTNAME_PREFIX="/tmp/lastname" if [ "${TAR_FILETYPE}" != "f" ]; then exit fi if [[ "${TAR_FILENAME}" =~ "checksum" || "${TAR_FILENAME}" == "ova.xml" ]]; then exit fi DISKNAME=${TAR_FILENAME%/*} FILENAME=${TAR_FILENAME#*/} CURNUMBER=${FILENAME#"${FILENAME%%[!0]*}"} # First file ? TMP_LASTNAME should be empty if [ ! -f "${TMP_LASTNAME_PREFIX}_${DISKNAME}" ]; then echo ${CURNUMBER} > ${TMP_LASTNAME_PREFIX}_${DISKNAME} cat > ${DISKNAME}.raw else LASTNUM=$(cat ${TMP_LASTNAME_PREFIX}_${DISKNAME}); # is sequential ? if [ $(expr ${LASTNUM} + 1) -eq "${FILENAME}" ]; then cat >> ${DISKNAME}.raw else for i in $(seq $(expr ${LASTNUM} + 1) $(expr ${FILENAME} - 1)); do dd if=/dev/zero of=${DISKNAME}.raw bs=1M count=1 oflag=append conv=notrunc 2>/dev/null done cat >> ${DISKNAME}.raw fi echo ${CURNUMBER} > ${TMP_LASTNAME_PREFIX}_${DISKNAME} fi