Free XenServer VM’s Backup Tool and PowerShell Script!

Recently I wrote a blog about XenServer and Powershell commands this blog was also published on the Citrix Blog site here. With those commands in hand I wanted to create something that can be used by everyone who uses Citrix XenServer. To mind came a PowerShell VM Backup Script (invoke-XenBackup) and a PowerShell Forms GUI tool to also schedule your Backup of XenServer VM’s. The tool has the following functions:

  • Create a backup folder with date.
  • Take a snapshot of a running or stopped VM.
  • Export the snapshot to a XVA file.
  • Optionally Zip the backup folder.
  • Optionally Email backup log.
  • Shedule a backup as a Windows Scheduled Task.
  • Run and delete scheduled backup tasks.
  • Saves your XenServer Password in a Encrypted Vault.

Download the Workspace-Guru XenServer Backup Tool.

System requirement’s:

Video tutorial

Powershell Script

The heart of the tool is a PowerShell script I created named invoke-XenBackup. The script does require the XenServer PowerShell module installed. The GUI Tool will do this automatically. To do this manually download the PowerShell module here under the development section. And extract it to your PowerShell Module folder.

Example how to use the script:

Invoke-XenBackup -ExportPath “C:\Backup” -VMnames “VM01″,”VM02″,”VM03” -username “root” -password “P@ssw0rd” -XenHost “XenHost01” -LogPath “C:\Temp” -Email -SMTPServer “smtp.domain.com” -FromEmail “backup@domain.com” -ToEmail “sysadmin@domain.com” -ZIP

This will backup VM01, VM02 and VM03 from XenHost01 in C:\Backup. Username and Password are for XenHost01. After the backup the folder will be ZIP’d and the backup logfile will be send in a email to sysadmin@domain.com

Download the script as a RES / Ivanti Automation Building Block from the RES HUB.

I hope this was informative. For questions or comments you can always give a reaction in the comment section or contact me:

22 thoughts on “Free XenServer VM’s Backup Tool and PowerShell Script!

  1. Excellent work Chris!

    When importing a backed up VM it is restored as a template, what in most cases is not wanted. This can be avoided by setting the following parameters, at line 133, before exporting the snapshot .

    Set-XenVM -Uuid $SnapshotUuid -IsATemplate $false -HaAlwaysRun $false

  2. Hello ,,,I am really new at this, do not even know how to write a script on any language, but I am really thankful I found this website. I have tried the backup tool on my server, I see the zip logs on the folder I want to send them to but I do not know where that actual snapshot went to . I do not see it under snapshots at the VM selected. Please excuse my ignorance. What am I not seeing or what am I doing wrong.

    1. Hi Frank,

      Cool that you found the tool! The tool will copy the snapshot to the export path you selected after that it will delete the snapshot. You can send the logs to Chris.twiest@dtncomputers.nl. That way I can help some more.

  3. Hi Chris,
    I’ve been having issues when backing up my XenServer VMs. Your software issued to work fine but it stopped with no reason. I create a task with it but it does not run it and i don’t know where to find the logs.
    Any help would be appreciated.

    Thanks

    1. Hi David,
      You can find the logs at “C:\ProgramData\Workspace-Guru\XenServer-Backup”.
      If you open the application and try a new backup with “Run Backup NOW” you will get the most info in the log.

      Hope this helps you can always send me the logs: Chris.twiest@dtncomputers.nl

      1. Thanks.

        Does the software copy the VMs to local PC and then to the NAS (if using?).
        I noticed that the VM responsible for the backups loosing the storage space when the backup used to started.

        1. The software exports the snapshots (backups) to the backup path. This must be a local storage to the vm so it can be iscsi lun etc.

          1. Hi Chris,
            It would be good to add the feature of exporting VMs directly to a network path. May this be NAS or any sort. Export to external drive could be a plus too.

            Your software is a very good, and free. It could even be used in a corporate place.

          2. Thank you and a Version 2 of the tool is in the making with network drive support. And maybe some more features;)

  4. I get the following error on backup and I don’t see script folder being populated with .ps1 files of program data\workspace-guru\xenserver backup in my lab testing and I am authenticating to pool-master –

    The property ‘Pool’ cannot be found on this object. Verify that the property
    exists and can be set.
    At line:1025 char:5
    + $Pools.Pool = $PoolMaster
    + ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

    0
    1
    2
    3
    4
    5

    Directory: C:\ProgramData\Workspace-Guru\XenServer-Backup

    Mode LastWriteTime Length Name
    —- ————- —— —-
    d—– 8/6/2018 11:31 AM Backup_Logs

    Directory: C:\ProgramData\Workspace-Guru\XenServer-Backup\Backup_Logs

    Mode LastWriteTime Length Name
    —- ————- —— —-
    -a—- 8/6/2018 11:31 AM 0 XenBackupLog_2018-06-08-11-31-
    17.txt
    2018-06-08-11-31-17 — Start Backup

    Directory: E:\backup

    Mode LastWriteTime Length Name
    —- ————- —— —-
    d—– 8/6/2018 11:31 AM XenBackup-2018-08-06

    Directory: E:\backup\XenBackup-2018-08-06

    Mode LastWriteTime Length Name
    —- ————- —— —-
    d—– 8/6/2018 11:31 AM lab-app-srv
    Export-XenVm : There is not enough space on the disk.

    At line:764 char:5
    + … Export-XenVm -Uuid $SnapshotUuid.uuid -XenHost “$XenHost” …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Export-XenVm], IOException
    + FullyQualifiedErrorId : System.IO.IOException,Citrix.XenServer.Commands.
    ExportXenVmCommand

    Directory: C:\ProgramData\Workspace-Guru\XenServer-Backup\Backup_Logs

    Mode LastWriteTime Length Name
    —- ————- —— —-
    -a—- 8/6/2018 11:44 AM 0 XenBackupLog_2018-06-08-11-44-
    05.txt
    2018-06-08-11-44-06 — Start Backup

    Directory: E:\backup

    Mode LastWriteTime Length Name
    —- ————- —— —-
    d—– 8/6/2018 11:44 AM XenBackup-2018-08-06

    Directory: E:\backup\XenBackup-2018-08-06

    Mode LastWriteTime Length Name
    —- ————- —— —-
    d—– 8/6/2018 11:44 AM lab-app-srv

    1. Hello Prasant,

      You can ignor the pool error. The backup fails because: Export-XenVm : There is not enough space on the disk. I don’t know why you won’t get a script in the folder did you schedule the task correctly with enough rights?

  5. Chris… I am using run backup now before trying the schedule. I assigned full permission on user account I am logged in with and modify access to everyone for test and still failing

      1. Chris,

        First off, thank you for doing all of the leg work in putting this together. I’m having a similar issue to Prasamt; I’m running out of disk space. In monitoring the process, it looks like I’m running out of drive space on my C:\ drive on the VM where the script is running. I’ve specified another drive (E: in this case) for the backup destination and for the logging. It seems as if the backup gets written to C: and then copied to E; small VM’s backup with no issue, whereas larger ones fail when C: runs out of space.

        Are there default locations that Citrix XenServer Powershell uses for temp or operating locations?

        Any help would be appreciated.

        Thanks again!

        1. Thank you for figuring that out! I will have to look in to that. I’m busy with v2 of the tool. Will take a look at this!!

          1. I found the issue. It is with PowerShell in general, not necessarily your script. If you change the environmental variable ($env:TMP) to a location with sufficient space everything works as expected. The default location is:

            C:\Users\%username%\AppData\Local\Temp

            In my specific case, I added a two statements just before the Invoke-XenBackup command in the ps1 file for the job:

            $env:TMP = “E:\TEMP”
            $env:TEMP = “E:\TEMP”

            This forces PowerShell to use E:\TEMP as the temp location to copy the snapshot prior to writing to the location specified in your script. Using this location, I had ample free space to backup all of the VM’s in my pool.

Leave a Reply

Your email address will not be published. Required fields are marked *