ncftp & ghettovcb Working Together

I’m a bit chuffed with my scripting efforts in ESXi, so I thought I would share, I hope someone else might find this useful.

To give a bit of background, I run a VMWare Hypervisor ESXi server, it’s only a free license version single host, so most of the backup software doesn’t work that you can buy. But I have found an awesome script called ghettovcb that utilizes the snapshot and VM console commands to make VM running (and off) backups of my guest VMs. But obviously I want to get this data off the host, this is where ncftp comes in.

Now I found the code I needed to write to get all my machines backed up and transferred was crazy, and to get these two to work together.

Writing this, I’ve just thought I should code up all the commands into a single script file, maybe that’ll be next. But the below allows you to state a single VM’s backup folder, or a list with the “-f textfilewithvmsperline” command, which I’ve been able to use the same list from ghettovcb, so I know, if it’s backed up, it’ll be uploaded also.

Well, shout out if this has helped you.

#!/bin/sh

#Where are a few things in your file structure
NCFTP="/vmfs/volumes/5TB-RAID5EE/ncftp/bin/ncftpput"
FTPHOST="192.168.100.200"
FTPUSER="Username"
FTPPASS="Password"
FTPPATH="Share/Folder"
BACKUPS="/vmfs/volumes/5TB-RAID0/backups"
SHORTNAMEFORECHO="5TB-RAID0/backups"
#The rest below shouldn't need changing

#Turn the firewall off, got this permanently set though it's hand to keep it in mind
#esxcli network firewall set --enabled false

#Check a VM name has been given, and advise if not.
if [ "$1" == "" ]; then
echo "Please enter the name of the VM you wish to upload..."
exit 1
else
# Check if a -f command has been issued, for a file list upload
if [ "$1" == "-f" ]; then
echo "Flag issued for VMs file list to upload, load these and process.."
UPLOAD=`cat $2`
#echo "$UPLOAD" && exit 0 #Debugging line to see the list before it is run, this is normally commented out
else
echo "Single named VM listed to upload, processing.."
UPLOAD=$1
fi
fi

#Okay lets get down to business and process this list or single VM
for I in $UPLOAD; do
#Identify the most recent backup files for the listed VM
echo "You've stated $I, looking up the most recent backup."
LASTBACKUP=`ls -Art $BACKUPS/$I | tail -n 1`

#Check if a location has been found.
if [ "$LASTBACKUP" == "" ]; then
echo "Results of the search have failed, please check the listed name and try again."
else
echo "The last backup location is $SHORTNAMEFORECHO/$I/$LASTBACKUP"
# Use this location and upload it to Icharus NAS
echo "Beginning upload of folder"
$NCFTP -u$FTPUSER -p$FTPPASS -E -R $FTPHOST $FTPPATH $BACKUPS/$I/$LASTBACKUP
fi
done

#Should be all done, suggesting so...
echo "Complete"

#Turn the Firewall back on
#esxcli network firewall set --enable true

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.