User Tools

Site Tools


general:xenserver:xenserver

This is an old revision of the document!


XenServer 8.x

Auto start VM

Turn on autostart

#!/bin/sh
 
# Turn on auto_poweron
 
xe vm-param-set uuid=$( xe vm-list name-label=<name> --minimal ) other-config:auto_poweron=true

Turn off autostart

#!/bin/sh
 
# Turn off auto_poweron
 
xe vm-param-set uuid=$( xe vm-list name-label=<name> --minimal ) other-config:auto_poweron=false

Backup metadata to other storage

#!/bin/bash
 
STORAGE_SR_NAME="/dev/sdb1"
 
if [ -e /etc/xensource/pool.conf ]; then
    if [ "$(cat /etc/xensource/pool.conf)" = "master" ]; then
        sruuid=$( xe sr-list name-label=${STORAGE_SR_NAME} --minimal )
        "/opt/xensource/bin/xe-backup-metadata" -c -u $sruuid >/dev/null 2>&1
        EXITVALUE=$?
        if [ $EXITVALUE != 0 ]; then
             /usr/bin/logger -t backup-metadata "ALERT exited abnormally with [$EXITVALUE]"
        fi
    fi
fi
 
exit 0

Snapshot and copy VM

Snapshot and copy VM (possibly to other storage)

#!/bin/bash
 
set -e
 
VMToCopy=
NewName=
DestStorageName="Local Storage"
 
oldcopyid=$( xe vm-list name-label=$NewName --minimal )
#echo $oldcopyid
 
snapid=$( xe vm-snapshot name-label=$VMToCopy new-name-label=$NewName-$datestr )
#echo "$? ID: $snapid"
 
datestr=$( date +%Y-%m-%d_%R_%Z )
 
templateid=$( xe snapshot-copy new-name-label=$NewName uuid=$snapid sr-uuid=$( xe sr-list name-label="$DestStorageName" --minimal ) )
#echo "$? ID: $templateid"
 
xe template-param-set uuid=$templateid is-a-template=false
#echo "$? ID: $templateid"
 
xe snapshot-uninstall uuid=$snapid force=true > /dev/null
#echo "$?"
 
xe vm-param-remove uuid=$templateid param-name=other-config param-key=auto_poweron
xe vm-param-set uuid=$templateid name-description="Copy made: $datestr"
#echo "$?"
 
xe vm-reset-powerstate uuid=$templateid force=true
#echo "$?"
 
xe vm-uninstall vm=$oldcopyid force=true > /dev/null
general/xenserver/xenserver.1629877970.txt.gz · Last modified: 2021/08/25 09:52 by