Spearfoot

Bash script to create and download ESXi server configuration

Jun 5th, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.22 KB | None | 0 0
  1. #!/bin/bash
  2. #########################################################################
  3. #
  4. # save-esxi-config.sh
  5. #
  6. # Generates and downloads the configuration of a given ESXi host
  7. #
  8. # Requires SSH support on the ESXi host
  9. #
  10. # The ESXi hostname must be resolvable; may work with IP addresses but
  11. # has not been tested with them.
  12. #
  13. #########################################################################
  14.  
  15. # Name of ESXi host - edit to suit your system, or make into a command-line parameter
  16. VM_HOST="felix.ncs"
  17.  
  18. # Directory where we download the configuration file, edit as needed  
  19. VM_DEST_DIR="/root/work"
  20.  
  21. # Generate the ESXi configuration file and extract the URL we will use to download it from
  22. # the host. Note that we have to replace the '*' in the URL with the hostname
  23.  
  24. echo "Generating configuration file on ESXi host $VM_HOST"
  25. VM_CONFIG_URL=$(ssh root@${VM_HOST} vim-cmd hostsvc/firmware/backup_config | awk '{print $7}' | sed -e "s/*/${VM_HOST}/")
  26.  
  27. # Form target filename
  28. VM_DATE=$(date +%Y%m%d%H%M%S)
  29. VM_CONFIG_FILE="$VM_DEST_DIR"/"$VM_HOST"-configBundle-"$VM_DATE".tgz
  30.  
  31. echo "Downloading $VM_CONFIG_URL to $VM_CONFIG_FILE"
  32. wget --no-check-certificate --output-document=${VM_CONFIG_FILE} ${VM_CONFIG_URL}
Add Comment
Please, Sign In to add comment