VMware Cloud Community
megaframe
Contributor
Contributor
Jump to solution

New to ESXi - How do I ftp files from the ESXi host?

I have read several threads on configuring FTP for other machines to connect to the ESXi server. But I need to FTP my backup files (created with the ghettoVCB.sh) to our Lacie enthernet disk. The ethernet disk is embedded XP that allows FTP connections to it.

Can someone tell me how to FTP from the ESXi machine?

Thanks!

Charles

0 Kudos
23 Replies
bjkamp
Contributor
Contributor
Jump to solution

New and improved script, it will backup all VM's that will match.

I have attached it as a file as I don't seem to get it properly displayed here.

Tested it and works on my VM.

Instead of for $i in $ALLFILES you could use tar if you have a really fast processor AND sufficient local disk space on the vm machine you could do something like this:

LOCALBACKUPDIR='/localbackupdir'

TARFILENAME="$VMNAME.tar.gz"

tar -czf $LOCALBACKUPDIR/$TARFILENAME $VMLOCATE/

ftpput -u $BACKUPUSER -p $BACKUPPW $BACKUPHOST $BACKUPDIR/$VMNAME/$TARFILENAME $LOCALBACKUPDIR/$TARFILENAME

This will put all files in a tar.gz file and compress (usually compresses very well). Please note that on slower machines (CPU or disk) compressing speed is slower then just copying files over the network (if you have Gbit networks anyway).

0 Kudos
bjkamp
Contributor
Contributor
Jump to solution

I've attached the script in the post as a file in my previous post (vmbackup.sh), new version which does a backup from all machines that match using grep -i (not case sensitive).Just a bit more explanation on the script:

So you can use grep regular expressions (change the line to grep -E -i for advanced regular expressions).

It does the grep on the output of the "vim-cmd /vmsvc/getallvms" command which gives an output like this:

Vmid Name File Guest OS Version Annotation

16 vmname1 \[Datastore-Local-1\] XYZSrv1/XYZSrv1.vmx winLonghorn64Guest vmx-07

32 vmname2 \[Datastore-Local-1\] Xconsole-1/Xconsole-1.vmx winXPProGuest vmx-07

This means that you can also backup all vm's on a specific datastore by using for example:

vmbackup.sh Datastore-Local-1

or all windows systems by using for example:

vmbackup.sh winLonghorn64Guest

It stores all VM ID's and one by one ($j is the VMID) performs the backup to the given server. It also uses the output of "vim-cmd /vmsvc/getallvms" to extract the name of the vm (remember $j is the VM-ID):

VMNAME=`vim-cmd /vmsvc/getallvms | grep -i "^$j " | awk '{ print $2 }'`

Based on the status (powerd on or off) it will shutdown the specific vm (vim-cmd /vmsvc/power.shutdown $j) and wait until the vm is shutdown (remember that the power.shutdown function will return immediately, this is the while ; do ... done). Be aware that this could be a deadlock as when the vmware guest does not shutdown the script will wait forever (working on this, adding a time-out).

The ALLFILES var will hold all files that belong to the vm guest (ALLFILES=`ls -1 $VMLOCATE`) and the for i in $ALLFILES will traverse through all the files (filename is $i) and ftp them to the given location.

If VMSTAT was on (e.g. vm guest was running) the script will start the vm again, if it was not running it will leave it like that Smiley Happy as I guess there is a reason why it was not running.

If there are errors try and put some echo $variable in the script to find out if the correct names etc are displayed. The script is not tested extensively and things that could go wrong are for example spaces in the names of vm guests (I don't know if that is allowed anyway)

varialbes used are:

SERVNAME: The string that is matched against the getallvms command

VMID: Contains all VM ID's that matched the SERVNAME

VMNAME: Contains the name of the VM guest extracted frin getallvms

VMSTAT: Contains the power state (on or off), fetched from power.getstate

VMDATASTORE: contains the absolute path of the datastore, fetched from get.datastore command

VMLOCATE: contains the absolute path to the directory where the vm guest is located

I just noticed in the script that I execute power.getstate twice, the first one can be removed.

Alternative to use tar is given in the previous post. I guess the rest you guys can figure out yourselve Smiley Happy

Have fun

0 Kudos
doepain
Contributor
Contributor
Jump to solution

I know that you can use WinSCP to FTP to the ESXi file system and copy files from, also using Unix Services on Windows you can establish and NFS mount point which you could then access from the ESXi server.

I use ghettoVCB to drop all of my backups in and NFS mount point which is on a Windows Server 2003 server that is running "Unix Serives for Windows. THis has worked well for us, and fairly simple to implement.

Senior Hosting Engineer

ModusLink Open Channel Solutions, Inc.

Senior Hosting Engineer ModusLink Open Channel Solutions, Inc.
0 Kudos
serez
Contributor
Contributor
Jump to solution

thanks for your script. at least i have an alternative to back up those VMs to ftp server instead of mounting nfs to datastore.

by the way then if all the VMs were already backup, how about to restore it? Currently i planned to test VM backup from ESXi 4.0 to WD Share Space via ftp. (just for testing purpose)

0 Kudos