«

»

Backup vSphere vNetwork Distributed Switches using PowerCLI

A few weeks ago a customer asked me how to automate the export of the vSphere vNetwork Distributed Switches (VDS) configuration. Their existing routine included to make a manual export of the VDS configuration whenever a VDS change was implemented including adding or removing a VDS port group.
In the vSphere Web Client you can easily export the configuration per VDS by right-click the VDS and select “All vCenter Actions” and “Export Configuration”
Screen Shot 2013-10-29 at 20.58.51

When performing a VDS backup you can select if you want to include the VDS port groups or not.
Screen Shot 2013-10-29 at 21.07.11

There is also an option to perform a configuration export of an individual VDS port group by right-click the VDS port group and select “All vCenter Actions” and “Export Configuration”.

Below you’ll find the PowerCLI script i implemented in my customers environment that is running vSphere 5.5.

Change the following parameters in the below script to match your environment:

  • $vcenter = “vc01.vcdx56.local“
  • $vcenteruser = “vcdx56\magnus“
  • $vcenterpw = “not secret“
  • Backup each vNetwork Distributed Switch not including the port groups directory = c:\vSphere\$switch.without_portgroups.$date.zip”
  • Backup each vNetwork Distributed Switch including the port groups directory = “c:\vSphere\$switch.with_portgroups.$date.zip”
  • Backup each port group individually directory = “c:\vSphere\$($_.name).portgroup.$date.zip”

Change the red marked text in the script to your required values.

# Script to backup the vNetwork Distributed Switches (VDS) including their port groups
# The script will generate:
# * 2 files per VDS, 1 including the VDS configuration without the port groups and 1 including the VDS configuration and the VDS port groups
# * 1 file per VDS port group
#
# The script will run once a day meaning no need to use the force option to overwrite any existing backups since the date is included in the backup file names.
#
# Version 1.0 Magnus Andersson RTS
#————————————————
# Start of script parameters section
#
# vCenter Server configuration
$vcenter = “vc-demo01.vcdx56.local“
$vcenteruser = “vcdx56\magnus“
$vcenterpw = “not secret“
#
$date=get-date -uformat %Y-%m-%d
#
# End of script parameter section
#—————————————— #
#
# Connect to vCenter Server
connect-viserver $vcenter -User $vcenteruser -Password $vcenterpw
#
# Get the vNetwork Distributed switches
$switches=get-vdswitch
#
# Perform the backups
foreach ($switch in $switches)
{
#
# Backup each vNetwork Distributed Switch not including the port groups
export-vdswitch $switch -Withoutportgroups -Description "Backup of $switch without port groups" -Destination "c:\vSphere\$switch.without_portgroups.$date.zip"
#
# Backup each vNetwork Distributed Switch including the port groups
export-vdswitch $switch -Description "Backup of $switch with port groups" -Destination "c:\vSphere\$switch.with_portgroups.$date.zip"
#
# Backup each port group individually
get-vdswitch $switch | Get-VDPortgroup | foreach { export-vdportgroup -vdportgroup $_ -Description "Backup of port group $($_.name)" -destination "c:\vSphere\$($_.name).portgroup.$date.zip"
}
}

To schedule the PowerCLI script on a Windows machine, see my Schedule PowerCLI script in Wndows task scheduler blog post.

To restore the VDS you right-click the VDS and select “All vCenter Actions” and “Restore Configuration”.
Screen Shot 2013-10-29 at 21.20.43

When performing a VDS restore you got two options, same as when exporting the VDS configuration, either restore the VDS with the port groups included or not.
Screen Shot 2013-10-29 at 21.20.58

Restore the VDS port group by right-click the VDS port group and select “All vCenter Actions” and “Restore Configuration”.

You can also use PowerCLI to restore the VDS and the VDS port group if you want.

1 pings

Comments have been disabled.