Article 5FH3G finalising vmware esxi backup script

finalising vmware esxi backup script

by
robertkwild
from LinuxQuestions.org on (#5FH3G)
hi all,

making a script to backup my centos 7 vms on vmware esxi

just want to know your thoughts on it and what you think

i have tested it and it works

Code:#!/bin/sh

allvms=/scripts/allvms.txt
backvms=/scripts/backvms.txt
vmdk=/scripts/vmdk.txt
source=/vmfs/volumes/datastore1
dest=/vmfs/volumes/datastore1/backup
date=$(date +%d-%m-%y)

vim-cmd vmsvc/getallvms | awk '{ print $1 }' | awk '(NR>1)' > $allvms

while IFS= read -r line; do

vim-cmd vmsvc/get.summary $line | grep 'name' | awk '{print $3}' | grep -qw 'centos7'

if [ $? -eq 0 ]; then

sed -i "/$line/d" $allvms

fi

vim-cmd vmsvc/power.getstate $line | grep -q 'Powered off'

if [ $? -eq 0 ]; then

sed -i "/$line/d" $allvms

fi

done < $allvms

cp -f $allvms $backvms

while IFS= read -r line2; do

name=$(vim-cmd vmsvc/get.summary $line2 | grep 'name' | awk '{print $3}' | sed 's/^[[:punct:]]//g' | sed 's/[[:punct:]]$//g' | sed 's/[[:punct:]]$//g')

mkdir -p $dest/$date/$name

cp -f $source/$name/$name.vmx $dest/$date/$name/$name.vmx

vim-cmd /vmsvc/snapshot.removeall $line2

grep -w 'vmdk' $source/$name/$name.vmx | awk '{print $3}' | sed 's/^[[:punct:]]//g' | sed 's/[[:punct:]]$//g' | sed 's/[[:punct:]]$//g' > $vmdk

vim-cmd /vmsvc/snapshot.create $line2 $name-ss $name-ss 0 1

while IFS= read -r line3; do

vmkfstools -i $source/$name/$line3 $dest/$date/$name/$line3 -d thin

done < $vmdk

vim-cmd /vmsvc/snapshot.removeall $line2

done < $backvmslatest?d=yIl2AUoC8zA latest?i=uKNv3O3lMTg:QS3ZBXDQ-P4:F7zBnMy latest?i=uKNv3O3lMTg:QS3ZBXDQ-P4:V_sGLiP latest?d=qj6IDK7rITs latest?i=uKNv3O3lMTg:QS3ZBXDQ-P4:gIN9vFwuKNv3O3lMTg
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments