Home > Citrix, PowerShell Scripting, XenApp > Backup, Restore and Reset your XenApp 6 farms with powershell.

Backup, Restore and Reset your XenApp 6 farms with powershell.

All good organizations should have at least one test XenApp farm, for testing changes before reaching your production environment. But quite often either changes made to the test environment are forgotten or changes to production are forgotten and your test environment goes from being a mirror of production, to differentiated and useless testing grounds.

Keeping the environments aligned is a needle and haystack event as you try to compare each policy, application and worker group manually and often by eye. Sometimes its just easier to rebuild the farm from a template of production.

I wrote the following PowerShell Module to overcome this differentiation over time by giving the support guys the ability to completely wipe a XenApp farm and re-import the production settings before beginning a test.

The basic process to this module is backup production, wipe test then restore to test. Below you will find all the neccessary information, the caveats and warnings around using these modules.

Thanks are due to @neilspellings and @kbaggerman for looking over the code and for the feedback.

Be warned, I wont be held responsible if you accidentally wipe your production farm. Always use backup-xafarm before you run reset-xafarm, regardless of the environment.

The following items are out of scope of this project:

  • Configuration logging is out of scope.
  • *Zone configuration is out of scope.

* zone configuration isn’t out of scope due to lack of interest, more out of lack of support in PowerShell to do so.

The following are necessities for this script to work:

  • All of your Xenapp applications must be published to worker groups, not individual servers.
  • you must run these commandlets from a XenApp server, running the management console to ensure you have access to the powershell snapins required.

Known issues:

  • The policy backups and restore take an age, this isn’t my code so I cant fix this. Grab a coffee while it runs.

Modules:

This powershell module is available in two formats:

1: The complete script, including the modules neccessary from the Citrix.GroupPolicy.Commands.psm1 module which I borrowed to from Citrix.

You can Download this here.

2: The Basic script, this script includes just my code and relies on you having to import the above module before running my module.

You can download this here.

A note for Citrix, I borrowed your module and included the code in the complete script to make this a complete solution. If you are unhappy with this in any way let me know and I’ll remove this module.

This module has three core components:

  • Backup-xafarm
  • Reset-xafarm
  • Restore-xafarm

Importing the module:

Simply copy the module to a local disk (to remove script signing prompts which you receive from network locations) and run the command you require depending on the module you wish to use:

1: Complete Module:

import-module .\Citrix.XenApp.Backup.psm1

2: Basic Module:

import-module .\Citrix.GroupPolicy.Commands.psm1
import-module .\Citrix.XenApp.Backup.Basic.psm1

Follow the jump below to find a breakdown of the commands and how to use them:

Backup-xafarm

Example: backup-xafarm -exportdirectory \\server\share

Backup-xafarm is to be run on your source aka your production farm. This command will check your current farms configuration and if it detects a problem it will alert:

Assuming no problems were detected, it will then attempt to export the following items to a shared data directory:

  • Administrators
  • Folders
  • Applications
  • Load evaluators
  • Worker Groups
  • Load Balancing items
  • Policies

The export directory can be a shared or local folder, once the backup is complete the folder should appear as below:

Once the script completes, you can move this folder (if local) to the target farm for import.

Reset-xafarm

Example: Reset-xafarm -Force

Reset-xafarm is to be run on your target farm aka your test farm. This command will completely destroy your farm configuration, wiping out all items that are backed up by backup-xafarm and assigning only the user running this script administration access to the Farm.

For this reason a -Force switch has been included to make sure you want to do this. If you do not provide the -force, you’ll be warned and the command will close:

When using the -force command, the process will run:

Restore-xafarm

Example: restore-xafarm -importdirectory \\server\share

Restore-xafarm is to be run on your target farm aka your test farm. This command will import the contents from a backup-xafarm and attempt to apply it to your test farm. This command should be run after a reset-xafarm to ensure consistency.

Once the restore is complete, you should need onto to populate the worker groups and move the XenApp servers to the correct folders if neccessary.

These tasks can be scripted quite easily and I’d be happy to show examples of how to complete this last step if you need it.

Thats it! happy powershelling.

  1. Colin Hill
    March 7, 2013 at 12:14 pm

    great script but 1 major issue for me. We publish a desktop for all of our servers for app support teams. To run this on our Prod farm I would have to have a Worker Group for every server as it currently fails saying applications published to servers are not supported. With over 150 servers this will never happen in our enviroment. Is there either a way I can back these up or exclude the desktop folder when recursing the applications?

    • March 7, 2013 at 9:59 pm

      Hi Colin,

      Absolutely, that check could be turned off in the code. I’m slammed at the moment and will be for a few weeks so feel free to remove if yourself knowing it shouldn’t break anything.

      A

  2. Mayur
    March 15, 2014 at 6:42 pm

    Hi Andrew, I this is quite an old post which I came across while searching the net for ideas and concepts of how to replace the complexity of using PVS when used for single image management in a XenApp 6.5 farm.

    I currently deploy my Xenapp servers unattended in a 4/5 stepped process:

    1. Deploy Windows OS
    2. Install XenApp 6.5 and join farm
    3. Install applications
    4. Add new XA server into a Worker group
    5. Optionally Add new publish applications and user permissions.

    At present I apply Windows and applications updates using scripts which run sequentially through each xenapp server. If a new application needs to be added it gets installed silently at the same time. All the Xenapp servers are identical in build and applications to provide good DR recover-ability, better use of the resources and scalability and minimize profile corruption etc.

    I am seeking ideas on how I could transform the process of updating the Windows patches and applications updates/additions using my automation method.

    What I had in mind but not as yet tested in lab is if I could script the process in such a way that each time there are Windows updates requiring to be added to the farm servers I simply rebuild the farm from scratch. Off course this would require some form of staging and testing before running it in production. Many years back I have used a tool from VisionApp which did exactly this.

    Is this something worth spending time on or there is an easier method that you can think of to achieve the same goal.

    Thanks
    M

    • March 18, 2014 at 6:53 pm

      I recommend RES automation manager or frontrange DSM if you want I automate the entire process. Doing so from powershell would be a lot of work.

      • Mayur
        March 18, 2014 at 8:19 pm

        Yes, I agree using PoSH can be messy and hard to maintain. I have thought about trying PVS but the cost of Platinum license, complexity of its many moving parts does not warrant its useability for smaller Xenapp environments.

        I would be grateful to get an overview of what would be involved in terms of initial setup and ongoing maintenance to use RES AM or Frontrange DSM. I had downloaded a trial of RES AM a while ago but never got round to setting it up. Any whitepapers or step by step docs I can review would be very helpful.

        The thought also crossed the mind of perhaps looking at using SCCM and Config Manager 2007 plugin for XenApp to automate the deploying of new apps and Windows updates but not sure what is involved in using it from a complexity/knowledge/skills standpoint.

      • March 18, 2014 at 8:21 pm

        Check out Barry Schiffers AIM for some good scripts and automation framework: http://www.barryschiffer.com/aim-toolkit/

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: