mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-22 20:54:49 +09:00
1 parent
548ac12a0a
commit
04a0753489
11 files changed
+478
-121
No files matched your search
@@ -1289,6 +1289,7 @@ TM_QCOW2_FILES="src/tm_mad/qcow2/clone \
|
||||
src/tm_mad/qcow2/mkswap \
|
||||
src/tm_mad/qcow2/mkimage \
|
||||
src/tm_mad/qcow2/mv \
|
||||
src/tm_mad/qcow2/mv.ssh \
|
||||
src/tm_mad/qcow2/context \
|
||||
src/tm_mad/qcow2/premigrate \
|
||||
src/tm_mad/qcow2/postmigrate \
|
||||
@@ -1296,9 +1297,13 @@ TM_QCOW2_FILES="src/tm_mad/qcow2/clone \
|
||||
src/tm_mad/qcow2/mvds \
|
||||
src/tm_mad/qcow2/mvds.ssh \
|
||||
src/tm_mad/qcow2/snap_create \
|
||||
src/tm_mad/qcow2/snap_create.ssh \
|
||||
src/tm_mad/qcow2/snap_create_live \
|
||||
src/tm_mad/qcow2/snap_create_live.ssh \
|
||||
src/tm_mad/qcow2/snap_delete \
|
||||
src/tm_mad/qcow2/snap_delete.ssh \
|
||||
src/tm_mad/qcow2/snap_revert \
|
||||
src/tm_mad/qcow2/snap_revert.ssh \
|
||||
src/tm_mad/qcow2/cpds \
|
||||
src/tm_mad/qcow2/cpds.ssh \
|
||||
src/tm_mad/qcow2/resize"
|
||||
|
||||
@@ -503,3 +503,22 @@ function get_destination_host {
|
||||
|
||||
echo ${HOSTS_ARRAY[$ARRAY_INDEX]}
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------------------
|
||||
# Rebase backing files of snapshots in current directory
|
||||
# @param $1 name of the backing_file symlink used internally
|
||||
#--------------------------------------------------------------------------------
|
||||
rebase_backing_files() {
|
||||
local DST_FILE=$1
|
||||
|
||||
for SNAP_ID in $(find * -maxdepth 0 -type f -print); do
|
||||
INFO=$(qemu-img info --output=json $SNAP_ID)
|
||||
|
||||
if [[ $INFO =~ "backing-filename" ]]; then
|
||||
BACKING_FILE=${INFO/*backing-filename\": \"/}
|
||||
BACKING_FILE=${BACKING_FILE/\"*/}
|
||||
BACKING_FILE=$(basename ${BACKING_FILE})
|
||||
qemu-img rebase -f qcow2 -u -b "${DST_FILE}.snap/$BACKING_FILE" $SNAP_ID
|
||||
fi
|
||||
done
|
||||
}
|
||||
+31
-49
@@ -43,18 +43,20 @@ DRIVER_PATH=$(dirname $0)
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
DST_PATH=`arg_path $DST`
|
||||
|
||||
SRC_PATH_SNAP="${SRC_PATH}.snap"
|
||||
DST_PATH_SNAP="${DST_PATH}.snap"
|
||||
DST_FILE=$(basename "$DST_PATH")
|
||||
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
DST_HOST=`arg_host $DST`
|
||||
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
|
||||
SRC_ARG_PATH=`arg_path $SRC`
|
||||
|
||||
DST_DS_PATH="$(dirname $(dirname $(dirname $DST_PATH)))"
|
||||
SRC_DS_PATH="$(dirname $(dirname $SRC_ARG_PATH))"
|
||||
|
||||
SRC_PATH="${DST_DS_PATH}${SRC_ARG_PATH##$SRC_DS_PATH}"
|
||||
|
||||
DST_FILE=$(basename "$DST_PATH")
|
||||
ssh_make_path $DST_HOST $DST_DIR "ssh"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get Image information
|
||||
@@ -76,50 +78,30 @@ SIZE="${XPATH_ELEMENTS[j++]}"
|
||||
ORIGINAL_SIZE="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Create DST path
|
||||
# Copy files to the remote host
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
ssh_make_path $DST_HOST $DST_DIR 'ssh'
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Clone (cp) SRC into DST
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
type="$(file -b --mime-type $SRC_PATH)"
|
||||
|
||||
if [ "$type" == "application/x-iso9660-image" ]; then
|
||||
CLONE_CMD="cp ${SRC_PATH} ${DST_PATH}"
|
||||
else
|
||||
if [ -n "$ORIGINAL_SIZE" -a "$SIZE" -gt "$ORIGINAL_SIZE" ]; then
|
||||
RESIZE_CMD="qemu-img resize ${DST_PATH} ${SIZE}M"
|
||||
fi
|
||||
|
||||
CLONE_CMD=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
|
||||
cd $DST_DIR
|
||||
|
||||
rm -rf "${DST_PATH}.snap"
|
||||
|
||||
mkdir -p "${DST_PATH}.snap"
|
||||
|
||||
B_FORMAT=\$($QEMU_IMG info $SRC_PATH | grep "^file format:" | awk '{print \$3}' || :)
|
||||
$QEMU_IMG create -o backing_fmt=\${B_FORMAT:-raw} -b $SRC_PATH -f qcow2 $QCOW2_OPTIONS ${DST_PATH}.snap/0
|
||||
|
||||
rm -f "${DST_PATH}"
|
||||
|
||||
ln -s ${DST_FILE}.snap/0 ${DST_PATH}
|
||||
|
||||
cd ${DST_PATH}.snap
|
||||
|
||||
ln -s . ${DST_PATH}.snap/${DST_FILE}.snap
|
||||
|
||||
${RESIZE_CMD}
|
||||
CP_CMD=$(cat << EOF
|
||||
set -e -o pipefail
|
||||
rm -rf $DST_PATH_SNAP
|
||||
mkdir -p $DST_PATH_SNAP
|
||||
qemu-img convert -q -O qcow2 $SRC_PATH $DST_PATH_SNAP/0
|
||||
rm -f $DST_PATH
|
||||
cd $DST_PATH_SNAP
|
||||
ln -sf . $DST_FILE.snap
|
||||
cd ..
|
||||
ln -sf $DST_FILE.snap/0 $DST_PATH
|
||||
EOF
|
||||
)
|
||||
|
||||
log "Copying $SRC in $DST_PATH_SNAP/0"
|
||||
ssh_exec_and_log "$DST_HOST" "$CP_CMD" "Error copying SRC TO $DST_PATH_SNAP/0"
|
||||
|
||||
|
||||
if [ -n "$ORIGINAL_SIZE" -a "$SIZE" -gt "$ORIGINAL_SIZE" ]; then
|
||||
RESIZE_CMD="qemu-img resize ${DST_PATH_SNAP}/0 ${SIZE}M"
|
||||
ssh_exec_and_log "$DST_HOST" "$RESIZE_CMD" \
|
||||
"Error resizing image $DST"
|
||||
fi
|
||||
|
||||
log "Cloning $SRC_PATH in $DST"
|
||||
ssh_exec_and_log "$DST_HOST" "$CLONE_CMD" "Error copying $SRC to $DST"
|
||||
|
||||
exit 0
|
||||
hup_collectd $DST_HOST
|
||||
@@ -57,15 +57,11 @@ while IFS= read -r -d '' element; do
|
||||
done < <(onevm show -x $VMID| $XPATH \
|
||||
/VM/DEPLOY_ID \
|
||||
/VM/LCM_STATE \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/TARGET \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SOURCE \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CLONE)
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/TARGET)
|
||||
|
||||
DEPLOY_ID="${XPATH_ELEMENTS[j++]}"
|
||||
LCM_STATE="${XPATH_ELEMENTS[j++]}"
|
||||
DISK_TARGET="${XPATH_ELEMENTS[j++]}"
|
||||
DISK_SRC="${XPATH_ELEMENTS[j++]}"
|
||||
CLONE="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dir
|
||||
@@ -82,7 +78,6 @@ DST_DS_PATH="$(dirname $(dirname $DST_ARG_PATH))"
|
||||
DST_PATH="${SRC_DS_PATH}${DST_ARG_PATH##$DST_DS_PATH}"
|
||||
|
||||
if [ "$SNAP_ID" != "-1" ]; then
|
||||
[ "$CLONE" != "YES" ] && SRC_PATH="$DISK_SRC"
|
||||
SRC_PATH="$SRC_PATH.snap/$SNAP_ID"
|
||||
fi
|
||||
|
||||
|
||||
+30
-37
@@ -26,7 +26,6 @@
|
||||
|
||||
SRC=$1
|
||||
DST=$2
|
||||
|
||||
VMID=$3
|
||||
DSID=$4
|
||||
|
||||
@@ -36,25 +35,23 @@ else
|
||||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
|
||||
fi
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
LIBFS=${DRIVER_PATH}/../../datastore/libfs.sh
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_HOST=`arg_host $DST`
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_SNAP_DIR=${DST_PATH}.snap
|
||||
DST_FILE=`basename $DST_PATH`
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
|
||||
SRC_ARG_PATH=`arg_path $SRC`
|
||||
|
||||
DST_DS_PATH="$(dirname $(dirname $(dirname $DST_PATH)))"
|
||||
SRC_DS_PATH="$(dirname $(dirname $SRC_ARG_PATH))"
|
||||
|
||||
SRC_PATH="${DST_DS_PATH}${SRC_ARG_PATH##$SRC_DS_PATH}"
|
||||
SNAP_DIR="${SRC_PATH}.snap"
|
||||
SNAP_NAME="$(basename $SNAP_DIR)"
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
SRC_SNAP_DIR=${SRC_PATH}.snap
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Create DST path
|
||||
@@ -63,42 +60,38 @@ SNAP_NAME="$(basename $SNAP_DIR)"
|
||||
ssh_make_path $DST_HOST $DST_DIR 'ssh'
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Link (ln) SRC into DST
|
||||
# Copy SRC into DST
|
||||
#-------------------------------------------------------------------------------
|
||||
log "Linking $SRC_PATH in $DST"
|
||||
log "Copying $SRC_PATH in $DST"
|
||||
|
||||
type="$(file -b --mime-type $SRC_PATH)"
|
||||
|
||||
if [ "$type" == "application/x-iso9660-image" ]; then
|
||||
CMD="ln -sf ${SRC_PATH} ${DST_PATH}"
|
||||
else
|
||||
CMD=$(cat <<EOT
|
||||
CMD=$(cat <<EOT
|
||||
set -ex -o pipefail
|
||||
mkdir -p "${DST_SNAP_DIR}"
|
||||
cd "${DST_SNAP_DIR}"
|
||||
|
||||
mkdir -p "${SNAP_DIR}"
|
||||
|
||||
if [ ! -L "${SNAP_DIR}/${SNAP_NAME}" ]; then
|
||||
ln -s "${SNAP_DIR}" "${SNAP_DIR}/${SNAP_NAME}"
|
||||
if [ -d ${SRC_SNAP_DIR} ]; then
|
||||
for F in \$(ls ${SRC_SNAP_DIR}); do
|
||||
if [ -f ${SRC_SNAP_DIR}/\$F ]; then
|
||||
cp ${SRC_SNAP_DIR}/\$F .
|
||||
fi
|
||||
done
|
||||
else
|
||||
cp ${SRC_PATH} 0
|
||||
fi
|
||||
|
||||
SNAP="\$(ls ${SNAP_DIR} | grep '^[[:digit:]]*$' | sort -n | tail -n 1 || :)"
|
||||
rm -f "${DST_FILE}.snap"
|
||||
ln -sf "." "${DST_FILE}.snap"
|
||||
|
||||
if [ -z "\${SNAP}" ]; then
|
||||
SNAP=0
|
||||
ln -sf "$SRC_PATH" "$SNAP_DIR/0"
|
||||
fi
|
||||
rebase_backing_files "$DST_FILE"
|
||||
|
||||
rm -f "${DST_PATH}"
|
||||
SNAP="\$(ls | grep '^[[:digit:]]*$' | sort -n | tail -n 1 || :)"
|
||||
cd ..
|
||||
rm -f "${DST_FILE}"
|
||||
ln -sf "${DST_FILE}.snap/\$SNAP" "${DST_FILE}"
|
||||
|
||||
ln -sf "$SNAP_DIR/\$SNAP" "$DST_PATH"
|
||||
|
||||
rm -rf "${DST_PATH}.snap"
|
||||
|
||||
ln -sf "$SNAP_DIR" "${DST_PATH}.snap"
|
||||
EOT
|
||||
)
|
||||
fi
|
||||
|
||||
ssh_exec_and_log $DST_HOST "$CMD" "Error linking $SRC to $DST"
|
||||
ssh_exec_and_log_stdin $DST_HOST "$CMD" "$LIBFS" "Error copying $SRC to $DST"
|
||||
|
||||
exit 0
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../ssh/mv
|
||||
+29
-29
@@ -26,7 +26,6 @@
|
||||
|
||||
SRC=$1
|
||||
DST=$2
|
||||
|
||||
VMID=$3
|
||||
DSID=$4
|
||||
|
||||
@@ -36,39 +35,23 @@ else
|
||||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
|
||||
fi
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
LIBFS=${DRIVER_PATH}/../../datastore/libfs.sh
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get Image information
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
DISK_ID=$(basename ${SRC} | cut -d. -f2)
|
||||
|
||||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <(onevm show -x $VMID| $XPATH \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CLONE)
|
||||
|
||||
CLONE="${XPATH_ELEMENTS[j++]}"
|
||||
if [ "$CLONE" != "YES" ]; then
|
||||
# it's persistent image, nothing to do
|
||||
exit 0
|
||||
fi
|
||||
. $TMCOMMON
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
SRC_PATH="$(arg_path $SRC)"
|
||||
SRC_HOST="$(arg_host $SRC)"
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
SRC_SNAP_DIR=${SRC_PATH}.snap
|
||||
|
||||
DST_PATH="$(arg_path $DST)"
|
||||
DST_PATH="$DST"
|
||||
DST_FILE=`basename $DST`
|
||||
DST_SNAP_DIR=${DST_PATH}.snap
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Move the image back to the datastore
|
||||
@@ -76,8 +59,25 @@ DST_PATH="$(arg_path $DST)"
|
||||
|
||||
log "Moving $SRC to datastore as $DST"
|
||||
|
||||
ssh_exec_and_log "${SRC_HOST}" \
|
||||
"cp -r ${SRC_PATH} ${DST_PATH}" \
|
||||
"Error copying ${SRC} to ${DST}" >&2
|
||||
MV_CMD=$(cat <<EOT
|
||||
set -ex -o pipefail
|
||||
rm -rf ${DST_SNAP_DIR}
|
||||
mkdir -p ${DST_SNAP_DIR}
|
||||
|
||||
mv ${SRC_SNAP_DIR}/[0-9]* ${DST_SNAP_DIR}
|
||||
cd "${DST_SNAP_DIR}"
|
||||
ln -sf "." "${DST_FILE}.snap"
|
||||
|
||||
rebase_backing_files "$DST_FILE"
|
||||
|
||||
SNAP="\$(ls | grep '^[[:digit:]]*$' | sort -n | tail -n 1 || :)"
|
||||
cd ..
|
||||
rm "${DST_FILE}"
|
||||
ln -sf "${DST_FILE}.snap/\$SNAP" "${DST_FILE}"
|
||||
rm -rf ${SRC_PATH}
|
||||
EOT
|
||||
)
|
||||
|
||||
ssh_exec_and_log_stdin "$SRC_HOST" "$MV_CMD" "$LIBFS" "Error moving disk ${SRC_PATH} to ${DST_PATH} on $SRC_HOST"
|
||||
|
||||
exit 0
|
||||
Executable
+85
@@ -0,0 +1,85 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# snap_create host:parent_image snap_id vmid ds_id
|
||||
|
||||
SRC=$1
|
||||
SNAP_ID=$2
|
||||
VMID=$3
|
||||
DSID=$4
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
DATASTORES=/var/lib/one/datastores
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
|
||||
DATASTORES=$ONE_LOCATION/var/datastores
|
||||
fi
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
SRC_PATH=$(arg_path $SRC)
|
||||
SRC_HOST=$(arg_host $SRC)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get Image information
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
DISK_ID=$(basename ${SRC} | cut -d. -f2)
|
||||
|
||||
|
||||
SYSTEM_DS_PATH=$(dirname ${SRC_PATH})
|
||||
|
||||
SYSTEM_DS_DISK_PATH="${SYSTEM_DS_PATH}/disk.${DISK_ID}"
|
||||
|
||||
# for TM_MAD=ssh create the snapshot always on system DS
|
||||
DISK_PATH="${SYSTEM_DS_DISK_PATH}"
|
||||
DISK_PATH_SHORT="$(basename ${SYSTEM_DS_DISK_PATH})"
|
||||
|
||||
NEXT_SNAP_ID=$(($SNAP_ID+1))
|
||||
|
||||
SNAP_DIR="${DISK_PATH}.snap"
|
||||
SNAP_DIR_SHORT="${DISK_PATH_SHORT}.snap"
|
||||
|
||||
SNAP_PATH="${SNAP_DIR}/${NEXT_SNAP_ID}"
|
||||
SNAP_PATH_SHORT="${SNAP_DIR_SHORT}/${NEXT_SNAP_ID}"
|
||||
|
||||
SNAP_CMD=$(cat <<EOT
|
||||
set -ex -o pipefail
|
||||
|
||||
mkdir -p "${SNAP_DIR}"
|
||||
|
||||
PREVIOUS_SNAP=\$(readlink $SYSTEM_DS_DISK_PATH)
|
||||
|
||||
cd "${SNAP_DIR}"
|
||||
|
||||
if [ -e "${SNAP_PATH}" ]; then
|
||||
echo "Snapshot file ${SNAP_PATH} already exists." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
qemu-img create -f qcow2 -o backing_fmt=qcow2 -b "\${PREVIOUS_SNAP}" "${SNAP_PATH}"
|
||||
ln -sf $SNAP_PATH_SHORT $SYSTEM_DS_DISK_PATH
|
||||
EOT
|
||||
)
|
||||
|
||||
ssh_exec_and_log "${SRC_HOST}" "${SNAP_CMD}" \
|
||||
"Error creating snapshot ${SNAP_PATH}"
|
||||
|
||||
Executable
+159
@@ -0,0 +1,159 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# snap_create host:parent_image snap_id vmid ds_id
|
||||
|
||||
SRC=$1
|
||||
SNAP_ID=$2
|
||||
VMID=$3
|
||||
DSID=$4
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
DATASTORES=/var/lib/one/datastores
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
|
||||
DATASTORES=$ONE_LOCATION/var/datastores
|
||||
fi
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
source $TMCOMMON
|
||||
source ${DRIVER_PATH}/../../etc/vmm/kvm/kvmrc
|
||||
|
||||
SRC_PATH=$(arg_path $SRC)
|
||||
SRC_HOST=$(arg_host $SRC)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get Image information
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
DISK_ID=$(basename ${SRC} | cut -d. -f2)
|
||||
|
||||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <(onevm show -x $VMID| $XPATH \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/TARGET \
|
||||
/VM/DEPLOY_ID \
|
||||
'%m%/VM/TEMPLATE/DISK/TARGET')
|
||||
|
||||
TARGET="${XPATH_ELEMENTS[j++]}"
|
||||
DEPLOY_ID="${XPATH_ELEMENTS[j++]}"
|
||||
ALL_DISKS="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
SYSTEM_DS_PATH=$(dirname ${SRC_PATH})
|
||||
|
||||
SYSTEM_DS_DISK_PATH="${SYSTEM_DS_PATH}/disk.${DISK_ID}"
|
||||
|
||||
DISK_PATH="${SYSTEM_DS_DISK_PATH}"
|
||||
DISK_PATH_SHORT="$(basename ${SYSTEM_DS_DISK_PATH})"
|
||||
|
||||
NEXT_SNAP_ID=$(($SNAP_ID+1))
|
||||
|
||||
SNAP_DIR="${DISK_PATH}.snap"
|
||||
SNAP_DIR_SHORT="${DISK_PATH_SHORT}.snap"
|
||||
|
||||
SNAP_PATH="${SNAP_DIR}/${NEXT_SNAP_ID}"
|
||||
SNAP_PATH_SHORT="${SNAP_DIR_SHORT}/${NEXT_SNAP_ID}"
|
||||
|
||||
# virsh snapshot-create by default creates snapshots for all the disks that
|
||||
# are not read only. To be able to make a snapshot in only one of the disks
|
||||
# an xml must be created describing all of the disks and setting the value
|
||||
# snapshot='no' to the disks that are not going to be snapshotted.
|
||||
|
||||
# <domainsnapshot>
|
||||
# <name>1</name>
|
||||
# <description>snap 1</description>
|
||||
# <disks>
|
||||
# <disk name='vda' snapshot='no'/>
|
||||
# <disk name='vdb'>
|
||||
# <source file='/var/lib/one/datastores/1/09eec196c67b38dea41048a628978600.snap/1'/>
|
||||
# </disk>
|
||||
# <disk name='vdc' snapshot='no'/>
|
||||
# </disks>
|
||||
# </domainsnapshot>
|
||||
|
||||
DOC="
|
||||
<domainsnapshot>
|
||||
<name>${DISK_ID}-${SNAP_ID}</name>
|
||||
<description>snap ${DISK_ID}-${SNAP_ID}</description>
|
||||
<disks>"
|
||||
|
||||
for disk in $ALL_DISKS; do
|
||||
if [ "$disk" = "$TARGET" ]; then
|
||||
DOC="$DOC
|
||||
<disk name='$disk' snapshot='external'>
|
||||
<source file='$SNAP_PATH'/>
|
||||
</disk>"
|
||||
else
|
||||
DOC="$DOC
|
||||
<disk name='$disk' snapshot='no'/>"
|
||||
fi
|
||||
done
|
||||
|
||||
DOC="$DOC
|
||||
</disks>
|
||||
</domainsnapshot>"
|
||||
|
||||
CMD=$(cat <<EOT
|
||||
set -ex -o pipefail
|
||||
|
||||
mkdir -p "${SNAP_DIR}"
|
||||
|
||||
PREVIOUS_SNAP=\$(readlink $SYSTEM_DS_DISK_PATH)
|
||||
|
||||
# Temporary xml file
|
||||
FILENAME="/tmp/snapshot-$VMID-$DISK_ID-$SNAP_ID"
|
||||
echo "$DOC" > \$FILENAME
|
||||
|
||||
if virsh -c $LIBVIRT_URI domfsfreeze $DEPLOY_ID ; then
|
||||
trap "virsh -c $LIBVIRT_URI domfsthaw $DEPLOY_ID" EXIT TERM INT HUP
|
||||
elif virsh -c $LIBVIRT_URI suspend $DEPLOY_ID; then
|
||||
trap "virsh -c $LIBVIRT_URI resume $DEPLOY_ID" EXIT TERM INT HUP
|
||||
else
|
||||
echo "Could not domfsfreeze or suspend domain" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# older qemu-img requires relative backing file paths
|
||||
# to be resolvable from the current directory
|
||||
cd "${SNAP_DIR}"
|
||||
|
||||
if [ -e "${SNAP_PATH}" ]; then
|
||||
echo "Snapshot file ${SNAP_PATH} already exists." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
$QEMU_IMG create -o backing_fmt=qcow2 -b "\${PREVIOUS_SNAP}" \
|
||||
-f qcow2 ${QCOW2_OPTIONS} "${SNAP_PATH}"
|
||||
|
||||
virsh -c $LIBVIRT_URI snapshot-create $DEPLOY_ID --disk-only --atomic --no-metadata \
|
||||
--reuse-external --xmlfile \$FILENAME
|
||||
|
||||
rm \${FILENAME}
|
||||
|
||||
ln -sf $SNAP_PATH_SHORT $SYSTEM_DS_DISK_PATH
|
||||
EOT
|
||||
)
|
||||
|
||||
ssh_exec_and_log "${SRC_HOST}" "${CMD}" \
|
||||
"Error creating snapshot ${SNAP_PATH}"
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# snap_delete host:parent_image snap_id vmid ds_id
|
||||
|
||||
SRC=$1
|
||||
SNAP_ID=$2
|
||||
VMID=$3
|
||||
DSID=$4
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
DATASTORES=/var/lib/one/datastores
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
|
||||
DATASTORES=$ONE_LOCATION/var/datastores
|
||||
fi
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
SRC_PATH=$(arg_path $SRC)
|
||||
SRC_HOST=$(arg_host $SRC)
|
||||
|
||||
DISK_ID=$(basename ${SRC} | cut -d. -f2)
|
||||
SYSTEM_DS_PATH=$(dirname ${SRC_PATH})
|
||||
|
||||
DISK_PATH="${SYSTEM_DS_PATH}/disk.${DISK_ID}"
|
||||
|
||||
SNAP_DIR="${DISK_PATH}.snap"
|
||||
SNAP_PATH="${SNAP_DIR}/${SNAP_ID}"
|
||||
|
||||
ssh_exec_and_log "${SRC_HOST}" "rm ${SNAP_PATH}" \
|
||||
"Error deleting snapshot ${SNAP_PATH}"
|
||||
|
||||
Executable
+67
@@ -0,0 +1,67 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# snap_create host:parent_image snap_id vmid ds_id
|
||||
|
||||
SRC=$1
|
||||
SNAP_ID=$2
|
||||
VMID=$3
|
||||
DSID=$4
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
DATASTORES=/var/lib/one/datastores
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
|
||||
DATASTORES=$ONE_LOCATION/var/datastores
|
||||
fi
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
SRC_PATH=$(arg_path $SRC)
|
||||
SRC_HOST=$(arg_host $SRC)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get Image information
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
DISK_ID=$(basename ${SRC} | cut -d. -f2)
|
||||
|
||||
|
||||
SYSTEM_DS_PATH=$(dirname ${SRC_PATH})
|
||||
|
||||
DISK_PATH="${SYSTEM_DS_PATH}/disk.${DISK_ID}"
|
||||
|
||||
SNAP_DIR="${DISK_PATH}.snap"
|
||||
SNAP_DIR_SHORT=$(basename "$SNAP_DIR")
|
||||
|
||||
SNAP_PATH="${SNAP_DIR}/${SNAP_ID}"
|
||||
SNAP_PATH_SHORT="${SNAP_DIR_SHORT}/${SNAP_ID}"
|
||||
|
||||
SNAP_CMD=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
|
||||
cd "${SNAP_DIR}"
|
||||
qemu-img create -f qcow2 -o backing_fmt=qcow2 -b "${SNAP_PATH_SHORT}" "\$(readlink -f ${DISK_PATH})"
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "${SRC_HOST}" "${SNAP_CMD}" \
|
||||
"Error reverting snapshot to ${SNAP_PATH}"
|
||||
Reference in new issue
Block a user