VMware vSphere

 View Only
Expand all | Collapse all

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

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

    Posted Sep 14, 2009 02:42 PM

    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



  • 2.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Sep 14, 2009 02:48 PM

    Did you use a local datastore or an NFS datastore? If you used local look at setting up an NFS datastore. You then have many options for moving / copying your data.

    There are directions etc for adding ftp to ESXi on vm-help.com but I would suggest that the more you add as services to the ESXi host the more chance you have of making the host unstable.



  • 3.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Sep 14, 2009 03:06 PM

    I used the ghettoVCB sh to make a copy of the VM files locally. Unfortunately the Lacie disk device does not support NFS. So I am trying to FTP the files to the Lacie disk. I looked at the vm-help.com site and I must be missing something because I don't see and information on using FTP from the esxi console.



  • 4.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Sep 14, 2009 02:57 PM

    You would have to enable the hidden console to use the builtin ftp client. Have a look at this link.

    http://professionalvmware.com/2009/05/unsupported-console-and-ssh-on-esxi-4/

    If you found this or any other answer useful please consider the use of the Helpful or correct buttons to award points



  • 5.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Sep 14, 2009 03:08 PM

    I have enabled the hidden console. I can't find any info on the "builtin ftp client" you mentioned.



  • 6.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Sep 14, 2009 03:25 PM

    Once you have enabled the ssh console on the ESXi server you can use fastscp or winscp to secure ftp in to your ESXi host and grab your files.

    Tom



  • 7.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Sep 14, 2009 03:30 PM

    Right! but I am trying to FTP them from the esxi host to the Lacie disk. This way I can script the transfer to happen via scheduled job. So I really need outgoing FTP is what I trying to say I suppose. Sorry if this wasnt clear.



  • 8.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Sep 14, 2009 03:33 PM

    I do not believe there are any FTP binaries on the ESXi host. Your only option would be to ftp to the host from your desktop, grab the files, then from your desktop put them on your Lacie.



  • 9.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Sep 14, 2009 03:35 PM

    Is there anyway to install FTP binaries to the ESXi host?



  • 10.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Sep 14, 2009 03:37 PM

    Not that I'm aware of.



  • 11.  RE: New to ESXi - How do I ftp files from the ESXi host?
    Best Answer

    Broadcom Employee
    Posted Sep 14, 2009 04:00 PM

    Not sure about ESXi 3.5, but on ESXi 4.0 there is an FTP client,l as mentioned you need to get into the unsupported busybox console:

    ~ # vmware -v
    VMware ESXi 4.0.0 build-171294
    

    ftpget

    ~ # ftpget
    BusyBox v1.9.1-VMware-visor-654 (2008-12-17 10:01:32 PST) multi-call binary
    
    Usage: ftpget [options] remote-host local-file remote-file
    
    Retrieve a remote file via FTP
    
    Options:
            -c,--continue   Continue previous transfer
            -v,--verbose    Verbose
            -u,--username   Username
            -p,--password   Password
            -P,--port       Port number
    

    ftpput

    ~ # ftpput
    BusyBox v1.9.1-VMware-visor-654 (2008-12-17 10:01:32 PST) multi-call binary
    
    Usage: ftpput [options] remote-host remote-file local-file
    
    Store a local file on a remote machine via FTP
    
    Options:
            -v,--verbose    Verbose
            -u,--username   Username
            -p,--password   Password
            -P,--port       Port number
    
    
    

    =========================================================================

    William Lam

    VMware vExpert 2009

    VMware ESX/ESXi scripts and resources at:

    VMware Code Central - Scripts/Sample code for Developers and Administrators

    VMware Developer Comuunity

    Twitter: @lamw

    If you find this information useful, please award points for "correct" or "helpful".



  • 12.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Sep 14, 2009 04:10 PM

    Wow! that's it!

    works great.

    Thanks sooo much.

    Charles



  • 13.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Sep 14, 2009 04:27 PM

    Wow, I learned something new!



  • 14.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Sep 14, 2009 05:48 PM

    Thanks Lam!!


    Maish

    Virtualization Architect & Systems Administrator



  • 15.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Oct 24, 2009 09:06 PM

    Here is a script that may be helpful. it uses the output of vim-cmd /vmsvc/getallvms, the parameter you provide will be matches against this output. Be sure you setup the backup directory with the proper access and directory names that match the vmname (2nd field in the getallvms output) as data will be stored there. The script will stop all running VMs that will be backed up and start them again (if they where running in the first place). It will not start VMs that where not running.

    Sorry that the indents are not copied in correctly, had to lose the comments as well as the posting does funny things with it:

    #!/bin/sh

    VERSION=1.1

    if ; then

    echo "Usage: $0 vmname"

    exit 1

    fi

    SERVNAME=$1

    BACKUPHOST=<hostname or ip>

    BACKUPUSER=<vmbackup_ftp_user>

    BACKUPPW='password'

    BACKUPDIR='/vmbackup'

    VMID=`vim-cmd /vmsvc/getallvms | grep -v "^Vmid" | grep "$SERVNAME" | awk '{ print $1 }'`

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

    VMSTAT=`vim-cmd /vmsvc/power.getstate $j | grep Powered | awk '{ print $2 }'`

    VMDATASTORE=`vim-cmd /vmsvc/get.datastores $j | grep url | awk '{ print $2 }'`

    VMLOCATE="$VMDATASTORE/$VMNAME"

    echo "Location: $VMLOCATE"

    echo "Name : $VMNAME"

    ALLFILES=`ls -1 $VMLOCATE`

    VMSTAT=`vim-cmd /vmsvc/power.getstate $j | grep Powered | awk '{ print $2 }'`

    if ; then

    echo "Server $VMNAME with VMID $j is already powered off"

    else

    echo "Powering off server $VMNAME with ID $j"

    vim-cmd /vmsvc/power.shutdown $j

    VMSTAT=on

    echo "Checking status (now $VMSTAT)"

    while ; do

    echo wait for $VMNAME to shutdown..

    sleep 10

    VMSTAT=`vim-cmd /vmsvc/power.getstate $j | grep Powered | awk '{ print $2 }'`

    done

    VMSTAT=on

    fi

    for i in $ALLFILES; do

    echo backup $VMLOCATE/$i to $BACKUPDIR/$VMNAME/$i on $BACKUPHOST

    ftpput -u $BACKUPUSER -p $BACKUPPW $BACKUPHOST $BACKUPDIR/$VMNAME/$i $VMLOCATE/$i

    done

    if ; then

    vim-cmd /vmsvc/power.on $j

    fi

    done



  • 16.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Oct 24, 2009 09:09 PM

    You should add this to a new post so it isn't lost.



  • 17.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Oct 24, 2009 09:16 PM

    I am new to this, so where would I do that?



  • 18.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Oct 24, 2009 09:26 PM

    There are several places you could post it. Make a new post in this forum. Back forum, developer forum?? have a look through.



  • 19.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Nov 11, 2009 02:43 PM

    Hello, nice script you made.

    I tried it on my ESXi (VSphere) but i can´t get it to work.

    Just typed the Vm-machinename after the script.

    -


    -


    /bin # sh backup.sh VmTestBackup

    Insufficient arguments.

    Insufficient arguments.

    Location: /

    Name :

    Insufficient arguments.

    Powering off server with ID

    Insufficient arguments.

    Usage: power.shutdown vmid

    Shutdown the guest OS

    Checking status (now on)

    wait for to shutdown..

    Insufficient arguments.



  • 20.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Nov 11, 2009 05:07 PM

    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 :smileyhappy: 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 :smileyhappy:

    Have fun



  • 21.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Nov 11, 2009 03:14 PM

    You can wrap your script in tags to make the script readable.

    A link to the forum markup language.



  • 22.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Nov 11, 2009 03:48 PM

    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).



  • 23.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Nov 03, 2010 02:10 AM

    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)



  • 24.  RE: New to ESXi - How do I ftp files from the ESXi host?

    Posted Feb 22, 2010 04:03 PM

    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.