Last active
March 18, 2019 19:39
-
-
Save s1carii/08ddb09e8013323a29bf54c58638db47 to your computer and use it in GitHub Desktop.
Manual backup procedure for running ESXi VMs; works, script to be tested
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Potential solution: | |
#!/bin/sh | |
# create storage directory for vm backup | |
mkdir -p /vmfs/volumes/datastore1/web01-backup/ | |
# copy config files for the running VM | |
cp /vmfs/volumes/datastore1/web01/web01.vmx /vmfs/volumes/datastore1/web01-backup/web01.vmx | |
cp /vmfs/volumes/datastore1/web01/web01.nvram /vmfs/volumes/datastore1/web01-backup/web01.nvram | |
cp /vmfs/volumes/datastore1/web01/web01.vmsd /vmfs/volumes/datastore1/web01-backup/web01.vmsd | |
# create a snapshot of the target VM | |
vmid=$(vim-cmd vmsvc/getallvms | grep web01 | awk '{print $1}') | |
vim-cmd vmsvc/snapshot.create $vmid backup 'Snapshot created by Backup Script' 0 0 | |
# store the vmdk to a backup location while snapshot is running | |
vmkfstools -i /vmfs/volumes/datastore1/web01/web01.vmdk /vmfs/volumes/datastore1/web01-backup/web01.vmdk -d thin | |
# delete/flatten the snapshot | |
vim-cmd vmsvc/snapshot.removeall $vmid | |
# So the process would be: | |
# - Copy the config files to the backup location | |
# -- .vmx, .nvram, .vmsd | |
# - create a snapshot for the vm | |
# - copy the .vmdk to the backup location | |
# - MAKE SURE TO DEL THE SNAPSHOT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment