LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   CentOS (https://www.linuxquestions.org/questions/centos-111/)
-   -   finalising vmware esxi backup script (https://www.linuxquestions.org/questions/centos-111/finalising-vmware-esxi-backup-script-4175692254/)

robertkwild 03-18-2021 11:41 AM

finalising vmware esxi backup script
 
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 < $backvms


shruggy 03-18-2021 02:29 PM

Answered at f.c.o


All times are GMT -5. The time now is 10:49 PM.