Home VCAP-DCA 5 Using VIFS for Datastore File Management

Using VIFS for Datastore File Management

by admin

The VIFS tool, available on vMA or vCLI, allows you to perform remote file management operations on ESXi hosts. I’ve written previously about using the vMA to manage hosts and virtual machines, as part of covering the VCAP5-DCA objectives, however I didn’t cover use of the VIFS tool. This post will look at some of the common tasks you can carry out with VIFS.

For convenience, in the examples here I will be using my vMA with FastPass configured for the ESXi host so that I don’t have to authenticate each time I run the command. You can read about configuring fastpath here, or alternatively VIFS allows you to specify authentication credentials when executing a command.

Listing a ESXi Host’s Datastores and Datastore Files with VIFS

To list the available datastores on a host you can run:

vi-admin@vmlab:~[esxi1.vmlab.loc]> vifs --listds

Content Listing
---------------

ESXi1-Local
Local-SWAP
SAN-VMFS-01
SAN-VMFS-02
SAN-VMFS-03

To list the files in the root of a given datastore, you can run:

vi-admin@vmlab:~[esxi1.vmlab.loc]> vifs --dir '[SAN-VMFS-01]'

Content Listing
---------------

TestVM01/
TestVM02/
TestVM06/
TestVM06-3252334c.vswp
TestVM07/
TestVM08/
esx-tools-for-esxi-9.7.0-0.0.00000.i386.vib
output.csv
sysSwap-hls-5220efd6-867f-dea8-26bf-000c293cc34e.swp
test/
vmx-TestVM06-844247884-1.vswp

Or to list the contents of a specific directory:

vi-admin@vmlab:~[esxi1.vmlab.loc]> vifs --dir '[SAN-VMFS-01] /TestVM01/'

Content Listing
---------------

TestVM01-flat.vmdk
TestVM01.nvram
TestVM01.vmdk
TestVM01.vmsd
TestVM01.vmx
TestVM01.vmxf
vmware-15.log
vmware-16.log
vmware-17.log
vmware-18.log
vmware-19.log
vmware-20.log
vmware.log

You can also use vifs to view some of the host’s configuration files, specifically those available through the https://hostname/host url. To do so:

vi-admin@vmlab:~[esxi1.vmlab.loc]> vifs --dir /host

Content Listing
---------------

auth.log
configRP.log
dhclient.log
esx.conf
esxupdate.log
fdm.log
hostAgentConfig.xml
hostd.log
hostprofiletrace.log
hosts
lacp.log
license.cfg
motd
openwsman.conf
pam.d/passwd

Copying and Moving Files using VIFS

You can copy a file using the following command, specifying the source and destination paths and filenames:

vi-admin@vmlab:~[esxi1.vmlab.loc]> vifs --copy '[SAN-VMFS-01] /TestVM01/vmware.log' '[SAN-VMFS-01] /TestVM01/testlog.log'
Copied file from [SAN-VMFS-01] /TestVM01/vmware.log to [SAN-VMFS-01] /TestVM01/testlog.log successfully.

The move command uses similar syntax:

vi-admin@vmlab:~[esxi1.vmlab.loc]> vifs --move '[SAN-VMFS-01] /TestVM01/testlog.log' '[SAN-VMFS-03] /testlog.log'
Moved file from [SAN-VMFS-01] /TestVM01/testlog.log to [SAN-VMFS-03] /testlog.log successfully.

We can check the file is in the new location by running:

vi-admin@vmlab:~[esxi1.vmlab.loc]> vifs --dir '[SAN-VMFS-03]'

Content Listing
---------------

XP1/
XP2/
XP3/
testlog.log

Uploading and Downloading files using VIFS

Upload and downloading is handled through http get and put commands. To download a file from a host:

vi-admin@vmlab:~[esxi1.vmlab.loc]> vifs --get '[SAN-VMFS-03] /testlog.log' testlog.log
Downloaded file to testlog.log successfully.

To upload a file:

vi-admin@vmlab:~[esxi1.vmlab.loc]> vifs --put testfile '[SAN-VMFS-03] /testlog.log'
Uploaded file testfile to /testlog.log successfully.

To confirm the file has uploaded, use the –dir switch:

vi-admin@vmlab:~[esxi1.vmlab.loc]> vifs --dir '[SAN-VMFS-03]'

Content Listing
---------------

XP1/
XP2/
XP3/
testlog.log

Removing Files and Folders with VIFS

The final thing I want to cover here is how to remove files and directories using vifs. To remove a file:

vi-admin@vmlab:~[esxi1.vmlab.loc]> vifs --rm '[SAN-VMFS-03] /testlog2'
Remove '/testlog2'? (y/n) : y
Deleted file '[SAN-VMFS-03] /testlog2' successfully.

The command to remove a directory is similar, with –rm being replaced with –rmdir.

Useful Links and Resources

https://pubs.vmware.com/vsphere-50/index.jsp?topic=%2Fcom.vmware.vcli.examples.doc_50%2Fcli_manage_files.5.8.html

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More