Skip to content

Instantly share code, notes, and snippets.

@int128
Last active December 10, 2015 06:29
Show Gist options
  • Save int128/4395093 to your computer and use it in GitHub Desktop.
Save int128/4395093 to your computer and use it in GitHub Desktop.
esxi_host='root@192.168.1.100'
esxi_key='/home/jenkins/esxi_key'
function exec_on_esxi () {
ssh -i "${esxi_key}" "${esxi_host}" "$@"
}
function esxi_online_backup () {
vmid="$1"
vmname="$2"
exec_on_esxi df -h
exec_on_esxi vim-cmd vmsvc/snapshot.create ${vmid} current
exec_on_esxi rm -fr "/vmfs/volumes/datastore1/${vmname}/"
exec_on_esxi mkdir -p "/vmfs/volumes/datastore1/${vmname}/"
exec_on_esxi ls -l "/vmfs/volumes/ssd/${vmname}/" "/vmfs/volumes/datastore1/${vmname}/"
exec_on_esxi cp -af "/vmfs/volumes/ssd/${vmname}/*" "/vmfs/volumes/datastore1/${vmname}/" || true
exec_on_esxi ls -l "/vmfs/volumes/ssd/${vmname}/" "/vmfs/volumes/datastore1/${vmname}/"
exec_on_esxi vim-cmd vmsvc/snapshot.removeall ${vmid}
exec_on_esxi df -h
}
exec_on_esxi vim-cmd vmsvc/getallvms
esxi_online_backup 1 buildserver
esxi_online_backup 2 testserver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment