Configuring minimum vCenter privileges for an Avamar Backup Service Account

Posted by vele1655 | Posted in Automation, Avamar, Backup | Posted on 02-04-2013

Tags:

0

This comes up in most deployments when minimum levels of access is desired when creating any type of vCenter service accounts.  Typically the configuration is manually done, but is a good example of how useful PowerCLI can be as it is a much better answer for achieving consistency and integrity in a process. 

There is a script below that leverages a pre-built configuration including the necessary items to achieve what is currently documented as minimum access needs for Avamar to perform its normal operations.  We leverage PowerCLI and its built in basic cmdlets that allow you to easily perform the necessary operations.  See the following screenshot where we are showing the VIRole and VIPrivilege cmdlets. 

image

 

If you want to view the roles that are already created you can get there from the vCenter home screen, following the below screenshots.

image

 

image

 

Below are the requirements based on development environment and testing.  Keep in mind, that the script developed should work outside of these versions but the privileges might have been renamed depending on your versions.  There is a simple hashtable in the script that can be updated to accommodate any PrivilegeGroupId and Privilege Name. 

  • Powershell v2+
  • PowerCLI 5.1
  • vCenter 5.1
  • Download the script here

 

Onwards!

 

The script is very easy to run.   Simply download it, and execute it with the following line.  There are two expectations.

  • You have connected to a vCenter server already (Connect-VIServer), (Set-ExecutionPolicy is unrestricted or bypass)
  • You have created a new role (New-VIRole -name newrolename)
  • ..or you want to run the script against an existing role and ensure it has no more and no less permissions as defined in the script

 

.\UpdateVIRoleBackupServicePrivileges.ps1 -Role (Get-VIRole -Name “Backup Service”)

image

 

That’s it!  You can see the role configured below based on the privileges listed above.

 

image

 

The next step is to Add Permission for this role and a specified User/Group to the correct place in the vCenter Hierarchy.  This can be at the vCenter/Datacenter/Cluster/Host level.  See below screenshots where we are adding the Role and a User/Group at the vCenter level which assigns the “test” user the “Backup Service” role privileges for all things covered under the vCenter instance.

image

 

image

 

image

 

And there you have it!

 

Bonus

In some cases there might be the need to be more granular with what objects the new role is assigned to.  This can cause some complication, so how would you go about reporting on, for example, what datastores a specific user has access to?

Get-Datastore | Select Name,@{n="VIPermission";e={Get-VIPermission -Principal "AWESOMESAUCE\test” -Entity $_}}

image

 

In other cases you may want to automate the addition of the permissions to the proper vCenter object.  Here you can see that we created a new permission set (Role & User specified) and applied it to the vSpecialists datacenter.

New-VIPermission -Role $role -Principal "AWESOMESAUCE\test"  -Entity (Get-Datacenter vSpecialists)

image

 

image

Integrating Avamar VM Image Backup Reporting with VMware vCenter Operations

Posted by vele1655 | Posted in Avamar, vCOps | Posted on 25-02-2013

Tags:

4

Have you ever wondered how your backups affect performance and other things in your environment?  Are you used to manually hunting and pecking for this information?   Shouldn’t an operator know right away that a backup was taking place when troubleshooting or performing root cause analysis after the fact?  If a Virtual Machine or Datastores are underperforming wouldn’t it be nice to know how many backups were occurring during these times and what is affected? 

 

If you’re a VMware customer and are familiar with vCenter Operations Standard+ and utilize EMC Avamar for VM Image based backups these kinds of questions can be answered!  As usual with my stuff, I am providing an unofficial way to perform this integration, but if you find it valuable let VMware and EMC know!

 

First of all, the integration being shown was performed with vCenter Operations 5.6 Standard and above along with Avamar 6.1.

 

The integration that is occurring between Avamar and vCenter Operations is very simple.  We are taking backup events after they have finished and creating “change events” in vCOps for the start and finish of the backup operation.  You can see this from the Operational Events graph below. 

 

We are looking at the Health graph of a specific VM along with its related events.  Here we are hovering over the graph on an ME logo which corresponds to change events for this VM.  Notice mostly there are clustered events two at a time representing start and finish of backup jobs for this VM.  Also notice how the Health (graph) is lower in some cases during these events?  This represents the analytical capabilities of vCOps determining that there are a certain percentage of metrics or KPI’s that are above their “learned” dynamic threshold (DT) for this VM.  This can result from a Virtual Machine’s own metrics that it relies on.  The event is being shown here with the duration of backup and total bytes that were sent after changed blocks (CBT) were deduplicated within the Avamar VMware image proxy VM.

 

 

clip_image001[8]

 

 

Note!  The concept of the VMware image proxy is important for this use case!  Here a similar graph that is showing the workload instead of health for a Virtual Machine.  Notice how there is not extra workload being reported?  Well this makes sense since the VM is not doing anything during backup time, the proxy is!  This can however in certain cases spike since a VM workload may peak since it’s underlying dependent items such as storage may be hitting peak demand.  Anyhow, this offload is how VM image based backups occur with Avamar, but as you can see can cause lower health due to using underlying shared resources (such as storage) and thus increasing response times or reducing capable throughput.

 

 

clip_image002[7]

 

 

So how can we get to the bottom of this?  We showed the Health prior, but let’s now look at the anomalies view.  This summarizes possible reasons for the health being low and is somewhat inverse to the health graph.  Again we see backup events integrated and the anomalies being reported.

 

clip_image003[7]

 

 

Now let’s flip over to see related items such as Datastores that the VM is using.  You can see this easily from the Environment -> Members tab where the Datastores for the VM are listed.

 

clip_image004[7]

 

 

Here we have the same Operational Events view from the VM and are still looking at anomalies.  We start by reviewing the anomalies and selecting a workload badge on the graph on the left side.  You can see here that there is a time when vCOps determined that a Datastore was being limited by Disk IO and thus the demand was at 100% affecting all resources that relied on the Datastore. 

 

 

clip_image005[7]

 

 

Now let’s overlay the change events on the graph.  We can now see that the backup events can be shown to directly relate to the anomalies.  Notice how there are now multiple events being shown?  This view is from the Datastore and it is showing not only events for itself, but also events that occur from all of its children (VMs).  So here we can see an accumulation of backup events all occurring at the same time for different VMs!  This is a good thing of course since we are intentionally doing this.

 

clip_image006[8]

 

 

So you may be asking now, so what?  Don’t do backups?  The point here is to show that we have Avamar and vCenter Operations can be integrated to give an operator the information they need to properly react and plan for these type of events.  In this example we are doing image based VM backups with source based deduplcation from Avamar along with VMware’s changed block tracking (VADP integration).  These features offload and reduce infrastructure utilization during backups.  So what would your environment look like if you’re not taking advantage of CBT and source based dedupe?  You tell me!

 

 

 

So how can I get this integration going?  The integration used here is written in Powershell/.NET.  It is very simple, we consume events from the Avamar Postgres through a .NET provider and post them to the vCOps REST interface as change events.  Below is a basic outline of how I outline the areas that will be covered when it comes to installing and configuring the integration.

 

 

  • Installing the Avamar vCenter Operations Integration
  • Success!  Continue on with Standard Non-Interactive Usage..
  • Standard Interactive Usage
  • More details on Get-VMAvamarActivities

 

 

 

Installing the Avamar vCenter Operations Integration

Now in order to get the integration working there are a few requirements that I must call out.  First, what you can download from this site is not officially supported, take it as an early alpha release technical preview!  Your feedback can help shape future product integration so send it my way!

 

Requirements

 

Integration Points

  • Avamar Postgres Database
    • Review Avamar 6.1 Administration Guide, “Support for third-party reporting tools”
    • Review Avamar 6.1 Administration Guide, Appendix C “MCS and EMC Database Views”
  • Avamar
  • VMware vCenter
  • vCOps 5.6 REST Interface

 

 

The Powershell module contains cmdlets that can leveraged either in a continuous service oriented fashion, or interactively.  In order to make this easier, as part of the install process there is a step to create a login profile that stores authentication information (in a secure form) as well as a shortcut to launch the Avamar vCOps Service.  So let’s get started!

 

Download Powershell Module and Postgres Data Provider

If Powershell and PowerCLI is installed then the first step is to download the Avamar vCOps Powershell module along with proper Postgres .NET data provider assemblies.  The Powershell module can be downloaded from here.  The Postgres module must be downloaded from another place here.  Notice the screenshot below, from the Downloads page, download any of the version 2 ZIPs that match your .NET version.  In my example, since I am using Powershell 3 I downloaded the Npgsql2.0.12.0-bin-ms.net4.0.zip.  I highly suggest you use Powershell v3 to take advantage of Login Profiles.

clip_image007[8]

 

Unzip Downloads and Unblock

Now once downloaded, unzip the Powershell module to a non-network drive and directory of your choice.  This requirement is in place due to DLLs that don’t play nicely when living on network drives.  Limitation can be overcome with some simple hardcoding if you so please.  Unzip the Npgsql file and grab two files, Npgsql.dll and Mono.Security.Dll.  Copy them to the newly created directory with the Powershell module in it.  This is how the files should look in this directory.

clip_image008[7]

 

One more thing here for Powershell v2 users.  The DLLs may need to be Unblocked for security purposes (we do it automatically in v3).  Right click the DLLs individually and press Properties.  Press the Unblock button at the bottom.

 

 

Create Login Profile

With that done, you should be ready to create your first Login Profile which is used to store credential (as a Secure String) and IP/DNS information for each integration point.  This dramatically simplifies things and enhances the security a bit.  Important note! The Secure Strings are .NET based, and are based on keys that are generated per logged in User per Server to the Powershell instance.  Each User that opens Powershell will need to run this command themselves with the credential information or you will need to generate the proper Secure Strings for them with their unique Key (not shown here but possible).  This leverages the ConvertTo-SecureString cmdlet.

 

Ok, now that you’ve got it downloaded and proper files in place the next thing to do is to open a Powershell window.  Change directory to where you unzipped the Powershell module.

 

Run the following command to import the Powershell module.

Dir *.psm1 | Import-Module

 

Now check to ensure you have the necessary cmdlets from this module loaded.  See screenshot below.

Get-Command -Module avamar_vcops

 

And finally you can create the profile if the cmdlets are loaded as seen in the screenshot below.  Take the following command and copy it to notepad and edit the properties in include the proper IP/DNS, Username, and Password of Avamar, vCenter (VIServer) and vCenter Operations.  If you wish to not include vCenter Operations, remove the “vCOps=” line.  This will mean you can only use the script in an interactive form, no posting the backup job events to vCOps but possibly to a destination of your choice.  Also, ensure you include passwords in single quotes (‘) to ensure special characters are preserved.

New-AvamarLoginProfile -Shortcut -Name “profile1″ -LoginProfile  @{

            Avamar=@{server=”ave02″;username=”MCUser”;password=’pass’}

            AvamarDB=@{server=”ave02″;username=”viewuser”;password=’viewpass’}

            VIServer=@{server=”vcenter01″;username=”root”;password=’rootpass’}

            vCOps=@{server=”vcops01″;username=”admin”;password=’pass’}

        } 

 

 

You should see the following output where “Shortcut has been created” is shown at the bottom.  I will explain the shortcut in a second.

 

clip_image009[7]

 

 

 

Test Login with Profile

Now the next step is to test and use the login profile.  But first if you don’t have a PowerCLI window (you followed instructions, but PowerCLI window would work too), you need to load the PSSnapin from the Powershell window.  By not having you open PowerCLI I can ensure that we are not connecting to multiple vCenter instances.  During development I didn’t plan on this, so for now make sure you are only using 1 vCenter at a time per Powershell instance.

Add-PSSnapin vmware.vimautomation.core

 

From the same command prompt enter the following command, edit the “profile1″ name to whatever you specified in the above cmdlet for the -Name parameter.

Connect-AvamarLoginProfile -Name profile1

 

This command will connect to all of the items that were specified in the Login Profile.  If successful, you will see the output as follows without error.  If it is not successful, then it will show errors.  Most likely errors include password or IP/dns problems.  Please refer to Requirements and previous steps if you are encountering errors.

clip_image010[6]

 

 

 

Success!  Continue on with Standard Interactive Usage..

Since we have successfully created and are using a profile now we have everything we need to get the integration working.

 

Start a VM Image Backup

In the case of this demo, I am using the integration in a fresh lab environment with an unused Avamar Virtual Edition node installed.  So I am going to start a backup so I have a backup record to see.

clip_image011[6]

 

 

Get-VMAvamarActivities

There is a semi-advanced cmdlet that we are going to be using in its most basic fashion to correlate Virtual Machines as Avamar VM Clients and their corresponding backups.  Under the covers the cmdlet can be used in a handful of different scenarios that I will cover in the advanced section.  In this case since there are no parameters specified we are returning every backup job for this VM with the following command.

Get-VM wguest-01 | Get-VMAvamarActivities

 

clip_image012[6]

 

It is important to also call out that there is a much more efficient way to get all VMs (for larger environments) and their associated Avamar accounts.  The following command would return all VMs (-getAllVms) and cache all Avamar VM client accounts without individual lookup (-useBulkAvamarVMLookup) and specifies to only pull the last three days of jobs (-Start_Recorded_Date_Time). 

Get-VMAvamarActivities -getAllVms -useBulkAvamarVMLookup -Start_Recorded_Date_Time ((Get-Date).addDays(-3))

 

These are all important parameters for the next part.  We are working towards being able to prepare for Non-Interactive Usage (service) where we continuously update the backup jobs.  In order to do this however, there is one more concept that needs to be covered.

 

Bookmarking (-useBookmark)

In order to track which records have been sent to vCenter Operations, after a successful post if the (-vCOpsPost) parameter is specified , a bookmark entry is created and stored as a AvamarNameorIP.CliXml.  See the following screenshot where the file was created after a successful post.  The (-useBookmark) parameter if specified respects the bookmark as last record seen, and to retrieve only the newer records.  This way we can either run the integration on demand or run it continuously as a service and it keeps track after each individual successful Post per backup job where it left off and can recover from any error (as long as bookmark is there).  Important note:  If you have multiple vCenter’s that are talking to the same Avamar instance, then bookmarking will not work properly.  In the case you care to integrate multiple vCenters with a single Avamar instance and send the data to vCOps (using bookmarking) then create separate directories with the same files in them.  The separate directories will allow each instance of Powershell to maintain its own AvamarNameorIP.CliXml file.  This is possibly not a limitation in a future rev.

 

Bookmarking is required so that we don’t send duplicate data to vCenter Operations.

 

 

clip_image013[6]

 

 

So before running the Non-Interactive mode you have a choice to make.  You can either sync up the entire Avamar VM image job history to vCenter Operations for VMs that currently exist, or you can create a bookmark to begin at a certain point.  The next command gets all of the VMs, and starts from 3 days prior, posts the results to vCenter Operations and creates proper bookmarks.

 

Get-VMAvamarActivities -getAllVms -useBulkAvamarVMLookup -Start_Recorded_Date_Time ((Get-Date).addDays(-3)) -vCOpsPost

 

Or for pulling all backup jobs and creating bookmarks. (This is what is ran continuously in Non-Interactive Usage)

Get-VMAvamarActivities -getAllVms -useBulkAvamarVMLookup -vCOpsPost

 

clip_image014[6]

 

Important Note:  A bookmark will only be created with a successful post of a backup job!  You can create a bookmark manually by specifying the following command and changing the “AddDays” portion from the previous 30 days, to something of your choice.  This will set you up for running this as a service starting at this point, or interactive usage if specifying -(useBookmark) automatically from this point.  Note how we are specifying ToUniversalTime, may not be extremely important, but can be if you are trying to be exact since the Avamar database stores events in UTC.

New-Object -Type psobject -Property @{recorded_date_time=((Get-Date).AddDays(-30)).ToUniversalTime() } | Export-CliXml “$($DefaultAvamarServer.Server).CliXml”

 

Standard Non-Interactive Usage (service)

Open Created Shortcut

With Explorer open the directory that has the Powershell module.  Notice the “Avamar vCOps (profile1)” shortcut that exists.  This was created automatically for you when we created the Login Profile.  This shortcut can be used to launch the non-interactive “service” method of performing the integration.

clip_image015[6]

 

 

Once you double click the shortcut it will launch a Powershell window and title it appropriately for the profile name and Powershell PID.  You can see here that we perform a Login, Backup Job query and post, and Logout.  This sequence is iteratively ran with a 5-minute delay between runs.  A parameter of (-once) can be added to the shortcut in order to only run once and quit.

 

Below you can see the window with a couple of lines that begin with “Posting.”  Since we ran a backup job prior, it is actually posting this information to vCOps now.

 

clip_image016[6]

 

 

Verify Post of Change Event in vCOps

Now you can see that the event actually made it into vCOps by loading the standard vSphere oriented UI and navigating to the VM on the left side.  You can then click on Operations in the top, and Events below it.  Once there a health screen graph will appear, and you can select the Target above the graph in the “Related Events” portion of the graph toolbar.  If necessary you can modify the date range with the calendar button on the tool bar.  You should then see the appropriate change events marked ME (My Event) with the attached descriptions as you saw in the Powershell window above.

 

clip_image017[6]

 

 

 

All Done!  You now have the interactive and non-interactive modes working and are ready to push backup information continuously to vCOps and possibly do some other really cool stuff with Powershell and Avamar!

 

 

 

 

 

 

 

Backup and Restore of VMware vCloud Director Virtual Application Configuration

Posted by vele1655 | Posted in Automation, Avamar, Backup, vCloud Director | Posted on 25-02-2013

Tags:

0

Backing up and recovering vCloud Director is going to be a very popular topic as IT organizations inevitably move from managing their virtual infrastructure to managing Virtual Datacenters supported by VMware’s vCloud Director.

This year you will start to see many vendors release their own vCloud Director protection. What we are going to show here is probably more detailed than most will currently implement from a Virtual Application recovery perspective. This Virtual Application configuration collection and recovery process however is only one small piece of what a full blown vCD backup application should look like.

  • VADP Integrated Backups VM Image Backups
  • Full Backup and Restore of Virtual Application Configuration
  • vCloud Director Hierchial Policy Management
  • Self-Service
    • Backup Policy Management
    • Recovery
  • API
    • REST
    • Framework

There is definitely a natural progression towards all of the features listed above that you will start to see existing backup products take, but most likely no one is quite there yet. Keep in mind what you may really need in the short term for vCD protection product versus a best of breed vSphere backup product. This post may contain relevant stuff to check the “Full Backup and Restore of Virtual Application Configuration” box in the short term.

Let’s continue on though if you’re interested..

Moving to the Software Defined paradigm and extracting logic from physical hardware has a lot of benefits such as portability and agility. But when we define SD.* we also bring in another important aspect– backup and recovery. Here is a simple question you can ask yourself.. If I adopt the SDDC, how can I ensure my SLAs for recovery? If I scripted my way to a SDDC without Automation Software (vCloud Director), how can I capture and recover the state of my VMs or Virtual Applications and their dependencies they have to function? Or put simply, as I take advantage of more SD.* features can I recover them in a repeatable and consistent fashion and ensure minimum RTOs?

In an Automation world controlled by software (like vCloud) this is realistic. First of all, let’s simplify this a little bit when comparing backup strategies between vCloud and vSphere/vCenter. What currently differs in protecting vCloud Director versus vCenter VMs? When protecting vCenter VMs we leverage VADP (vSphere API for Data Protection) to offload Image based backups to proxies and allow for the recovery of Virtual Machines (their Virtual Hardware, and Virtual Disks). This process is still done for vCloud Director protection! However, where we start to differ is that with vCD we accommodate this backup of VMs with vCD configuration that describes how to reconstruct the Virtual Application container– we don’t refer to this as Metadata, but configuration of the Virtual Application. This container is what is needed to allow a Virtual Application to function which includes details such as Software Defined Networking aspects (Firewall, NAT, etc.).

So how do we accomplish this from vCD? Very simply by collecting the raw XML that vCD supplies through its API which defines the exact configuration state of vCD objects. We store this state which can then later be used for reconstruction from scratch or specific pieces. This XML can be stored and used by any language or method to pursue Virtual Application recoveries. The unfortunate thing at the moment though is that there are no vCD API’s for backup and recovery, so expect a different approach from every vendor for protecting vCD in the short term. This means every vendor must implement their own Virtual Application backup and recovery processes– and some won’t do this at all. In reality, an API for vCloud that places the configuration aspects from VApp through VDC, and other items in a consistent state for configuration collection is really needed but not available now. Here is an example of what we are referring to.

clip_image001[4]

So the good news here is that you can leverage this PowerCLI module for backup and recovery against your existing VM Image based protection and recovery methods (possibly Avamar or VDP) to provide vCloud protection in the short term. It is even possible that currently you are using vCD likewise to vCenter (no extra features) and don’t need robust configuration backup and can settle with solely existing vSphere backup methods.

The rest of the post is going to focus on the vCloud Director specific aspects of backup and restore, which again are simply capturing XML in REST calls. There are a lot of PowerCLI/Powershell cmdlets called out below that were specifically developed to augment PowerCLI’s capabilities with vCD. Expect more goodness in the upcoming future!

  • Backup of vCloud Configuration
  • Restore of vCloud Configuration– Virtual Applications and Templates
  • Advanced Restore of vCloud Configuration

Requirements

  • Powershell v3
  • PowerCLI 5.1 R1/R2
  • Download the module here
    • Dir *.psm | Import-Module
    • Connect-CIServer

Backup of vCloud Configuration

Backup-vCD

In order to collect specific or most vCloud Director objects we can use the Backup-vCD cmdlet to in bulk or specifically request recursive requests of vCD XML configuration. By recursive requests, this means we make a request for an object and then make sub-requests for the inidividual editable portions of this objects that can later be sent. The output directory can be dynamic and is specified based on (-outDirectory) parameter. This cmdlet can be run on a schedule to Asynchronously collect and store configuration and can use the previous parameter to create unique namespaces per run.

Backup all available vCD objects

Backup-vCD -QueryType All

Backup a specific Virtual Application’s configuration

Get-CIVApp App-Finance | Backup-vCD -QueryType AdminVApp

Backup a specific Virtual Application Template’s configuration

Get-Org BRS-vLab-Eng | Get-Catalog brs-vlab-gold-catalog | Get-CIVAppTemplate linux-03-gold | Backup-vCD -QueryType AdminVAppTemplate

Export-CIXml

This cmdlet is used under the covers in the previous cmdlet to request the actual vCloud Director object’s XML data.

Get-CIVApp App-Finance | Export-CIXml

Export-CIVAppConfigCollection

In order to properly associate the relevant XML files associated with a Virtual Application we create an aggregate XML container called a Config Collection with this cmdlet. The single file that is generated can then be used for recovery at a later time. This can be considered the complete recoverable identity of a Virtual Application. This command as well can be used Synchronously (with maintence mode on CIVApp) or Asynchronously to collect Config Collections. A system

Backup a specific Virtual Application’s configuration in a CIVApp XML Config Collection

Get-CIVApp App-Finance | Backup-vCD -QueryType AdminVApp | Export-CIVAppConfigCollection

Backup all Virtual Application’s configuration in a CIVApp XML Config Collection. This would be used if there is a dedicated system that is storing the configuration files and backed up via traditional file system protection.

Get-CIVApp | %{ $_ | Backup-vCD -QueryType AdminVApp | Export-CIVAppConfigCollection }

Export-CIVAppTemplateConfigCollection

Same as Export-CIVAppConfigCollection.

Backup a specific Virtual Application Template in a CIVAppTemplate XML Config Collection

Get-Org BRS-vLab-Eng | Get-Catalog brs-vlab-gold-catalog | Get-CIVAppTemplate linux-03-gold | Backup-vCD -QueryType AdminVAppTemplate | Export-CIVAppTemplateConfigCollection

Restore of vCloud Configuration– Virtual Applications and Templates

If you are leveraging any defined method in this PowerCLI module to protect the XML configuration then you are ready to be able to leverage the Restore capabilities that are outlined below. The examples below however, will be focused on using the Config Collections as mentioned in the prior section for simplicity.

It is important to note that the recovery of vCloud Director Virtual Applications can be very difficult and can also be very simple at the same time. The complexity arises because the CIVApp container configuration is in certain sections based on configuration of dependent items such as Virtual Machines. These VMs can be different in many ways such as more or less network adapters. As well, in CIVApps, the Virtual Application Networking can be wildly different if recovering “In Place” from an old backup. For this reason I sum it up in saying that “Out Of Place” CIVApp restores are easiest as there are little configuration changes that need to take place to achieve a restore with high levels of configuration parity. On the contrary, “In Place” restores are difficult to achieve with high levels of configuration parity.

With these cmdlets we are expecting that you are protecting the Virtual Machines with whatever method you so choose. It is important to mention here that there are “In Place” Virtual Machine recoveries which leverage change block tracking (CBT) and VADP which basically just roll back Virtual Disks. There are also “Out Of Place” VM recoveries which can be considered full Virtual Machine recoveries. It is outside the realm of this post to describe how you would restore a Virtual Machine. All that we rely on here is that Virtual Machine’s either already in a CIVApp and are named properly (based on backup), or Virtual Machines are “waiting” in vSphere to be consumed by vCloud Director. So in the case of an “Out of Place” CIVApp recovery, you must recover the Virtual Machines first into vSphere and then use the cmdlets. In the case of “In Place” CIVApp recoveries, you must recover the Virtual Disks if you so desire for the Virtual Machines. You may also use the cmdlets and skip the VM import function and execute only Virtual Application configuration recovery against an existing CIVApp.

Is that clear? =) This post only integrates with Virtual Machines to import them into vCloud Director!

Restore-CIVApp

This cmdlet is used to do either “In Place” or “Out of Place” Virtual Application restores. It requires that you specify the configuration files directory or Config Collection variable and whether the restore is occurring “In Place” or not.

The following command will restore “In Place” an existing CIVApp configuration without importing VMs into a CIVApp. See below for more options.

Restore-CIVApp -restoreInPlace -Name NewVApp2 -orgVdcName BRS-vLab-OvDC -XmlVAppConfigCollection ([xml](gc .\backups\vapp-05fda93c-8576-4ba5-9db7-ec8082697753\vapp-config.xml))

The following command will restore “Out of Place” to a new CIVApp and will import specific VMs from vSphere during the process. Notice how we specify each VM with VMName as it is uniquely called in vCenter, CIVMName as the name we wish it to have in vCD, and ComputerName as the Guest hostname if we wish to customize it. The Guest hostname will change after the Import if it differs from what is in the Config Collection.

@{VMName=”App-Fin-WFE”;CIVMName=”App-Fin-WFE”;ComputerName=”App-Fin-WFE”},

@{VMName=”Finance VM 1″;CIVMName=”Finance VM 1″;ComputerName=”FinanceVM1″} | Restore-CIVApp -Name NewVApp2 -orgVdcName BRS-vLab-OvDC -nocopy:$true -XmlVAppConfigCollection ([xml](gc .\backups\vapp-05fda93c-8576-4ba5-9db7-ec8082697753\vapp-config.xml))

The following command is like the first one presented, but it specifies VAppOptions which lists specific sections of the CIVApp configuation to restore. By removing items, you stop these items from being configured. An empty array (,@()) can be specified for no CIVApp options.

Restore-CIVApp -restoreInPlace -Name NewVApp2 -orgVdcName BRS-vLab-OvDC -XmlVAppConfigCollection ([xml](gc .\backups\vapp-05fda93c-8576-4ba5-9db7-ec8082697753\vapp-config.xml)) -VAppOptions @(“VAppNetwork”,”VMNetworkConnection”,”VAppNetServices”, “GuestCustomization”,”VMCapabilities”,”Startup”, “LeaseSettings”,”VAppMetadata”,”VMMetadata”,”Owner”)

Restore-CIVAppTemplate

The restore of CIVAppTemplates are very similar to those of CIVApps. However, there is an important distinction. The CIVAppTemplates are for the most part not modifiable, so there is firstly not a need to restore configuration “In Place.” The second is since CIVAppTemplates are not modifiable, there is no way to restore configuration. Any restore of a CIVAppTemplate “Out of Place” happens by performing CIVApp recovery steps but in a more static way since configuration is expected to be perfectly succinct with backup. Once this recovery “Out of Place” is complete, it is up to the user to verify proper integrity of configuration and add to the proper catalog. A “Restore in Place” is capable only for Virtual Machine Virtual Disks in this case.

This command will recover CIVAppTemplate configuration to a CIVApp as a new CIVApp.

@{VMName=”App-Fin-WFE”;CIVMName=”App-Fin-WFE”;ComputerName=”App-Fin-WFE”},

@{VMName=”Finance VM 1″;CIVMName=”Finance VM 1″;ComputerName=”FinanceVM1″} | Restore-CIVAppTemplate -Name NewVAppTemplate2 -orgVdcName BRS-vLab-OvDC -XmlVAppTemplateConfigCollection $xmlVAppTemplateConfigCollection -VAppOptions @(“VAppNetwork”,”VMNetworkConnection”,”GuestCustomization”, “VAppTemplateMetadata”,”VMMetadata”,”Owner”)

Advanced Restore of vCloud Configuration

So those are the basics of what I am publishing as capabilities for Backing up and Recovering Virtual Application configuration in a vCloud Director world. The previous section is dramatically simplified compared to what can be done by leveraging the “under the covers” cmdlets for recovery. Now let’s expose the process so you can possibly paint outside the lines if so desired.

Creating Virtual Applications and Importing

The first step in recovery is to possibly create a new Virtual Application container and import specific vSphere Virtual Machines into this container.

New-CIVApp2

This cmdlet differs from the standard New-CIVApp cmdlet since it only creates a blank CIVApp container. The New-CIVApp cmdlet will clone from an existing CIVApp or deploy from CIVAppTemplate. In our case, we create blank containers with no VMs as a place holder which can then be used for Virtual Machine imports.

Creates a new CIVApp named testvm in a specific Organizational Virtual Datacenter.

New-CIVApp2 -Name “testvm” -OrgVdc (Get-OrgVdc BRS-vlab-ovdc)

Import-CIVApp2

Once we have a CIVApp container we can use Import-CIVApp2 to bring import Virtual Machines from vSphere into this container. The CIVApp container can have existing VMs or not, a (-Replace:$True) parameter can be used to delete an existing Virtual Machine if the name of it in the CIVApp container is the same as one being imported as (CIVMName). The (-NoCopy:$True) parameter can be used to move the source vSphere VM instead of a copy.

Here we are importing two Virtual Machines, VMName specifies the vSphere (hopefully) unique name, CIVMName specifies the name of the VM within the CIVApp, ComputerName is the Guest hostname and is important if you are custmizing the guest. The (-OrgVdcName) is the actual name of the OrgVdc (not object).

@{VMName=”wguest-vapp5″;CIVMName=”VM4″;ComputerName=”VM4″},@{VMName=”wguest-vapp5″;CIVMName=”VM3″;ComputerName=”VM3″} | Import-CIVApp2 -Name VApp9 -OrgVdcName “BRS-vLab-OvDC”

Import-CIVAppTemplate2

This cmdlet is for creating a CIVAppTemplate based on a Virtual Machine import from vSphere. This may or may not be useful and is very limited since there is are basically no configuration changes that can take place or VMs that can be imported in a template state.

The following command will import a specific VM from vSphere and import it directly into a VAppTemplate and name the tempalte (-name) and the VM (-vmName) along with its ComputerName (-ComputerName) and whether to copy or move the vSphere VM (-sourceMove).

Get-VM wguest-01 | Import-CIVAppTemplate2 -name test20 -vmName “testvm” -ComputerName “testvm” -OrgVdc (Get-OrgVdc BRS-vlab-ovdc) -sourceMove “true”

Restoring Static Virtual Application Configurations

These cmdlets are to be used in mostly “like for like” Virtual Application configuration restore scenarios. This includes situations where you are recovering CIVApp’s “Out of Place” and possibly “In Place.” They work on the premise that we take XML from the backup, and reapply it to existing CIVApp containers. If the dependent items differ (more or less Virtual Network cards, Virtual Machines), then vCloud Director may complain during restore. See next section for more dynamic restores.

The following cmdlets use the Virtual Application or Template Config Collections. Place this configuration in an XML object variable for use in the cmdlets.

$xmlVAppConfigCollection = ([xml](gc .\backups\vapp-05fda93c-8576-4ba5-9db7-ec8082697753\vapp-config.xml))

Restore-CIVAppNetworkConfig

Restores the NetworkConfigSection to the target CIVApp. This section includes relevant networking information for a CIVApp such as VApp Networks and VApp Networking Services (Firewalling, NATing, DHCP, etc.).

Get-CIVApp test7 | Restore-CIVAppNetworkConfig -NetworkConfigSection $xmlVAppConfigCollection.VAppConfigCollection.VApp.NetworkConfigSection

Restore-CIVVMNetworkConnection

Restores the Networking Connections per Virtual Machine from the Children section of the CIVApp. This information includes MAC address and parent Network. The parent network may mean it relies on first running the Restore-CIVAppNeworkConfig.

Get-CIVApp test7 | Get-CIVM | Restore-CIVMNetworkConnection -VAppChildren $xmlVAppConfigCollection.VAppConfigCollection.VApp.Children

Restore-CIVAppGuestCustomization

Restores the Guest Customization properties of Virtual Machines in a CIVApp.

Get-CIVApp test7 | Get-CIVM | Restore-CIVMGuestCustomization -VAppChildren $xmlVAppConfigCollection.VAppConfigCollection.VApp.Children

Restore-CIVAppOwner

Restores the Owner of the CIVApp.

Get-CIVApp test7 | Restore-CIVAppOwner -OwnerSection $xmlVAppConfigCollection.VAppConfigCollection.VAppReconfigurationCollection.Owner

Restore-CIVAppAccessControlParams

Restores the Access Control parameters that specify which users have access to the CIVApp.

Get-CIVApp test7 | Restore-CIVAppControlAccessParams -ControlAccessParamsSection $xmlVAppConfigCollection.VAppConfigCollection.VAppReconfigurationCollection.ControlAccessParams

Restore-CIVAppMetadata

Restores the Virtual Application customizable Metadata.

Get-CIVApp test7 | Restore-CIVAppMetadata -MetadataSection $xmlVAppConfigCollection.VAppConfigCollection.VAppReconfigurationCollection.Metadata

Restore-CIVAppVMMetadata

Restores the Virtual Machine customizable Metadata.

Get-CIVApp test7 | Get-CIVM | Restore-CIVMMetadata -VmConfigCollection $xmlVApp.ConfigCollection.Vapp.ConfigCollection.VmConfigCollection

What do you think?

Unleashing VMware vSphere Stats for Powershell

Posted by vele1655 | Posted in Infrastructure, Monitoring, Powershell | Posted on 25-01-2013

Tags:

0

 

Stat collections using PowerCLI is a pretty well covered topic.  I have seen a lot of work done out there where it is demonstrated how to use the PowerCLI stats cmdlets, and how output can be customized to fit the needs of the consumer.  This post should be a bit different.  We will slightly reverse engineer how the Get-Stat/Get-StatType/Set-StatInterval cmdlets are used together, in order to provide a better understanding of how to leverage them along with new cmdlets presented here.  This should allow you to take full advantage of stats collections for VMware vSphere environments.  The methods shown actually under the covers are very similar to the methods that are used, if not the same, from a vSphere Web Services SDK (SOAP) perspective.

  • PowerCLI Get-Stat – Realtime, Raw Feeds, Collection Intervals
  • New Powershell vSphere Stats Module
  • Timesync issues

 

Later in this post I present a custom module for stats collection.  The second portion does leverage the vSphere SOAP SDK via the .NET compiled SOAP assembly, which gives native access to all exposed SOAP methods/types/events.  This can serve as a pretty cool example of how to develop more natively to the API in parallel to the PowerCLI framework.

I do some really interesting stuff here and possibly open up some opportunities while solving some challenges/bugs that Get-Stat presents currently.   A brief summary of what you get once you plow through the basics =)

  • Better output formatting
  • Expose more vSphere object types for stats
  • Show vSphere stats library
  • Intervals handled properly
  • Possible Timesync problems avoided

 

PowerCLI Get-Stat – Realtime, Raw Feeds, Collection Intervals

It is important to first put this post in perspective in regards to the basics of what is provided via PowerCLI.  There are three cmdlets that can work together to properly return stats for vSphere objects (VM, VMHost, Cluster, Resource Pool).  Lets explain the interaction of these objects because it relates to what you may or may not get returned when retrieving stats.

Get-StatInterval 

This cmdlet is used to return the appropriate intervals at which stats from the EsxHosts and vCenter are rolled up to aggregate stats.  These can take the form of (none, average, minimum, maximum, summation, and latest).  Notice how we are using a custom cmdlet (to be explained later in the post) to return all rollupTypes.

image

 

And when stats get rolled up there is a specific type associated (rate, absolute, delta).  This terminology is widely used across performance tools, so no need to explain it here.

image

 

Now comes the stat interval part.  We have established that stats get rolled up, and the Get-StatInterval command determines how often vCenter does it’s rollups (Sampling Period Secs) and for how long it keeps these stats (Storage Time Secs).

image

 

In summary sampling periods (rollups) are done for the 5-minute, 30-minute, 2-hour, and the 24-hour periods (Sampling Period Secs).  This information is held in the vCenter database for 1-day, 7-days, 30-days, and 1-year periods respectively (Storage Time Secs).  There is also a real-time option that comes from specifying a –Realtime parameter which aligns to 20-second intervals using a “raw feed” from the ESXi hosts directly.  ESXi hosts hold the 20-second samplings for 1 hour.  More to be covered here later in the post.

 

Get-Stat

So the combination of the rollups and the duration of storage should yield that our vCenter objects adhere to these rules.  Let’s take a look at the statistics that are returned for a virtual machine with default parameters specified.  Below you can see that we are calling (Get-VM | Get-Stat | Group MetricId).  This means that we are asking for the stats relating to a specific VM and then combining all of the rows with matching MetricIds into individual rows to help organize the results.  We do the same following when grouping by Timestamp.  With this you can see a few things.

  • 568 samplings returned for the metrics
  • 6 metrics returned for VMs
  • Samplings every 2 hours (7200 seconds)

image

 

So this is interesting.  When executing the PowerCLI Get-Stat command without parameters we get results for rollups at the 2-hour level.  But this doesn’t quite seem right however, are there only 6 metrics that are stored in vCenter for a VM?  The answer is no.

There are actually a lot more.  Let’s look at how to maximize the output from the Get-Stat command.

 

Get-StatType

Using PowerCLI and Get-Stat, if we want to get all stats from a vSphere resource then we need to force Get-Stat to look at all available metrics for that resource.  Using no parameters generated what we saw above (6 rollup stats for VMs) but in reality there are a lot more to be had.  So how can we see what those are and get them?  Get-StatType is the answer.  This cmdlet returns all available metrics for a resource.  When running against the same VM and for the 7200 second interval (2-hour) you can see we return more than 6.  We actually get 19 rollup stats for VMs.

image

 

So the stats exist in vCenter’s database, now how can we get at them?  Simple, we need to pass this list of all available stats to the –stat  parameter when running Get-Stat.  Below is the command that can be run to expose all rollup stats for the VMs.  Notice something interesting, that the disk.used.latest metricId has 2840 samples whereas the rest have 568.  This is due to “instances” or multiple disks per VM (swap, delta, flat).  This metric is also tracking different disks which are counted separately.

Get-VM vmName | %{ $_ | Get-Stat -Stat ($_ | Get-StatType -Interval 7200) } | Group MetricId | Sort Name

image

 

Now what is important at this point is that we are covering rollups stored in vCenter.  What we haven’t mentioned prior is that there are is a well known capability in vCenter to set the performance logging level.  Basically what happens is that all stats are generated at the ESXi level no matter what (I believe), and only certain stats are requested by vCenter when doing its stats rollup process.  The level is assigned per metric, and even possibly per device type if a metric is shared.  So you can see below that the level 4 (highest) has 184 metrics that it might record if all vSphere resource types were rolled up at the highest level.  vCenter ships at level 1, which means only certain metrics are rolled up.

image

 

Now let’s consider where rollups come from.  The rollups are based on real-time collections at the ESXi host layer.  The real-time collections, as mentioned before, are done every 20 seconds automatically.  These 20-second collections are then stored for 60 minutes on each ESXi host and vCenter accesses these pre-built stats when collecting.  The stats that live on the ESXi hosts can also be accessed by setting the interval appropriately.    When requesting this real-time feed (raw, explained later), all counters that are requested regardless of level (explained shortly) are returned.

You can see this in the following example where we specify the -Realtime parameter to Get-StatType which then returns all available metrics from all levels.

Get-VM VMname | Get-StatType -Realtime | Sort

imageimage

 

Let’s see what happens when we issue a real-time Get-Stat request.  You can see that we are showing the 20-second sampling period which dictates results coming from the ESXi host, but we are only seeing 9 metrics.  This sounds awfully familiar to the situation we encountered before where we needed to manually specify the –Stat parameter with Get-StatType to force the cmdlet to return everything for that resource.

image

 

So same trick as before, we are now forcing the exact stats to return and are seeing 258 instead of 8!  Sweet.

image

 

Now comes the next trick.  Say you would want to limit the stats being return to only the most recent one to create a “esxtop" style view.  This would happen by specifying the –MaxSamples 1 parameter.  Important note here, when looking at the use case for this compared to other perfomance metrics you may know. 

  • vSCSIStats – Realtime, IO sizes, Micro-Bursting stats (sub ms, no averages—histograms), not recorded, storage-VMDK focused
  • EsxTop – Semi-Realtime, averages, Hypervisor/VM focused, not recorded, extra collections on host
  • vSphere SDK QueryPerf (Get-Stat) – Semi-Realtime, averages, all vSphere focused, recorded

 

Notice how we are actually sorting and issuing a select on specific columns followed by formatting in a table format. 

image

 

Now the last part for PowerCLI’s stats collection.  What are the breadth of metrics available via PowerCLI’s stats collection?  When we mention realtime/rollup we are referring to the fact some resources have real-time metrics and some don’t.  However, the breadth of available metrics is visible by forcing the use of -Realtime when using Get-StatType.

114 for VMs (realtime)VMs – 114 metrics

image

 

VMHosts (realtime) – 170 metrics

image

 

Cluster (only rollups) – 30 metrics

image

 

Resource Pool (only rollups) – 6 metrics

image

 

 

New Powershell vSphere Stats Module

Now we can begin to transition into the 2nd part of this post focused on a new Powershell module I created for vSphere stats.  This module represents two things.  1) Simplifying the use of what was previously presented for Get-Stat/Get-StatType cmdlets 2) A re-write of Get-Stat as Get-StatAdv that leverages the vSphere SDK to simulate the functionality of but provide more stats than Get-Stat currently does.  So let’s continue!  Here is a summary of what the module provides.

  • Connect-VIServerVim, Get-StatRealtime, Get-StatRollup, Get-StatAdv, Get-StatTypeAdv, Get-StatCompositeAdv, Get-PerfCounter
  • QueryPerf/QueryPerfComposite
  • Exposes Datastore, Datastore Cluster, Datacenter, Folder Stats
  • Leverage Get-View as well as standard PowerCLI get cmdlets
  • Composite stats
  • Filterstat
  • Framework for vSphere Web Services SDK Soap

 

So first thing is first.  You must first follow the following criteria.

  • Developed in Powershell v3, PowerCLI 5.1 Release 1 (no guarantees for lower version)
  • Download the module here.
  • Unzip, and then load the module (dir *.psm1 | Import-Module)

 

Connect-VIServerVIM

This cmdlet does all of the fancy work and is based on previous work in this module but cleaned up dramatically since there was an actual use case for it. =)

Connect-VIServerVIM -username user -password ‘pass’ -viserver vCenter

or

Connect-VIServerVIM -credential (get-credential) -viserver vCener

 

Get-StatRealtime

Here is the first stat cmdlet to discuss.  The Get-StatRealtime cmdlet issues the same query (against Get-Stat) that you saw in the previous screenshot, so you’ll notice the output is the same and we are still leveraging PowerCLI’s stats cmdlets.

image

 

Get-StatRollup

As well for the rollups, I provide the Get-StatRollup cmdlet which issues the same query (against Get-Stat) and neatly formats output from rolled up data similar to above.  Here you see we issue with the –Interval 300 parameter and then group it by timestamp.

image

 

So in comes one of the first problems that the module is addressing.  Notice how in prior examples when looking at rollups we only saw 2-hour samplings.  Well, here you can see that we are issuing another call using the –Interval 300 parameter which should return us the 5-minute data stored on the vCenter server.  Problem!  We are getting the 2-hour samplings back.  How can we return 5-minute results from the PowerCLI Get-Stat cmdlet?  Use the –Start parameter (see end of post).  But overall, this seems to be a bug that I address with my custom module.

image

 

You see this as well across all four intervals where only 2-hour and 1-day intervals are returned.

image

 

Get-PerfCounter

So how many vSphere stats are there for vSphere 5.1 through the web services SDK?  The Get-PerfCounter cmdlet can answer that question.  We are formatting and selecting columns that are returned, but you can see the jist of it here.  There are 459 in vSphere 5.1 in my setup.

image

 

 

Get-StatAdv

This cmdlet is based on what the Get-Stat cmdlet returns and leverages the same SOAP methods via the vSphere SDK that the Get-Stat cmdlet uses.  However, through this method we provide native use of the QueryPerf SOAP method to return the performance stats.  By doing this we have complete control of what the methods receives for inputs and what the output looks like.  So in this case let’s give it a shot and issue the same command as prior with the –Interval 300 parameter against Get-StatAdv.  Notice how we are returning the same 23 rolled up stats as prior, but are now returning them every 5 minutes.

 

Get-VM VMname | Get-StatAdv -Interval 300 | Group Timestamp | Select -First 1

image

 

 

 

This is just the beginning!

 

Now what other types of resources can we pull for using Get-Stat or Get-StatRealtime? Clusters, Hosts, Virtual Machines, Resource Pools based on the error we get when trying to return stats for a Datacenter.

image

 

 

Since we are native to the QueryPerf method we can give it a shot and pass these objects in!  Coolness!  We now have Datacenter stats!  Note that we are specifying the –Interval 300 parameter below because these objects do not allow Realtime lookup from the Esxhosts.  Makes sense right?

image

And Folder stats!

image

 

Like Datacenters, Datastore views of performance are aggregations from Esxhosts and Folders/Datacenters are logical objects that aren’t collected via Esxhosts.

image

 

And a couple of Datastore Cluster stats!

image

 

If you’re familiar with vCenter Operations, what you’re now seeing may start to align a bit more with what is presented!

 

Timesync

I mention Timesync since it can be a problem when using the Get-Stat PowerCLI cmdlets.  The –start and –finish parameters allow you to specify time ranges during queries.  However, be aware that the DateTime objects are being sent (with proper timezone changes) to SDK.  This means that if the minutes/seconds is off between the client and server, the DateTime specified may not return expected results.  You can get around this with the PowerCLI cmdlets by using a command like the following.  Notice ($global:DefaultVIServer.ExtensionData.CurrentTime().ToLocalTime()).AddMinutes(-5)).  This command gets the current vCenter time, converts it to local time (timezone applied) and then removes 5 minutes from it.  This way you are always submitting the DateTime to vCenter without TimeSync issues.  In the custom module, we compute time differences and make up for them, so you can use ((Get-Date).AddMinutes(-5)) for example and it will be fine.

Get-VM VMName | Get-Stat -Start ($global:DefaultVIServer.ExtensionData.CurrentTime().ToLocalTime()).AddMinutes(-5) | ft * -autosize

image

 

Composite

Last but not lease there is a Get-StatCompositeAdv cmdlet.  This cmdlet leverages the QueryPerfComposite method which is meant for quicker queries and reduced network traffic.  The downside to using the composite method is that it seems to not return instances such as virtual disks.  Do your own scale testing to see!

Custom cmdlets can be tweaked to use CSV, and keep in native format which would save on client-side overhead for processing large amounts of stats. 

 

Links

Please review the vSphere Management SDK docs for Web Services and performance.

http://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.wssdk.pg.doc%2FPG_Performance.18.4.html

 

Breadcrumbs

For those wanting to develop against the SDK similar to what I did here.  Notice the $vimClient.VimService type is SoapHttpClientProtocol.  This is where all of the .NET methods/events exist.  Issue a Get-Member against it and check what you now have access to!  All of this is documented with C#/Java examples of how to leverage.  You can look at what I did in this module to help transpose what you might need to do.

image

Automating the Configuration of VMware Server Appliances for Image Level Protection with PowerCLI

Posted by vele1655 | Posted in Automation, Avamar, Backup, Powershell, VDP | Posted on 07-01-2013

Tags:

0

Part 1 of this series can be seen here where we discuss the nuts and bolts behind how to protect vPostgres databases by VM image level or guest level protection.  Here we will simplify it a bit and focus only on VM image level protection.  This assumes you are leveraging VDP or Avamar. 

All of that seems manageable I’m sure, but what if you want to press the easy button and have PowerCLI do it all for you?  This post contains work that is experimental.  It will allow you to protect VMware Server Appliances (VCSA, vPostgres, etc) that are published by VMware.  The automation may not be sanctioned directly by VMware, but the steps (if available) were taken from their website so the end-state should be supported. 

Warning: This is highly experimental!

Pre-Requisites

  • Powershell v3
  • PowerCLI 5.1 Release 1
  • Download module from here
  • Unzip, and run (dir *.psm1 | import-module -force)

Image Level Protection

This was the easier method in which we simply schedule a Cron Job that executes a pg_dump/all command on the vPostgres database.  This generates a file locally which is then backed up if you have the VM on an image level backup schedule with Avamar or VDP (VDP does not protect its own VCSA). 

By the time of this post I have tested this with the vPostgres vApp (9.1) along with the vCenter Server Appliance (5.1.0.5100).

 

Image Level – VCSA

The vCenter Server Appliance contains instructions on the VMware website, on how to do a Postgres backup.  I followed these directions to a T in creating our cron job. 

Get-VM VCSAname | New-VCSABackupCronJob -GuestUser root -GuestPassword vmware

image

 

If you take a look at the /etc/cron.daily/backupvPostgres.bin file you can see the results of this command. 

image

 

Feel free to execute this command to give it a test (/etc/cron.daily/backupvPostgres.bin).  You can then take a look at the backup (ls –laF /storage/db/vpostgres).  You can see we have a 400MB backup file of the VCDB instance.  Keep in mind that we are backing up to the same partition, so make sure to manage your space to ensure there is space for the DB along with its backup!

image

 

Image Level – vPostgres

Now the image level protection that we demonstrated with the vCenter Server Appliance basically leverages the vPostgres Cron Job cmdlets under the covers in a more specific way since VMware had specific details.  This can be done very easily for any Server Appliance that has the same level of details.  If it is the vPostgres Server Appliance, then you can always protect the whole Postgres instance with the following command.  Notice the New-vPostgresBackupCronJob cmdlet instead of the VCSA one.  The screenshot below shows the command being run.  Take note that we discovered the vPostgres path automatically.

Important Note:  With the version of vPostgres I was using, 9.1, the VM Tools Daemon on the vPostgres vApp was not configured for PAM authentication.  If you want Invoke-VMScript to work, you need to fix this.

Edit /etc/pam.d/vmtoolsd (and paste the next lines, and save the file)

#%PAM-1.0
auth       sufficient       pam_unix2.so nullok
auth       sufficient       pam_unix.so shadow nullok
auth       required         pam_unix_auth.so shadow nullok
account    sufficient       pam_unix2.so
account    sufficient       pam_unix.so
account    required         pam_unix_acct.so

 

Ok.. continue on!

 

Get-VM VMname | New-vPostgresBackupCronJob -GuestUser root -GuestPassword password 

image

 

Taking a look at the Cron file for this one, you can see it is more generic.  We are leveraging the pg_dumpall command here and putting the backup in the root of the vPostgres instance path.

image

 

Feel free to run the backup (/etc/cron.daily/backupvPostgres.bin).  You can look at the bak file as well to ensure that it ran.

image

 

The Cmdlets

New-VCSABackupCronJob – Instantiates a specific vCenter Server Appliance Cron Job creation

New-vPostgresBackupCronJob – Instantiates a general vPostgres Cron Job creation

Get-vPostgresPath – If a path is not specified we leverage this to try and determine what the vPostgres instance path is

New-VMOSCronJobvPostgres – We specify a generic backup script here, replace necessary items, and launcht he New-VMOsCronJob cmdlet

New-VMOSCronJob – This issues the New-VMOSScript command followed by a reset of the Cron service

New-VMOSScript – This takes a script text, creates a temporary file of it, copies it to the VM, moves it into place, and then makes it executable.

 

Restoring?  As always, make sure to follow application guidelines.  We are simply showing you how to create a backed up file which should then be used as part of a larger restore process that should be laid out by your application vendor.

 

You tell me? Is this useful?

Installing and Configuring an Avamar Agent Remotely Using PowerCLI

Posted by vele1655 | Posted in Automation, Avamar, Backup, Powershell, vCloud Director | Posted on 05-01-2013

Tags:

1

In the case of VMware Virtual Machine protection, this most likely isn’t necessary since you probably are using VM Image level protection right?  I hope so!  But there are cases when a more granular backup is desired.  This can useful if you want to target backups in the operating system for specific files, or specific applications.  In this case you will need to install an Avamar agent in the guest VM in order to do the guest OS operations and source-based dedupe.  The following post will give you the capability to completely automate, if desired, the install process of the Avamar guest agent as well as application agents.  This is meant for installs, but can be used for upgrades as well. 

So how can we accomplish this?  In PowerCLI there are a couple of commonly used cmdlets called Copy-VMGuestFile and Invoke-VMScript which allow you to transfer files and execute commands from a specified user account without the VM having a network connection.  The communication happens between the hypervisor and the VM.  The operation of the module is simple, you can either leverage the remote install capability in a on-demand or fully planned manner (CSV file).

As always, please do your own testing prior to use anywhere outside a lab to ensure you understand how this operates!

 

Pre-Requisites (as developed)

  • PowerCLI 5.1 Release 1 and Powershell 3 (should work on prior versions as well)
  • Avamar 6.1 (should work on any version)
  • Will work with any Linux version that allows Invoke-VMScript/Copy-VMGuestFile
  • Avamar Installed
  • Download module here
  • Unzip module, run (Dir *.psm1 | Import-Module) in Powershell
  • Logged into vCenter with PowerCLI, possibly vCloud Director as well (use Get-CIVApp name | Get-CIVM | %{ $_.ToVirtualMachine() })
  • Passwords specified as command line parameters with special characters have single quotes surrounding them!  (chorn)
  • VMware Tools are installed on the VM and scripts can be executed, and files transferred

 

Currently this only does Linux Agents that use RPM files.  Soon to be expanded..  We do not leverage MCCLI, or any programmatic interface to Avamar during the install, so it is up to you to verify that all was installed correctly.  This is solely meant to make the deployment of agents as easy as possible for VMware VMs that require guest agents.

 

On-Demand Install

Download the Avamar Agent to the PowerCLI System

Let’s consider this the beginning of this post and I will continue to mature and update it.  For now it is limited to Linux.  Very simple, the first step is to download an Avamar Agent installer file.  This is available by going to the Avamar web interface and pressing the link at the bottom, Documents and Downloads.  Now, find the agent that you want to install (hopefully a Linux one until I do others soon). 

Another important note here is that you could leverage a simply where clause when getting VMs to find ones that match specific operating OS types and then specify the agent required to fulfill these types.

Get-VM | where {$_.ExtensionData.Guest.GuestId -eq “sles11_64Guest”}

Test Invoke-VMScript

Now we want to test to ensure you can use the credentials specified and do a simple command like “echo”.  If your output looks like the screenshot, then you’re set.  Another way to do the following would be to use the Get-VMScriptEcho cmdlet.

Get-VM VMname | Invoke-VMScript -GuestUser guestUser-GuestPassword guestPassword -ScriptType bash -ScriptText "echo"

image

 

Copy, Install, and Configure the Agent

Now we move on to the actual Install-AvamarAgent cmdlet.  With this cmdlet we will copy the agent, as well as install and configure the agent using the specified information.  The expected output is in the following screenshot.  Notice that the last few lines are outputting a powershell object that contains the vm name, whether the install was successful and the result if there was an error.  You can capture this in a variable such by pre-pending $tmpRun = Get-VM…

Notice how wildcards are permitted in the file name!  We add a [0] at the end to ensure that we only select the first file if the wildcard matches multiple agents!

Get-VM VMname | Install-AvamarAgent -agentFile (Get-Item AvamarClient*sles11-x86_64*.rpm)[0] -GuestUser guestUser -GuestPassword guestPassword -AvamarServer avamar_ip_or_dns

image

 

How about a Avamar guest application agent? A very similar command will give similar results.

Get-VM VMname | Install-AvamarAppAgent -agentFile (Get-Item AvamarRMAN*sles11-x86_64*.rpm)[0] -GuestUser guestUser -GuestPassword guestPassword -AvamarServer avamar_name_or_ip

 

As you can see in the previous step we manually are specifying which agentFile.  What if you want this to be determined automatically?  The following command will attempt to match the proper agent file to the guest along with generating useful information which is for the most part leveraged in a planned install which is shown in the next section.

Get-VM bsg67235 | Export-VMGuestToolsInfo

image

 

Notice also from above that there are empty fields with AgentBinary_.  These are leveraged in the next planned install section, but can also be leveraged here.  You can fill these in on demand here if needed.  Here we will replace a column, but you could also add any column as AgentBinary_name.

Get-VM name | Export-VMGuestToolsInfo | Select *,@{n=”AgentBinary_RMAN”;e={“AvamarRMAN*.rpm”}} -ExcludeProperty AgentBinary_RMAN

 

You can then run Get-VmGuestAvamarAgentTargets as an extra command, to ensure you have downloaded the correct guest OS agent executable.   If the file is not found, you would receive a warning.  The application agent file is not checked here however, so make sure it exists or else it will get skipped on install.  As you can see below we are good, we have a VM, and and agent binary without warnings displayed.

Get-VM name | Export-VMGuestToolsInfo  | Get-VmGuestAvamarAgentTargets

image

 

So if you want to actually install based on these results, you can call then use the Install-AvamarAgentTargeted cmdlet against your Export-VMGuestToolsInfo output.

Get-VM name | Export-VMGuestToolsInfo | Install-AvamarAgentTargeted -GuestUser username -GuestPassword password -AvamarServer avamar_dns_or_ip

 

Great! So what if you don’t want to specify credentials in plain text?  You can leverage the next method, or you can leverage the Get-Credential cmdlet as follows.

$cred = Get-Credential

image

After this, you can replace the following parameters with parameters from the $cred variable when executing.

-GuestUser $cred.UserName –GuestPassword $cred.password

 

A Planned and Automated Multi-VM, Multi-Agent Install

  • Generate CSV report with assigned Agent binaries
  • Modify CSV report to include only VMs necessary for install and proper agent
  • Import CSV and target VMs
  • Install agents automatically
  • Reporting

Now that we have the basics done and have seen it work, it is now time to step into a bit more advanced functionality.  Wouldn’t it be nice if I could generate a report of the VMs that are registered and automatically choose a proper Avamar agent based on the guest ID? How about doing VMs at the same time?  Let’s show you exactly how to do this.

 

Generate CSV Report

The following command can be run to get all of the virtual machines, and export specific metadata information that will be useful later on.

Get-Vm | Export-VMGuestToolsInfo | Export-Csv VmGuests.csv -encoding ASCII -NoTypeInformation

 

Modify CSV Report

Once this command is done, feel free to open the CSV file in an editor of your choice, most likely Excel.  Your results should look something similar to below, notice the AgentBinary column that is auto-populated if we detected a Guest OS that is compatible with Avamar.  This might not be 100% accurate, so feel free to replace the file if necessary.  Remove unnecessary VMs that you don’t want targets for Agent installs.  Make sure to download the agents now for any files listed that you intend to install once you save the CSV in its edited form.  This CSV could be split up into multiple parts and each ran in their own PowerCLI window to parallelize the process.  The whole process should take under 60 seconds, where the majority of the time can be spent transferring the agent thus relying on network bandwidth to determine total time for all VMs.  You can expect under 60 seconds per VM if single threaded.

image

The latest version includes more columns, for guest credentials and application agent binaries.  You will see the actual schema when you run the cmdlet for the first time.  Application agent binaries are not linked up with appropriate versions, but if needed you can reference the displayed client binary per VM to lead you to the correct application binary.  These should be downloaded individually and the name should be pasted into the appropriate columns.  Each column named AgentBinary_appname that is filled with a file name will be attempted to be found and copied/installed during the process.

 

Import CSV and Target VMs

The next step will leverage this information to verify that the agent exists (so take the time to download them now!), guest is running, and guest id is currently detected.  If all of these criteria are met then it is populated in the list below the warnings.  Notice how the VMs that have agents with warnings do not show up in the list.  Get-VmGuestAvamarAgentTargets acts as a filter to ensure successful install of agents.  Currently, the warnings will only show for OS agents, warnings for missing application agents will be displayed during install.

 

image

 

Install Agents Automatically (authentication)

Ok, so the next step is to take the output from the previous step and use it to do a backup.  If you are happy with what you saw above, then you can proceed with the next command.

The next thing to consider when running in batch mode is the authentication per VM.  There are lots of options.  Overall, keep in mind that if a guestUser is specified for a VM, then what is specified as a secure password in the CSV file takes priority (guestPasswordSecure), unsecure password next priority (guestPassword) per VM.  The next section explains some of the options, other than per VM in the CSV file, you can specify a blanket default username in plain text or securely as runtime along with securely as each VM is encountered that doesn’t have previously mentioned credentials specified.

Save Usernames and Passwords in the CSV file

The Install-AvamarAgentTargeted will respect columns that are named GuestUser and GuestPassword.  If these columns are filled for VMs then the credentials will be used.  For this reason, the following command can be used without specifying credentials.

Import-Csv VmGuests.csv | Install-AvamarAgentTargeted -AvamarServer avamar_name_or_ip

Save Usernames and Passwords (as secure string) in CSV file

There is a column named guestPasswordSecure, which can be populated with a long secure string that is generated by New-SecurePasswordString. 

New-SecurePasswordString ‘p$ssword’ | Out-File temppw.txt

Open this file with notepad, and copy the contents.  The string can be pasted into the CSV file column of guestPasswordSecure for any VM.  This string is only valid for the host that generated the secure string.

Specify credentials in plain text (same creds for all VMs)

Import-Csv VmGuests.csv | Install-AvamarAgentTargeted -AvamarServer avamar_name_or_ip -GuestUser guestUser -GuestPassword guestPassword

Specify credentials securely (same creds for all VMs)

Import-Csv VmGuests.csv | Install-AvamarAgentTargeted -AvamarServer avamar_name_or_ip -GuestCredentials (Get-Credential)

Prompt for credentials securely for every VM

Notice here that we are using “{“ and “}” around Get-Credential instead of parenthesis.  This delays the operation from runtime, further into the script logic.

Import-Csv VmGuests.csv | Install-AvamarAgentTargeted -AvamarServer avamar_name_or_ip -GuestCredentials {Get-Credential}

 

So plenty of options for authentication!  My suggested route would be to enter the credentials securely into the CSV file (generate the proper secure strings) and then leverage the “Prompt for credentials securely for every VM” as the default in case a VM doesn’t not have credentials specified. 

 

Reporting

If you run Install-AvamarAgentTargeted, then you will probably want to have results stored somewhere.  For this we keep a variable, $global:result filled as VMs complete.  At any time, if the script stops you can access this variable to see the history.  I am excluding a specific column for cleaner viewing, but this one is probably important to you to see why the “Installed” column would be False.

$global:Results | select * –excludeproperty errorResult

image

 

You could also generate an HTML report with the following command.

$global:Results | ConvertTo-Html | Out-File Results.html

.\Results.html

 

The Cmdlets

These can be used individually for the most part with the correct parameters.  Examples of how to run each cmdlet if not found in the above post, can be found in the module above the cmdlet. 

Export-VMGuestToolsInfo – Generates a CSV file containing relevant guest information and an automatic mapping of guest OS type to respective Avamar binary

New-SecurePasswordString – This generates a secures string that can be pasted into the guestPasswordSecure column of a CSV file

Get-VmGuestAvamarAgentTargets – Used as a filter to ensure the Agent binary is available, the VM is powered on, and the guest state is running.

Install-AvamarAgentTargeted – Consumes the Get-VmGuestAvamarAgentTargets filter cmdlet output and instantiates install of OS and application agents

Install-AvamarAgent – Copies, Installs. and Registers the Avamar Guest OS agent

Install-AvamarAppAgent – Copies, and Installs the Avamar Guest Application agent

Get-VMScriptEcho – Tests that remote commands can be executed on a VM

Copy-AvamarAgent – Copies the specified file to the VM

New-AvamarAgentInstall – Begins the install process of the agent on the VM

Register-AvamarAgent – Registers the Avamar Guest OS agent to Avamar

Restart-AvamarAgent – Restarts the Avamar Guest OS agent

 

That should be it, of course there are more things that could be configured during the registration but not covered here.  The next step is to verify the install under /clients, open your Avamar console and take a look!

 

What could be coming?  Msft Server of course..

Protecting vPostgres Databases with Avamar or VDP

Posted by vele1655 | Posted in Avamar, Backup, VDP, vPostgres | Posted on 03-01-2013

Tags:

0

In my last post I discussed how to leverage vPostgres from Powershell.  Overall the Postgres (I use interchangeably with vPostgres as a term) database is an excellent choice for it’s functionality in replacement of other enterprise database platforms.  If you start to look through the VMware portfolio, it is seems to be becoming clear that a convergence for standard platforms (Postgres included) is taking place.  This means that there is more of a need to properly protect the Postgres as a whole to ensure the proper SLAs of your infrastructure. 

This post will focus on the techniques that can be used to protect Postgres databases.  In following posts, there will be more specifics to the virtual appliances being supplied by VMware to show how we can improve on generic protection steps.  With that side, this work can be abstracted to provide protection to just about anything by Avamar.

 

Important Notice

  • This backup method does not leverage a specific Postgres agent, don’t expect robust error handling
  • The recovery point object (RPO) for this method is up to how often you run the backup, for large databases however it is likely once every 24 hours
  • Please test the recovery thoroughly to ensure you are familiar with the process and the integrity of the backups

 

Let’s start by differentiating between Avamar and VMware’s Data Protection appliance.  In a few words, what’s different?  VDP is specifically targeted towards doing VMware image level backups currently.  This means that extra functionality for using in-guest agents for scripting or application quiescing is not possible.  So the first major break point in this discussion is around which method you choose to use to protect Postgres.

The protection method questions can come down to two main things.  Will you be leveraging VMware snapshots and image based protection (Avamar or VDP) or are you going to use in guest agents (Avamar)?  Avamar in this case can be either Avamar Virtual Edition (a VM) or the Avamar hardware appliance.

In the Postgres case, for in-guest agents we can leverage the Linux agent which allows for extra steps and targeted backups of specific files.  This means that we are able to treat vPostgres agnostically of hypervisor, guest hardware, and anything other than the operating system.  It also means when we deduplicate at the guest operating system, we are solely looking at a specific file and not the whole operating system.

VM Image Level Backups of vPostgres (Option 1)

If looking at VMware image based backups we are operating with the notion that a backup would entail the whole virtual machine and all of it’s disks.  This overweight process with use of CBT (changed block tracking, similar to array snapshot blockmaps) where we only backup changed blocks between backups, makes for a slim manageable process even if we are looking far beyond just the targeted database backup file. 

So you may ask at this point, well if VMware image level backups are good then I’m all set for the super-easy button right?  Sort of.   It depends on the level of protection you want for your Postgres databases.  I want to put you to this article, re. Postgres 9.1 Backups.  We are not covering Point-In-Time recovery here, this is for another post and mostly relevant for larger DBs or frequent backups.

Let’s focus on file system level backups of Postgres.  If simply doing a VM image level protection then you are at the mercy of a database thinking it is recovering from a crash, no guarantees based on unflushed buffers for the DB and possibly pages for the OS. How do you overcome this for the Image method?  Invoking a cron job locally in the guest that kicks off a backup job and saves the file locally would work.  This means you get a dump file every time the cron job launches that can be used for a full recovery of the DB if needed. 

Problem?  If there is no alignment to the VM image backup process (running asynchronous to each other, with no central control), then you run the risk during the VM image backup of two main things.  1) That you don’t get a complete backup 2) The backup occurs during a VM snapshot which then would cause a lot of extra IO to consolidate the changed blocks into the original VM.  Now this may only be valid for larger databases, but overall this method for reliability requires that you first backup the database locally, followed by a VM image level backup.  In all cases here there is a lack of cohesion between backing up and shipping it off.  A target based dedupe platform as an NFS mount could help (Data Domain) but overall the process still can lack central control and tends to be a bit legacy for this discussion.

Preparing vPostgres for VM Image Level Protection

Download the files here that are shown below as examples. 

This is easy! Let’s just create a simple cron job.

SSH to your vPostgres system.  Use your favorite editor to create the /etc/cron.daily/backupvPostgres.bin file.  Make the file look at the following:

#!/bin/sh

/opt/vmware/vpostgres/9.1/bin/pg_dumpall -U postgres -c > /var/vmware/vpostgres/9.1/vpostgres.bak

 

Make sure to run “chmod u+x /etc/cron.daily/backupvPostgres.bin” to set execution permissions.  Run “service cron restart”.  That’s it, you should be able to run /etc/cron.daily/backupvPostgres.bin manually and see that a new file appears under /var/vmware/vpostgres/9.1/vpostgres.bak each time.  This means that a VM snaphot and a VM image level protection will protect the VM and the stateful backup of the Postgres database.

Everything mentioned above is editable.  If you want to change the schedule of backup, simply use another cron directory, ie. cron.hourly, or set your own cron configuration.  If you want to dump specific databases instead of all at once you can use the pg_dump command.  Do you have a specific mount point to put the backup?  Then change where the BAK file goes.

Guest Level Backups of vPostgres (Option 2)

Now, getting into the good stuff.  Avamar can be a central controller of the backup process for Postgres.  The process that I am laying out is to leverage the Linux FS plugin to coordinate a Postgres backup locally, followed by a targeted backup of that file.  This allows you to keep the control and reporting of the process in Avamar’s wheel house, and guarantees a proper consistent backup.

So does that mean we shouldn’t protect the VM with VM image level backup? No! Both would make sense in this case.  This means you have the best of all worlds.  Since Avamar has source-based deduplication, there is no waste of capacity.

 

Preparing vPostgres for Guest Level Protection

Download the files here that are shown below as examples. 

Ok, so now comes for the fun part.  The following is considering you have Avamar installed already.  Since we aren’t doing VMware integration for guest-level protection then simply installed is what is needed.

Download the Avamar Linux Guest Agent

The Avamar appliance allows the download of the agents via SSL without authentication.  Open the Avamar appliance up, via https://avamarip_or_dns/ with your web browser.  At the bottom you will see a link that says, “Documents and Downloads”.  Click this link and look for the appropriate Linux version (probably 64-bit Linux, if recent VMware vApp then likely SLES11).  Look for the AvamarClient-linux-sles11-x86-version.rpm file.  This should be transferred to your vApp via SCP, other copy method of choice, or using wget targeted at the Avamar appliance.  Here is a wget commmand that should work with modification for Avamar version.

cd /tmp; wget –no-check-certificate https://avamar_ip_or_dns/DPNInstalls/downloads/SLES11/AvamarClient-linux-sles11-x86_64-version.rpm

 

If you have the client downloaded, then only a few easy steps to get it up and registered to Avamar.

rpm -ivvh AvamarClient-linux-sles11-x86_64-version.rpm

cd /usr/local/avamar/bin

./avagent.bin –mcsaddr=avamar_ip_or_dns –register –daemon=false       (these are double dashes)

service avagent restart

 

image

That’s it!  If it shows as succeeded in the log then you’re good to go.  However, still a couple of more steps to perform in the guest.

Option A – Synchronously run pg_dumpall to local disk, followed by push to Avamar

This option is semi self-explanatory.  In this case the downside is sort of obvious, we are storing a backup locally on the database VM.  This adds capacity and IO requirements along with increases in backup times.  For smaller databases, this might make sense to have a copy locally (and is required under the VMware image protection method) but for larger databases this may not be the case.

Use your editor of choice and create a file called /usr/local/avamar/etc/scripts/backupvPostgres.bin.  This file should contain something similar to what you see below where anything is replaceable if you want to change database being backed up, destination of backup, version, etc.  Make sure to issue a chmod u+x on the file to ensure executable access.

#!/bin/sh
/opt/vmware/vpostgres/9.1/bin/pg_dumpall -U postgres -c > /var/vmware/vpostgres/9.1/vpostgres.bak

 

One more file to edit in the same way, /usr/local/avamar/var/vpostgres.cmd.  This file should contain one line as follows, which references the file specified after the “>” above.  This file tells Avamar which file to target when performing the backup.  Remember to also set executable permissions on this file (chmod u+x).  Now there is plenty more that can be done with these combination of files, but for now let’s keep it simple with a single file that gets overwritten.  Important NOTE:  If you did the image level backup process with a cron job, this should be removed if using the guest method!  You want Avamar to now issue the command to backup the database, and not a cron job.

/var/vmware/vpostgres/9.1/vpostgres.bak

 

Option B – Asynchronously run pg_dump to a named pipes per database, with immediate push to Avamar as data is dumped

This option leverages named pipes in Linux.  This basically means that a named pipe file (via mkfifo) is created and the pg_dump command leverages this file as output.  The interesting thing about this process however is that the file keeps the dump from Postgres and the push to Avamar in sync.  So as data is dumped from Postgres, Avamar receives and the named pipe acknowledges and accepts more data.  A backup is thus done without using local disks.  We cannot use pg_dumpall in this scenario since pg_dumpall closes the backup file per database which causes Avamar to prematurely think the backup is done.

The method here is similar to what you saw in A, with the caveat of /tmp as the path, one extra file “end_backupvPostgres.bin”, and naming of the database per file.  The end file kills all running pg_dump requests in case the Avamar job gets canceled.  This is important since a risk of using this method is that we basically let the pg_dump command run on its own without control (background) and it won’t exit until Avamar gets all of the data that is sent.  If the Avamar agent happens to exit early, the pg_dumpall command would never exit.  There other means to achieve what the end_ script is doing, but beyond this post for now.

/usr/local/avamar/etc/scripts/backupvPostgres-databasename.bin

#!/bin/sh
rm /tmp/databasename.bak
mkfifo /tmp/databasename.bak
/opt/vmware/vpostgres/9.1/bin/pg_dumpall -U postgres -c -f /tmp/databasename.bak databasename &>/dev/null &
disown
exit $?

/usr/local/avamar/etc/scripts/end_backupvPostgres.bin (end_backupvPostgtgres.bin needs to be added to the post-script section in the dataset under options and advanced)

#!/bin/sh
killall pg_dump &> /dev/null
exit 0

/usr/local/avamar/var/vpostgres-databasename.cmd (two dashes before label)

–label=databasename

/tmp/databasename.bak

 

Remember to (chmod +x) all of these files!  If you run the backup bin file individually, it will not work without a reciprocal avtar command to consume the backup file so you must kill this manually (ps auxw | grep pg_dumpall) and (kill pid).

Another thing to call out here is that each database requires two of three of the files above named uniquely.

 

 

Ok, that’s it for the guest itself.  Now let’s open the Avamar console.  If you haven’t installed this yet, it is available under the same Documents and Downloads location specified prior.  This time you look under the Windows for x86 link for AvamarConsoleMultiple-windows-x86-version.exe.  If installed, this is what you should see in your start bar.  What is done under the GUI is scriptable, via MCCLI but not shown in this post.  Most of what is shown below is only done once, where new vPostgres instances require guest level interaction versus anything else.

image

 

Create a Dataset

Open Tools –> Manage Datasets.

image

 

The Avamar Dataset is used to identify certain backup parameters that are specific to types of plugins and other options.  The datasets can be used in different places, but we will be using them by applying them to a vPostgres backup group.

New –> Enter the Name, possibly “vPostres Dataset”

image

 

Leave the defaults alone on this screen.  Select the Options Tab.  From the drop down, select Linux File System, and select the “Show Advanced Option” checkbox.  Under the Pre-script section look for “Run user-defined script at the beginning of backup” and enter “backupvPostgres.bin”.  As well look at the Advanced Option section for the “Client-side flag file” and enter “vpostgres.cmd” (case sensitive).  These two files should reference the two files created above.

Press Ok twice to return to the Avamar Administrator menu.

Create a Backup Group

The next step is to create a backup group to be used for any vPostgres instances that pop up in the future with new Linux agents.  Open Navigation –> Policy.

image

 

Now Right Click Clients (or anywhere you wish) and click New Group.

image

 

Let’s name it “vPostgres Databases”.  Unselect Disabled if you wish to use the group right away.

image

 

Now Select Next, and then choose the /vPostgres Dataset from the dropdown.

image

 

The next screen allow you to choose a schedule, retention, and which clients to include.  We selected defaults, and the client by name that we registered followed by Finish.  The next step is to press “Back Up Group Now”.  This will then kick off a job in the background to backup the database.

image

image

 

Now let’s take a look at the status or activity of the job.  Navigation –> Activity.

image

 

As you can see in the screenshot below of the activity window there are two backups.  I actually started one, and then did a subsequent one to show the deduplication that occurred at the source and how many new bytes were sent even with a new fresh database dump.  The backup of my small Postgres database occurred in 3 seconds each time, with 30% of the first backup sent to, while 2.4% sent on the subsequent backup.

image

 

And that concludes, the guest protection section when configuring these in a manual fashion for vPostgres.

 

Restoring

Please refer to the Postgres documentation for Backups where it refers to Restoring the Dump.  This is a very simple process where you stop the database, and issue a specific command “psql and <” to recover specific entities.  As well, please refer to VMware or application vendor that leverages the Postgres database before doing a DB recovery.  They may have specific steps or caveats to consider! 

Let’s look at the backups however in Avamar.  Open Navigation –> Backup and Restore.

image

 

Find the registered client in the list on the left, followed by a selection of the date from the calendar.  You should see listed on the right the backups of the vPostgres databases.

image

 

If you select a database, then you can then select from the dropdown below the navigateable tree on the Linux file system leading to the backup file.

image

 

 

That’s it!

Powershell, Meet VMware’s vPostgres

Posted by vele1655 | Posted in Database, Powershell, Scripting, vPostgres | Posted on 02-01-2013

Tags:

1

First things, first.  I mention vPostgres (VMware’s Postgres), but in reality what I am going to demonstrate here is capable via any version of Postgres.  Also, there are older methods that have been used where the Postgres standard ODBC driver is used, but the downfall here is the requirement on a 32-bit Powershell instance to take advantage of it. 

In this post we are using the .NET Npgsql data provider which gives us some advanced postgres specific functionality while leverage whichever version of .NET/postgres that the provider versions support.

I will demonstrate how to get the Powershell vPostgres module working, create databases, tables, insert rows, and select from these rows.

This module was developed in Powershell 3, and wasn’t tested backwards to version 2.  If you’re not on version 3 yet, get there =) This should work under v2 as well however.

 

Setting Up vPostgres

Deploy vPostgres/Postgres

If using vPostgres vApp (assuming you have deployed the vApp), then the next step is to set the database password.  You can see from the following console screenshot of the vPostgres VM, that the /opt/aurora/sbin/set_password can be used to set the password once logged in.  The default password to login would be shown on the console if not set.

image

 

Ensure network access to Postrgres is open (optional)

There is a file in vPostgres vApp, pg_hba.conf, which is standard for postgres.  It is available at /var/vmware/vpostgres/9.1/pgdata/pg_hba.conf and can be edited to modify the type of network connectivity available to the postgres database.  In this case, since powershell is initiating DB requests, the powershell system would need network access.  An example of a wide open statement would be something as follows.  The default for vpostgres, should be open for md5 connections, but the below line could be added if you are having problems.

host all all 10.0.0.0/8 trust

Download Approriate Npgsl Version and Copy DLLs

The DLLs are available from the following link here.  If using Powershell 3 (hopefully) you will need the .NET 4 64-bit version.  There are two DLLs that are necessary Npgsql.dll and Mono.Security.Dll.  Once the data provider is installed, these should be located and copied into a folder that will contain the vpostgres.psm1 powershell module.  The next step is to unblock these DLLs (security feature in Pshell3).  This can be done by right clicking each dll and selecting properties, followed by Unblock at the bottom.  As well, you can use the Unblock-File cmdlet (Get-Item file | Unblock-File).

 

Download Unofficial vPostgres Powershell module

This module is available at the following link here.

 

Running

If all is good on the previous install steps then you should have these three files together in a directory. 

image

 

Load the module

From Powershell — Dir vpostgres.psm1 | Import-Module

This command should load the vPostgres module.  If there are no errors, then you are good to go.  You can run (get-command -module vpostgres) to see the commands available.

image

 

Connecting to vPostgres

Awesome, so now it’s time to connect to a vPostgres database!

The following command will connect to the database without specifying a database or port.  I am assuming here, that you don’t have one created yet to use. 

Connect-vPostgres -server ip/name -username postgres -password password  -database ” -port ”

image

If this works without error, then you’re good to go.  If there is an error it is most likely an authentication, connectivity, or pg_hba issue for network access.  Once connected I already issue a “select 1=2” to verify that we can talk with the database.

Notice that we also leverage the $vPostgresConnection global variable as a hash table to provide the ability to connect to multiple vPostgres instances as the same time.  We then issue $vPostgresConnection.”name” to retrieve said connection for use.

 

Creating a Database (test)

I am assuming that you need to create a database to use here.  If not then feel free to skip this part.

Get-vPostgresDataSet -connection $vPostgresConnection."ip/name" -query "CREATE DATABASE test WITH ENCODING=’UTF8′ OWNER=postgres;"

The command above will create the database, if nothing is returned then you’re good to go.  Notice how we use the connection parameter, this isn’t needed if we want to specify the connection details to this cmdlet.  See the module parameters.

 

Creating a table on test DB

Since we created the database, let’s reconnect to the vPostgres instance while specifying the database so that all of our following queries have the appropriate context set.

Connect-vPostgres -server ip/name -username postgres -password password -database test -port ”

If creating a new database, then we can create a table of name log with this command.   This table has two columns, a serial column which increments per entry, and a text field for hold an unlimited of text information.  This post isn’t meant to teach DBA basics, so google it if you’re scratching your head here =)

Get-vPostgresDataSet -connection $vPostgresConnection."ip/name" -query "CREATE TABLE log (id bigserial PRIMARY KEY,text TEXT)”

If there is no output, then all is good.  You can also issue a “SELECT * FROM log” in a following statement which should yield no results as well since the table is blank.

 

Create an Index (optional)

How about an index to speed up queries that leverage certain columns?  Again no DB expert, but you can look this up as well in plenty of places.

Get-vPostgresDataSet -connection $vPostgresConnection."ip/name" -query "CREATE INDEX ix_log_id ON log (id)”

 

Insert a Row

Now that we have a table and an index created, the next step would be to populate our table with a row.  There are three commands that I am running below.

image

In order to leverage a insert method that limits sql injection capabilities we can use handy sql parameters.  This means that we specify a PsObject with name=value’s which then get replaced after I submit the insert statement.

Here we create a PsObject with our name as the column name, and value as what should be inserted.

$SqlParam = New-Object -type PsObject -property @{text="testing"}

 

Now we do the insert, notice how the TEXT column name is used as (text) for the destination column, and the 1st position of (@text) with a @ symbol which then gets replaced by what’s in my PsObject “text” value field.  You can always forego the sqlParam and create an exact SQL statement where (@text) would be (‘testing’) instead.

Get-vPostgresDataSet -connection $vPostgresConnection."ip/name" -query "INSERT INTO log (text) VALUES (@text)" -sqlParam $sqlParam

 

If all is good, then let’s do a SELECT to see if the row is there!

Get-vPostgresDataSet -connection $vPostgresConnection."ip/name" -query "SELECT * FROM log" -sqlParam $sqlParam

 

Ok, so if the results look like what is in the screenshot from above then you’re good to go.  Your ID should be 1 and not 2 as I show.  I issued a “TRUNCATE TABLE LOG” prior to clear out a prior row.

 

Well that’s it for the basics!  If you’ve gotten this far, then Powershell is jiving with Postgres!

 

A Bit More Advanced

Bulk Copy Between Postgres Instances

So I mentioned earlier advanced functionality right?  Well here is something that is rather cool.  Say I have a bulk copy that needs to be performed between two distinct postgres databases (data pump).  Typically you might buy a commercial product to perform this operation.  However, since we are using the .NET data providers for Postgres we can use the advanced capabilities here.

There is a cmdlet called Copy-PostgresDataset which would be leveraged once you have established connectivity to both source and destination Postgres instances.  It would then initiate a binary copy with the Powershell system being the middle man to pump the binary data from one Postgres system to another.  The requirement here of course is that you have a table created already that has a proper schema that matches the initial table.

Copy-PostgresDataset -srcConnection $srcserver -dstConnection $dstserver -srcCommand "COPY (SELECT * FROM srctable) TO STDOUT" -dstCommand "COPY dstTable FROM STDIN"

 

Seems complex right?  Yeah, remember I am talking about between Postgres instances.  Another option here would be to consume each row into a PsObject and then do individual inserts per PsObject into the target database.  This option however is exponentially slower than a binary copy method.

 

Postgres Heroku HStore

This one is really cool!  A Hstore if you haven’t heard of it is a module in Postgres that allows for simple key->value lookups.  You can leverage this by enabling the hstore module, and then turning any column in a table into a Hstore column.  This then allows you to have that column have any number of key->value pairs which allow for schema-less insert’s and following lookups.  This is the ultimate lazy-dba tool!  Possibly no schema definition ahead of time!

There is a cmdlet in the module, Get-PostgresHstore, which can be used but let’s save this for another post!

 

 

Anyways, plenty more you can do with this.  Take a look at the data provider docs, and have fun!

Backing Up ALL vCD Configuration

Posted by vele1655 | Posted in Automation, Powershell, vCloud Director | Posted on 15-10-2012

Tags:

0

In continuing with the recent theme, this post will focus on leveraging previous work in order to backup vCD configuration.  The configuration I am referencing here is simply the XML that is retrievable from VMware vCloud Director’s REST interface per object type.  For example, a VApp has a configuration XML file that represents the capabilities, virtual machines, and other configurable items.  It is this file that can be used as reference at a later time in case a recovery is needed. 

Previous posts have showed how to export the XML of a vCD object, and in this post we will take it a step further and allow you do to all objects, single, or multiple types of objects from one simple cmdlet.

We will then take the output of these objects and store them in a way that is similar the structure of the API calls themselves.  This is important as it later allows us to use this as a historical view that is similar to the native API calls but cached for later use.

The following screenshot shows that we have a structure built within the “101512” directory that beings with API.  As you drill through each level you can see we have expanded externalnet, networkpool, and providervdc.  On the top right you can see we have selected the providervdc directory and are showing the xml file that was saved for a specific provider with this GUID.  Along with that if the provider had links, we have downloaded those as well and included separate directories.  In this case you can see the “availableStorageProfiles” as another sub-element.

 

image

 

What vCD queries does this currently work with?  This list below is based on the Query cmdlet that I use, Search-Cloud. 

AdminCatalog, AdminCatalogItem, AdminGroup, AdminOrgNetwork, AdminOrgVdc, AdminUser, AdminVApp, AdminVAppNetwork, AdminVAppTemplate, AdminVM, Catalog, CatalogItem, Datastore, ExternalNetwork, Group, Host, NetworkPool, Organization, OrgNetwork, OrgVdc, Portgroup, ProviderVdc, Right, Role, User, VApp, VAppNetwork, VAppTemplate, VirtualCenter, Vm

 

How can I run this?  First check with the previous posts.  Look at the pre-requisites, download the script, and test it out!

Rolling Back Objects in vCloud Director

What Changed- vCloud Director Integrity Scripts Unleashed

Backing Up All vCD vApp Configurations

 

Powershell Module available http://velemental.com/wp-content/uploads/2012/10/custom_vcd_cmdlets2_101612.zipHere.

 

Once you are good there, you can continue to actually running the new Backup-vCD cmdlet.

 

Backup-vCD

This cmdlet receives a couple of inputs.  The first being the QueryType which allows you to be more granular per QueryType (listed above) or simply enter “Any” to receive objects from all queries.  The second important parameter is the “OutDirectory” parameter which defaultly uses “.” but can leverage any directory you specify to store the root of the output “api” and everything forward.  This can allow for a form of archiving each run of the cmdlet.

 

Backup-vCD -QueryType All

image

 

Backup-vCD -QueryType NetworkPool -Verbose

If you’re curious about what is happening during the run you can always use the -verbose parameter.

image

 

Backup-vCD -QueryType NetworkPool,VirtualCenter -Verbose

image

 

What are the downsides here?  The process is single threaded so if you have a massive amount of information, you may need to multi-thread the process by selecting some of the bigger download items (vapp,vm) as separate cmdlet runs on different systems or on the same system.  Also keep in mind that we do not issue a call to vCD to pause configuration changes, so as we download the information from the API it is possible certain things (VMs in vApp for example) do not reflect each other since a VM configuration may have changed during backup time. 

Backing Up All vCD vApp Configurations

Posted by vele1655 | Posted in Powershell, vCloud Director | Posted on 12-10-2012

Tags:

2

This is going to be a quick post showing how you might backup your vApp configurations per organization.

See the following posts that describe some of what we are using here.

Permanent Link to Rolling Back Objects in vCloud Director

Permanent Link to What Changed- vCloud Director Integrity Scripts Unleashed

 

This is actually extremely simple!  The idea would be to backup the VMs using a standard vSphere backup method and then to use a dedicated Windows Host and backup the vCD configuration Xml files as well.  This gives you not only the VMs, but how they were configured in the case you need to do a recovery.  See the following simple example.

 

Backing up all vApps in an Org and saving them locally

Get-Org BRS-vLab-Eng | Get-CIVApp |  %{ $VApp=$_; $VApp | Export-CIXml | Out-File "$($VApp.name).$($VApp.org).vCD.xml" }

image

 

Now let’s take a look at one of those files!

 

(


(gc .\vApp1.BRS-vLab-Eng.vCD.xml)).VApp

image

 

As you can see, the whole vApp structure can be navigated.  So if you have any questions about how something was configured, what id a VM was, or any number of things you can find it easily!  You can also take those files, zip them up, email them or any number of different things since they live on a Windows host. 

This stuff is truly the tip of the ice berg, enjoy!