VMware Cloud Community
impranayk
Enthusiast
Enthusiast
Jump to solution

Script for DV Switch Backup of Multiple vCenter Servers

I am looking to schedule a backup of all dvswitch from multiple vcenter servers. I am using below script, what else can be added here to to mitigate below points?

1) All vcenter should run from single schedule job

1) Output should have contained vCenter name in starting_portgroup name

2) Schedule the task for daily run at particular time

3) Send an email confirmation after completion

LucD​ - Your help required.

___________

$vcenter = “vc1", "vc2", "vc3"

$vcenteruser = “domain\user“

$vcenterpw = “password“

#

$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:\output\$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"

}

}

-------------------------------------------------------------------------
Follow me @ www.vmwareinsight.com
Please consider marking this answer "correct" or "helpful" if you found it useful

Pranay Jha | Blog: http://vmwareinsight.com
vExpert 2016/2017, VCAP5-DCD/DCA, VCP5-DCV, VCA-Cloud, VCE-CIA, MCSE, MCITP
Tags (1)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I would that like this

$vcenter = “vc1", "vc2", "vc3"

$vcenteruser = “domain\user“

$vcenterpw = “password“


#

$date = Get-Date -UFormat %Y-%m-%d

#

# End of script parameter section

#—————————————— #

#

# Connect to vCenter Server

Connect-VIServer $vcenter -User $vcenteruser -Password $vcenterpw -PipelineVariable vc |

  ForEach-Object -Process {

  #

  # Get the vNetwork Distributed switches

  Get-VDSwitch -Server $vc -PipelineVariable vds |

  ForEach-Object -Process {

  #

  # Perform the backups

  #

  # Backup each vNetwork Distributed Switch not including the port groups

   $sVDSNoPG = @{

  VDSwicth = $vds

  Withoutportgroups = $true

  Description = "Backup of $($vds.Name) without port groups"

  Destination = "c:\vSphere\$($vc.Name)-$($vds.Name).without_portgroups.$date.zip"

  Server = $vc

  }

  Export-VDSwitch $sVDSNoPG

  #

  # Backup each vNetwork Distributed Switch including the port groups


   $sVDS = @{

  VDSwicth = $switch

  Description = "Backup of $($vds.Name) with port groups"

  Destination = "c:\output\$($vc.Name)-$($vds.Name).with_portgroups.$date.zip"

  Server = $vc

  }

  Export-VDSwitch @sVDS

  #

  # Backup each port group individually

  Get-VDPortgroup -VDSwitch $vds -PipelineVariable pg |

  ForEach-Object -Process {

   $sVDSPG = @{

  VDPortGroup = $pg

  Description = "Backup of port group $($pg.name)"

  Destination = "c:\vSphere\$($vc.Name)-$($vds.Name)-$($pg.name).portgroup.$date.zip"

  Server = $vc

  }

  Export-VDPortGroup @$sVDSPG

  }

  }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

6 Replies
LucD
Leadership
Leadership
Jump to solution

Do you intend to schedule this via the Task Scheduler on a Windows box?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
impranayk
Enthusiast
Enthusiast
Jump to solution

Yes, on windows box.

-------------------------------------------------------------------------
Follow me @ www.vmwareinsight.com
Please consider marking this answer "correct" or "helpful" if you found it useful

Pranay Jha | Blog: http://vmwareinsight.com
vExpert 2016/2017, VCAP5-DCD/DCA, VCP5-DCV, VCA-Cloud, VCE-CIA, MCSE, MCITP
0 Kudos
impranayk
Enthusiast
Enthusiast
Jump to solution

Any inputs on this LucD​ ?

-------------------------------------------------------------------------
Follow me @ www.vmwareinsight.com
Please consider marking this answer "correct" or "helpful" if you found it useful

Pranay Jha | Blog: http://vmwareinsight.com
vExpert 2016/2017, VCAP5-DCD/DCA, VCP5-DCV, VCA-Cloud, VCE-CIA, MCSE, MCITP
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sorry that I had dinner :smileygrin:

What do you mean by point 2)?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
impranayk
Enthusiast
Enthusiast
Jump to solution

When I have exporting report, it is fetching out correctly however I am looking for output file to be export with name of (vcenter+portgroup+so_on.zip). What shall I add in below strings?

++++++++++++++++++++++++++++

# Backup each vNetwork Distributed Switch not including the port groups

export-vdswitch $switch -Withoutportgroups -Description "Backup of $switch without port groups" -Destination "c:\output\$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:\output\$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:\output\$($_.name).portgroup.$date.zip"

}

}

+++++++++++++++++++++++++++

-------------------------------------------------------------------------
Follow me @ www.vmwareinsight.com
Please consider marking this answer "correct" or "helpful" if you found it useful

Pranay Jha | Blog: http://vmwareinsight.com
vExpert 2016/2017, VCAP5-DCD/DCA, VCP5-DCV, VCA-Cloud, VCE-CIA, MCSE, MCITP
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I would that like this

$vcenter = “vc1", "vc2", "vc3"

$vcenteruser = “domain\user“

$vcenterpw = “password“


#

$date = Get-Date -UFormat %Y-%m-%d

#

# End of script parameter section

#—————————————— #

#

# Connect to vCenter Server

Connect-VIServer $vcenter -User $vcenteruser -Password $vcenterpw -PipelineVariable vc |

  ForEach-Object -Process {

  #

  # Get the vNetwork Distributed switches

  Get-VDSwitch -Server $vc -PipelineVariable vds |

  ForEach-Object -Process {

  #

  # Perform the backups

  #

  # Backup each vNetwork Distributed Switch not including the port groups

   $sVDSNoPG = @{

  VDSwicth = $vds

  Withoutportgroups = $true

  Description = "Backup of $($vds.Name) without port groups"

  Destination = "c:\vSphere\$($vc.Name)-$($vds.Name).without_portgroups.$date.zip"

  Server = $vc

  }

  Export-VDSwitch $sVDSNoPG

  #

  # Backup each vNetwork Distributed Switch including the port groups


   $sVDS = @{

  VDSwicth = $switch

  Description = "Backup of $($vds.Name) with port groups"

  Destination = "c:\output\$($vc.Name)-$($vds.Name).with_portgroups.$date.zip"

  Server = $vc

  }

  Export-VDSwitch @sVDS

  #

  # Backup each port group individually

  Get-VDPortgroup -VDSwitch $vds -PipelineVariable pg |

  ForEach-Object -Process {

   $sVDSPG = @{

  VDPortGroup = $pg

  Description = "Backup of port group $($pg.name)"

  Destination = "c:\vSphere\$($vc.Name)-$($vds.Name)-$($pg.name).portgroup.$date.zip"

  Server = $vc

  }

  Export-VDPortGroup @$sVDSPG

  }

  }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference