One of the great new features introduced in vSphere 5.1 was the ability to export and import the configuration of your vSphere Distributed Switch (VDS) and port groups to a file.
This gives you a quick restore method in case of issues or misconfigurations and also allows you to copy the entire VDS or port group configuration to a new VDS. This feature is detailed by this VMware KB and is available via the vSphere Web Client, below you can see how we would do this via the web client:
Exporting the configuration with PowerCLI
With the introduction of the VDS cmdlets in PowerCLI 5.1 R2 we can also automate this process using the Export-VDSwitch and
Export-VDPortGroup cmdlets, the following examples show how we might do this:
We can also choose to backup each port group configuration individually, the following example shows how to do this for a single port group:
But what if we wanted to back up all our port groups for that VDS individually, we can easily achieve this with the following:
The code used for this example is as follows:
Get-VDSwitch -Name VDS-01 | Get-VDPortgroup | Foreach {
Export-VDPortGroup -VDPortGroup $_ -Description “Backup of $($_.Name) PG” -Destination “C:\Backups\$($_.Name).Zip”
}
Importing the configuration with PowerCLI
Now we have the exported configuration the next step is to look at how we could import these files again back into vCenter if an issue happened. Of course each file could be imported from the vSphere web client individually but this post will show you how to do this with PowerCLI.
The code used in this example is as follows:
Get-ChildItem “C:\Backups\PG” | Foreach {
New-VDPortgroup -VDSwitch NewVDS -Name “New$($_.BaseName)” -BackupPath $_.FullName
}
As you can see from the below, we now have two DVS which have the same configuration:
Conclusion
Backing up the VDS and port group configuration can not only give you a backup in case of emergency but can also be useful for creating new switches with the same configuration, one use case for example is moving the VDS configuration between vCenters, like test & dev to Production. The above examples show you how to automate this process with PowerCLI.
Don’t forget, the backup script could easily be scheduled to export on a weekly basis so that you have the latest configuration and multiple points in time to go back to.
Check out other new features in PowerCLI 5.1 R2 here
Hi Alan,
Thanks for the write-up!
I thought moving the VDS configuration between vCenters is not suppoted or does not work?
Cannot use the vDS Import function to migrate to new vCenter Server (2045468)
http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2045468
Wow, that’s news to me, thanks for bringing that to my attention, hopefully this will be fixed in a future version.
Also after further reading of the KB article it looks like this is a specific configuration that does not work, in general it does work.
Thanks Alan,
That’s totaly what I need.
VDS and port group configuration can not only give you a backup in case of emergency but can also be useful for creating new switches with the same configuration, one use case for example is moving the VDS configuration between vCenters, like test & dev to Production.
http://happyeasteri.com/2016/unique-easter-wishes-easter-day-messages-2016-for-boyfriend-girlfriend.html
Can you tell me why when condensing the import into one line like this, would append the name.zip
Get-ChildItem “C:\is\vDSBackup\” | Foreach {New-VDSwitch -Location (get-datacenter “mydc”) -Name “$_.BaseName” -BackupPath $_.FullName}
When i backup multiple dvswitches in same file, does the restore command restores all the dvSwitches