One of the coolest new networking feature found in vSphere 5.1 in my opinion is the ability to backup and restore a vSphere Distributed Virtual Switch (VDS) and/or vSphere Distributed Portgroup configurations. As you can imagine, there are a variety of use cases for leveraging such a feature like periodic backups in case of user error, change management, rollback and recovery, configuration audit/management and the list goes on and on.

If you have tried the new VDS backup and restore feature, you will notice it is currently a manual task today using the new vSphere Web Client. However, the VDS backup and restore feature is also available through the vSphere API and this allows you to easily create periodic backups or on-demand backups prior to making changes to your VDS configurations. These APIs can be useful to both vSphere/Network administrators as well as 3rd party partners who are developing network management tools to be able to take backups prior to applying any new configuration changes.

The following two vSphere API methods are available for backup and restore:

To demonstrate these new vSphere APIs, I have written a very simple vSphere SDK for Perl script called which will allows a user to easily backup/export either a VDS and/or DvPortgroup configuration. You will need to ensure that you have a vSphere 5.1 environment along with a VDS that is running version 5.1.

Disclaimer: These scripts are provided for informational/educational purposes only. It should be thoroughly tested before attempting to use in a production environment.

The script supports the following operations:

  • list-vds – List all VDS and DvPortgroups
  • backup-vds – Backup only a VDS
  • backup-dvpg – Backup only a particular DvPortgroup
  • view-backup – View an existing backup file

Here is an example screenshot running the “list-vds” operation:

There are two VDS’s in my lab, let’s go ahead and use the “backup-vds” operation and backup the vds-test. You will need to provide the name of the VDS using –vds option and the backup file name using the –backupname option.

We can see from the screenshot, a temporarily folder is created while the backup is being created which includes some binary data as well as an XML descriptor file that is generated. Once the backup has completed, it will create a zip archive and automatically append a date to the backup file name that was given. If you are interested in the contents of the backup, you can extract the zip file and explore the contents.

You may also want to add a comment along with your backup by using the –note option which can be useful to have a reference to the backup file or even specifying a change control ID. Here is example showing an individual DvPortgroup backup using “backup-dvpg” option and it  requires the name of the VDS using the –vds option, the backup file name using the –backupname option, the name of the DvPorgroup using –dvpg option and the –note option.

Within the backup zip file, there is an XML descriptor file that is generated as mentioned earlier and we can view this XML file which gives us a quick summary of the backup file without extracting the contents by using the “view-backup” option. You will need to specify the –backupname option which should point to the backup file. Let’s now take our backup file and perform a restore using the vSphere Web Client. Depending on whether you are restoring an individual DvPortgroup or VDS, you will need to perform the action on either a Datacenter or VDS object in the inventory navigator of the vSphere Web Client. In this example, I will be restoring an individual DvPortgroup because I accidentally removed the wrong DvPortgroup. Select the appropriate VDS and right click and in the All vCenter Actions, select the “Import Distributed Port Group” option.

Next, you will be prompted to select the backup file to restore from:

The last step is to review the summary before actually performing the restore. Here you will see some basic information which is pulled from the XML descriptor file and if you happen to have a comment using the –note option, then you should see it in the Notes field. Once you are ready to proceed, go ahead and click next.

To take this a step further, you can schedule automatic backups periodically using either a cronjob on a Linux system or a Windows scheduled task to backup your VDS configurations. This allows vSphere/Network administrators to easily restore from known backups in case of a miss-configuration or error were to occur without having to manually export the configuration each time using the vSphere Web Client.

Get notification of new blog postings and more by following lamw on Twitter:  @lamw