diff --git a/scripts/xe-backup-metadata b/scripts/xe-backup-metadata index 369e489c218..35fa31a5e94 100755 --- a/scripts/xe-backup-metadata +++ b/scripts/xe-backup-metadata @@ -74,7 +74,7 @@ function validate_vdi_uuid { function test_sr { sr_uuid_found=$(${XE} sr-list uuid="$1" --minimal) if [ "${sr_uuid_found}" != "$1" ]; then - echo Invalid SR UUID specified: $1 + echo "Invalid SR UUID specified: $1" usage fi } @@ -112,32 +112,32 @@ fi # determine if the SR UUID is vaid if [ -z "${sr_uuid}" ]; then # use the default-SR from the pool - sr_uuid=$(${XE} pool-param-get uuid=${pool_uuid} param-name=default-SR) + sr_uuid=$(${XE} pool-param-get uuid="${pool_uuid}" param-name=default-SR) fi test_sr "${sr_uuid}" sr_name=$(${XE} sr-param-get uuid="${sr_uuid}" param-name=name-label) # see if a backup VDI already exists on the selected SR -vdi_uuid=$(${XE} vdi-list other-config:ctxs-pool-backup=true sr-uuid=${sr_uuid} params=uuid --minimal) +vdi_uuid=$(${XE} vdi-list other-config:ctxs-pool-backup=true sr-uuid="${sr_uuid}" params=uuid --minimal) mnt= function cleanup { trap "" TERM INT cd / if [ ! -z "${mnt}" ]; then - umount ${mnt} >/dev/null 2>&1 - rmdir ${mnt} + umount "${mnt}" >/dev/null 2>&1 + rmdir "${mnt}" fi if [ ! -z "${vbd_uuid}" ]; then ${debug} echo -n "Unplugging VBD: " - ${XE} vbd-unplug uuid=${vbd_uuid} timeout=20 + ${XE} vbd-unplug uuid="${vbd_uuid}" timeout=20 # poll for the device to go away if we know its name if [ "${device}" != "" ]; then device_gone=0 for ((i=0; i<10; i++)); do ${debug} echo -n "." - if [ ! -b ${device} ]; then + if [ ! -b "${device}" ]; then ${debug} echo " done" device_gone=1 break @@ -146,14 +146,14 @@ function cleanup { done if [ ${device_gone} -eq 0 ]; then ${debug} echo " failed" - echo Please destroy VBD ${vbd_uuid} manually. + echo "Please destroy VBD ${vbd_uuid} manually." else - ${XE} vbd-destroy uuid=${vbd_uuid} + ${XE} vbd-destroy uuid="${vbd_uuid}" fi fi fi if [ ${fs_uninitialised} -eq 1 -a -n "${vdi_uuid}" ] ; then - ${XE} vdi-destroy uuid=${vdi_uuid} + ${XE} vdi-destroy uuid="${vdi_uuid}" fi } @@ -184,8 +184,8 @@ if [ -z "${vdi_uuid}" ]; then echo "Backup VDI not found, aborting. You can initialise one using the '-c' flag." exit 3 fi - echo ${vdi_uuid} - ${XE} vdi-param-set uuid=${vdi_uuid} other-config:ctxs-pool-backup=true + echo "${vdi_uuid}" + ${XE} vdi-param-set uuid="${vdi_uuid}" other-config:ctxs-pool-backup=true else ${debug} echo "Using existing backup VDI: ${vdi_uuid}" fs_uninitialised=0 @@ -196,71 +196,71 @@ if [ ${just_find_vdi} -gt 0 ]; then fi ${debug} echo -n "Creating VBD: " -vbd_uuid=$(${XE} vbd-create vm-uuid=${CONTROL_DOMAIN_UUID} vdi-uuid=${vdi_uuid} device=autodetect) -${debug} echo ${vbd_uuid} +vbd_uuid=$(${XE} vbd-create vm-uuid="${CONTROL_DOMAIN_UUID}" vdi-uuid="${vdi_uuid}" device=autodetect) +${debug} echo "${vbd_uuid}" if [ $? -ne 0 -o -z "${vbd_uuid}" ]; then - echo error creating VBD + echo "error creating VBD" cleanup exit 1 fi ${debug} echo -n "Plugging VBD: " -${XE} vbd-plug uuid=${vbd_uuid} -device=/dev/$(${XE} vbd-param-get uuid=${vbd_uuid} param-name=device) +${XE} vbd-plug uuid="${vbd_uuid}" +device=/dev/$(${XE} vbd-param-get uuid="${vbd_uuid}" param-name=device) -if [ ! -b ${device} ]; then - ${debug} echo ${device}: not a block special +if [ ! -b "${device}" ]; then + ${debug} echo "${device}: not a block special" cleanup exit 1 fi -${debug} echo ${device} +${debug} echo "${device}" -if [ $init_fs -eq 1 ]; then +if [ "$init_fs" -eq 1 ]; then ${debug} echo -n "Creating filesystem: " - mkfs.ext3 -j -F ${device} > /dev/null 2>&1 + mkfs.ext3 -j -F "${device}" > /dev/null 2>&1 ${debug} echo "done" fs_uninitialised=0 fi ${debug} echo -n "Mounting filesystem: " -mnt=/var/run/pool-backup-${vdi_uuid} -mkdir -p ${mnt} +mnt="/var/run/pool-backup-${vdi_uuid}" +mkdir -p "${mnt}" -/sbin/fsck -a ${device} >/dev/null 2>&1 +/sbin/fsck -a "${device}" >/dev/null 2>&1 if [ $? -ne 0 ]; then ${debug} fsck failed. Please correct manually cleanup exit 1 fi -mount ${device} ${mnt} > /dev/null 2>&1 +mount "${device}" "${mnt}" > /dev/null 2>&1 if [ $? -ne 0 ]; then ${debug} echo failed cleanup exit 1 fi -${debug} echo ${mnt} +${debug} echo "${mnt}" if [ ${leave_mounted} -eq 0 ]; then - lrconf=${mnt}/conf/${vdi_uuid} - if [ ! -f ${lrconf} ]; then + lrconf="${mnt}/conf/${vdi_uuid}" + if [ ! -f "${lrconf}" ]; then ${debug} echo -n "Initialising rotation: " - mkdir -p ${mnt}/conf/ - echo "${mnt}/${pool_uuid}.db {" >> ${lrconf} - echo " rotate ${history_kept}" >> ${lrconf} - echo " missingok" >> ${lrconf} - echo "}" >> ${lrconf} - echo done - echo ${metadata_version} >> ${mnt}/.ctxs-metadata-backup + mkdir -p "${mnt}/conf/" + echo "${mnt}/${pool_uuid}.db {" >> "${lrconf}" + echo " rotate ${history_kept}" >> "${lrconf}" + echo " missingok" >> "${lrconf}" + echo "}" >> "${lrconf}" + echo "done" + echo "${metadata_version}" >> "${mnt}/.ctxs-metadata-backup" fi # check the usage of the backup VDI - usage=`cd ${mnt} && df . | sed -n "2p" | awk '{ print $5 }' | tr -d '%'` + usage=`cd "${mnt}" && df . | sed -n "2p" | awk '{ print $5 }' | tr -d '%'` echo "Checking backup VDI space usage: $usage%" - if [ $usage -gt $usage_alert ] && [ ${force_backup} -eq 0 ]; then + if [ "$usage" -gt "$usage_alert" ] && [ "${force_backup}" -eq 0 ]; then echo "Running out of space, you can use '-d' option to attach VDI and free more space, exit now." cleanup exit 1 @@ -268,38 +268,38 @@ if [ ${leave_mounted} -eq 0 ]; then # invoke logrotate to rotate over old pool db backups echo -n "Rotating old backups: " - logrotate -f ${lrconf} - num_found=$(find ${mnt} -name \*.db\.* | wc -l) - echo found ${num_found} + logrotate -f "${lrconf}" + num_found=$(find "${mnt}" -name '*.db.*' | wc -l) + echo "found ${num_found}" # perform the pool database dump echo -n "Backing up pool database: " - ${XE} pool-dump-database file-name=${mnt}/${pool_uuid}.db + ${XE} pool-dump-database file-name="${mnt}/${pool_uuid}.db" echo done # backup the VM metadata for each VM in the pool into a dated directory datetime=$(date +%F-%H-%M-%S) - metadir=${mnt}/metadata/${datetime} - mkdir -p ${metadir} + metadir="${mnt}/metadata/${datetime}" + mkdir -p "${metadir}" echo -n "Cleaning old VM metadata: " IFS=" " - todelete=$(cd ${mnt}/metadata && ls -1 |sort -n | head -n -${history_kept} | xargs echo) + todelete=$(cd "${mnt}/metadata" && ls -1 |sort -n | head -n -${history_kept} | xargs echo) for dir in ${todelete}; do - rm -rf ${mnt}/metadata/${dir} + rm -rf "${mnt}/metadata/${dir}" done echo done IFS="," echo -n "Backing up SR metadata: " - mkdir -p ${metadir} - "@LIBEXECDIR@/backup-sr-metadata.py" -f ${metadir}/SRMETA.xml + mkdir -p "${metadir}" + "@LIBEXECDIR@/backup-sr-metadata.py" -f "${metadir}/SRMETA.xml" echo "done" echo -n "Backing up VM metadata: " ${debug} echo "" - mkdir -p ${metadir}/all + mkdir -p "${metadir}/all" for vmuuid in $(${XE} vm-list params=uuid is-control-domain=false --minimal); do ${debug} echo -n . - ${XE} vm-export --metadata uuid=${vmuuid} filename=${metadir}/all/${vmuuid}.vmmeta >/dev/null 2>&1 + ${XE} vm-export --metadata uuid="${vmuuid}" filename="${metadir}/all/${vmuuid}.vmmeta" >/dev/null 2>&1 done echo "done" echo -n "Backing up Template metadata: " @@ -307,13 +307,13 @@ if [ ${leave_mounted} -eq 0 ]; then template_uuids=$("@LIBEXECDIR@/print-custom-templates") if [ $? -eq 0 ]; then for tmpl_uuid in ${template_uuids}; do - ${XE} template-export --metadata template-uuid=${tmpl_uuid} filename=${metadir}/all/${tmpl_uuid}.vmmeta >/dev/null 2>&1 + ${XE} template-export --metadata template-uuid="${tmpl_uuid}" filename="${metadir}/all/${tmpl_uuid}.vmmeta" >/dev/null 2>&1 done fi echo "done" - "@LIBEXECDIR@/link-vms-by-sr.py" -d ${metadir} + "@LIBEXECDIR@/link-vms-by-sr.py" -d "${metadir}" else - cd ${mnt} + cd "${mnt}" env PS1="Mounted backup VDI on: ${mnt}\nPress ^D to exit shell and safely detach it.\n\n[\u@\h \W]\$ " bash fi diff --git a/scripts/xe-restore-metadata b/scripts/xe-restore-metadata index cdcf0d7f495..9018fe85875 100755 --- a/scripts/xe-restore-metadata +++ b/scripts/xe-restore-metadata @@ -55,7 +55,7 @@ function usage { function test_sr { sr_uuid_found=$(${XE} sr-list uuid="$1" --minimal) if [ "${sr_uuid_found}" != "$1" ]; then - echo Invalid SR UUID specified: $1 + echo "Invalid SR UUID specified: $1" usage fi } @@ -109,11 +109,11 @@ fi # determine if the SR UUID is vaid if [ -z "${sr_uuid}" ]; then # use the default-SR from the pool - sr_uuid=$(${XE} pool-param-get uuid=${pool_uuid} param-name=default-SR) + sr_uuid=$(${XE} pool-param-get uuid="${pool_uuid}" param-name=default-SR) fi test_sr "${sr_uuid}" -sr_name=$(${XE} sr-param-get uuid=${sr_uuid} param-name=name-label) +sr_name=$(${XE} sr-param-get uuid="${sr_uuid}" param-name=name-label) # probe first for a VDI with known UUID derived from the SR to avoid # scanning for a VDI @@ -131,20 +131,20 @@ mnt= function cleanup { cd / if [ ! -z "${mnt}" ]; then - umount ${mnt} >/dev/null 2>&1 - rmdir ${mnt} + umount "${mnt}" >/dev/null 2>&1 + rmdir "${mnt}" mnt="" fi if [ ! -z "${vbd_uuid}" ]; then ${debug} echo -n "Unplugging VBD: " >&2 - ${XE} vbd-unplug uuid=${vbd_uuid} timeout=20 + ${XE} vbd-unplug uuid="${vbd_uuid}" timeout=20 # poll for the device to go away if we know its name if [ "${device}" != "" ]; then device_gone=0 for ((i=0; i<10; i++)); do ${debug} echo -n "." >&2 - if [ ! -b ${device} ]; then + if [ ! -b "${device}" ]; then ${debug} echo " done" >&2 device_gone=1 break @@ -153,9 +153,9 @@ function cleanup { done if [ ${device_gone} -eq 0 ]; then ${debug} echo " failed" >&2 - ${debug} echo Please destroy VBD ${vbd_uuid} manually. >&2 + ${debug} echo "Please destroy VBD ${vbd_uuid} manually." >&2 else - ${XE} vbd-destroy uuid=${vbd_uuid} + ${XE} vbd-destroy uuid="${vbd_uuid}" vbd_uuid="" fi fi @@ -164,7 +164,7 @@ function cleanup { } if [ -z "${vdis}" ]; then - echo No VDIs found on SR. >&2 + echo "No VDIs found on SR." >&2 exit 0 fi @@ -173,45 +173,44 @@ trap cleanup SIGINT ERR for vdi_uuid in ${vdis}; do if [ "${vdi_uuid}" != "${backup_vdi}" ]; then echo "Probing VDI ${vdi_uuid}." - echo "This VDI was created with a prior version of XenServer." + echo "This VDI was created with a prior version of this code." echo "Its validity can't be checked without mounting it first." read -p "Continue? [Y/N]" -n 1 -r; echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; fi fi ${debug} echo -n "Creating VBD: " >&2 - vbd_uuid=$(${XE} vbd-create vm-uuid=${CONTROL_DOMAIN_UUID} vdi-uuid=${vdi_uuid} device=autodetect 2>/dev/null) + vbd_uuid=$(${XE} vbd-create vm-uuid="${CONTROL_DOMAIN_UUID}" vdi-uuid="${vdi_uuid}" device=autodetect 2>/dev/null) if [ $? -ne 0 -o -z "${vbd_uuid}" ]; then - ${debug} echo error creating VBD for VDI ${vdi_uuid} >&2 + ${debug} echo "error creating VBD for VDI ${vdi_uuid}" >&2 cleanup continue fi - ${debug} echo ${vbd_uuid} >&2 + ${debug} echo "${vbd_uuid}" >&2 ${debug} echo -n "Plugging VBD: " >&2 - ${XE} vbd-plug uuid=${vbd_uuid} - device=/dev/$(${XE} vbd-param-get uuid=${vbd_uuid} param-name=device) + ${XE} vbd-plug uuid="${vbd_uuid}" + device=/dev/$(${XE} vbd-param-get uuid="${vbd_uuid}" param-name=device) - if [ ! -b ${device} ]; then - ${debug} echo ${device}: not a block special >&2 + if [ ! -b "${device}" ]; then + ${debug} echo "${device}: not a block special" >&2 cleanup continue fi - ${debug} echo ${device} >&2 + ${debug} echo "${device}" >&2 ${debug} echo -n "Probing device: " >&2 mnt= if [ "$(file_exists "${device}" "/.ctxs-metadata-backup")" = y ]; then - ${debug} echo found metadata backup >&2 - ${debug} echo -n "Mounting filesystem: " >&2 - mnt=/var/run/pool-backup-${vdi_uuid} - mkdir -p ${mnt} + ${debug} echo "found metadata backup" >&2 + mnt="/var/run/pool-backup-${vdi_uuid}" + mkdir -p "${mnt}" /sbin/e2fsck -p -f "${device}" >/dev/null 2>&1 if [ $? -ne 0 ]; then - echo File system integrity error. Please correct manually. >&2 + echo "File system integrity error. Please correct manually." >&2 cleanup continue fi @@ -221,36 +220,36 @@ for vdi_uuid in ${vdis}; do cleanup else if [ -e "${mnt}/.ctxs-metadata-backup" ]; then - ${debug} echo Found backup metadata on VDI: ${vdi_uuid} >&2 - xe vdi-param-set uuid=${vdi_uuid} other-config:ctxs-pool-backup=true + ${debug} echo "Found backup metadata on VDI: ${vdi_uuid}" >&2 + xe vdi-param-set uuid="${vdi_uuid}" other-config:ctxs-pool-backup=true break fi fi else - ${debug} echo backup metadata not found >&2 + ${debug} echo "backup metadata not found" >&2 fi cleanup done if [ $just_probe -gt 0 ]; then - echo ${vdi_uuid} + echo "${vdi_uuid}" cleanup exit 0 fi -cd ${mnt} +cd "${mnt}" ${debug} echo "" >&2 -if [ ! -d ${mnt}/metadata ]; then - echo Metadata backups not found. >&2 +if [ ! -d "${mnt}/metadata" ]; then + echo "Metadata backups not found." >&2 cleanup exit 1 fi -cd ${mnt}/metadata +cd "${mnt}/metadata" -if [ $just_list_dates -gt 0 ]; then - ls -1r ${mnt}/metadata +if [ "$just_list_dates" -gt 0 ]; then + ls -1r "${mnt}/metadata" cleanup exit 0 fi @@ -258,39 +257,39 @@ fi if [ -z "${chosen_date}" ]; then chosen_metadata_dir=$(ls | sort -n | tail -1) if [ -z "${chosen_metadata_dir}" ]; then - echo No VM metadata backups found in ${mnt}/metadata >&2 + echo "No VM metadata backups found in ${mnt}/metadata" >&2 cleanup exit 1 fi else - if [ ! -d ${mnt}/metadata/${chosen_date} ]; then - echo Date directory "${chosen_date}" not found >&2 + if [ ! -d "${mnt}/metadata/${chosen_date}" ]; then + echo "Date directory ${chosen_date} not found" >&2 cleanup exit 1 fi - chosen_metadata_dir=${chosen_date} + chosen_metadata_dir="${chosen_date}" fi case ${restore_mode} in sr) - full_dir=${mnt}/metadata/${chosen_metadata_dir}/by-sr/${sr_uuid} + full_dir="${mnt}/metadata/${chosen_metadata_dir}/by-sr/${sr_uuid}" ;; all) - full_dir=${mnt}/metadata/${chosen_metadata_dir}/all + full_dir="${mnt}/metadata/${chosen_metadata_dir}/all" ;; esac if [ ! -d "${full_dir}" ]; then - echo No VM metadata exports were found for the selected SR >&2 + echo "No VM metadata exports were found for the selected SR" >&2 cleanup exit 1 fi -${debug} echo Selected: ${full_dir} +${debug} echo "Selected: ${full_dir}" -cd ${full_dir} +cd "${full_dir}" ${debug} echo "" >&2 -${debug} echo Latest VM metadata found is: >&2 +${debug} echo "Latest VM metadata found is": >&2 ${debug} ls >&2 if [ "$yes" -eq 0 ]; then @@ -298,14 +297,14 @@ if [ "$yes" -eq 0 ]; then echo "Please type in 'yes' and to continue." read response if [ "$response" != "yes" ]; then - echo Aborting metadata restore. + echo "Aborting metadata restore." cleanup exit 1 fi fi ${debug} echo "" >&2 -${debug} echo Restoring VM metadata: >&2 +${debug} echo "Restoring VM metadata:" >&2 trap - ERR