This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
general:xenserver:xenserver [2021/08/25 09:45] created |
general:xenserver:xenserver [2021/08/25 09:53] [Snapshot and copy VM] |
||
---|---|---|---|
Line 4: | Line 4: | ||
Turn on autostart | Turn on autostart | ||
- | <code> | + | <code bash> |
#!/bin/sh | #!/bin/sh | ||
Line 13: | Line 13: | ||
Turn off autostart | Turn off autostart | ||
- | <code> | + | <code bash> |
#!/bin/sh | #!/bin/sh | ||
Line 21: | Line 21: | ||
</code> | </code> | ||
+ | ===== Backup metadata to other storage ===== | ||
+ | <code bash> | ||
+ | #!/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 | ||
+ | </code> | ||
+ | |||
+ | ===== Snapshot and copy VM ===== | ||
+ | |||
+ | Snapshot and copy VM (possibly to other storage) | ||
+ | |||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | |||
+ | set -e | ||
+ | |||
+ | VMToCopy= | ||
+ | NewName=${VMToCopy}-copy | ||
+ | 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 | ||
+ | |||
+ | </code> |