LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS
User Name
Password
CentOS This forum is for the discussion of CentOS Linux. Note: This forum does not have any official participation.

Notices


Reply
  Search this Thread
Old 03-18-2021, 11:41 AM   #1
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Rep: Reputation: Disabled
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
 
Old 03-18-2021, 02:29 PM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,677

Rep: Reputation: Disabled
Answered at f.c.o
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Vmware ESXi recover .img backup timahe Linux - Virtualization and Cloud 3 10-31-2017 08:50 PM
LXer: Upgrade/Migrate VMware ESX/ESXi 4.x To ESXi 5.0 LXer Syndicated Linux News 0 09-11-2011 03:10 PM
RAID card for vmware esxi, and some other esxi questions JustinHoMi Linux - Enterprise 1 06-04-2010 03:57 PM
[SOLVED] Screen Resolution reverts when not root - CentOS guest on VMWare ESXi Sean1e Linux - Software 2 10-22-2008 11:54 AM
LXer: VMware to give away ESXi for free LXer Syndicated Linux News 0 07-25-2008 12:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS

All times are GMT -5. The time now is 02:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration