Skip to content

Instantly share code, notes, and snippets.

@silas
Created September 14, 2010 20:18
Show Gist options
  • Save silas/579690 to your computer and use it in GitHub Desktop.
Save silas/579690 to your computer and use it in GitHub Desktop.
Live XCP host backups
#!/usr/bin/env bash
DST_PATH="${DST_PATH:-/tmp}"
backup() {
uuid="$1"
label_name=$( xe vm-list uuid="$uuid" | grep 'name-label' | cut -b 24- )
snapshot_uuid=$( xe vm-snapshot vm="$uuid" new-name-label=backup_vm )
xe template-param-set is-a-template=false ha-always-run=false uuid="$snapshot_uuid"
filename="$DST_PATH/$( date +%Y-%m-%d )-$uuid.xva"
xe vm-export vm="$snapshot_uuid" filename="$filename"
xe vm-uninstall uuid="$snapshot_uuid" force=true
}
backup_all() {
options="vm-list is-control-domain=false is-a-template=false is-a-snapshot=false"
for uuid in $( xe $options | grep 'uuid' | awk -F': ' '{ print $2 }' ); do
backup "$uuid"
done
}
if [[ -z "$1" ]]; then
echo "Usage: $0 (<UUID>|all)"
exit 2
fi
if [[ "$1" = "all" ]]; then
backup_all
else
backup "$1"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment