XCP-ng
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Powershell script for backup summary reports

    Scheduled Pinned Locked Moved Backup
    7 Posts 4 Posters 147 Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T Offline
      tmk
      last edited by

      I recently developed a PowerShell script that fills a need that I couldn't find with the built-in reporting options for Xen Orchestra backups.

      The script is available on GitHub, It works with PowerShell 7 (if using self-signed certs and using the SkipCertificateCheck parameter), otherwise it may work with Windows Powershell 5, I just didn't get a chance to test that yet.

      Repository: https://github.com/codekeller/XO-PS-Scripts/tree/5ed1ce9915a41b266af6db54e29236e6f4265143/Xen Orchestra Backup Report

      The script connects to your Xen Orchestra server via REST API and generates HTML reports that combine:

      Complete backup job inventory - Shows all configured VM backups, metadata backups, and replication jobs

      Execution status correlation - Matches job definitions with recent execution history to show what's actually running vs. what's configured

      Professional reporting - Clean HTML output with a list of all configured backups jobs and their most recently run status within the last 24 hours (configurable)

      Automated delivery - Optional email integration for scheduled reporting

      Why I Built This

      Managing backup jobs across multiple pools and sites, I found myself constantly logging into XO to check backup status and manually correlating job definitions with execution results. This script automates that entire process and provides the kind of professional reports that management actually wants to see.

      Sample Output

      sample_report_screenshot.png

      The reports include a summary showing success/failure counts, job definitions organized by type with current status, and detailed execution logs with timing information. The HTML is optimized for both email delivery and web viewing.

      The README includes detailed documentation and real-world usage examples. I've also included sample reports so you can see exactly what output to expect.

      Getting Started

      Basic usage is straightforward with additional options available:

      .\Get-XenOrchestraBackupReport.ps1 -XenOrchestraUrl "https://xo.company.com" -ApiToken "your-token" -OutputPath "backup-report.html"
      

      Would love feedback from the community

      1 Reply Last reply Reply Quote 4
      • P Offline
        Pilow
        last edited by

        seems neat... but can't auth... it says my token is not good

        === Enhanced Xen Orchestra Backup Report Generator ===
        Starting backup job definitions and execution status retrieval...
        [2025-09-25 23:51:16] [Information] Script execution started
        [2025-09-25 23:51:16] [Information] Using API token provided via command line parameter
        [2025-09-25 23:51:16] [Information] Connecting to Xen Orchestra at: https://10.<redacted>
        [2025-09-25 23:51:16] [Information] Testing authentication...
        Write-Log : [2025-09-25 23:51:16] [Error] Script execution failed: Failed to authenticate with Xen Orchestra using
        provided API token
        Au caractère E:\Téléchargements\Get-XenOrchestraBackupReport.ps1:1825 : 5

        • Write-Log $errorMessage -Level Error
          
        • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          
          • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
          • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Write-Log

        Script execution failed: Failed to authenticate with Xen Orchestra using provided API token
        Write-Log : [2025-09-25 23:51:16] [Error] Stack Trace: à <ScriptBlock>,
        E:\Téléchargements\Get-XenOrchestraBackupReport.ps1 : ligne 1658
        à <ScriptBlock>, <Aucun fichier> : ligne 1
        Au caractère E:\Téléchargements\Get-XenOrchestraBackupReport.ps1:1829 : 9

        •     Write-Log "Stack Trace: $($_.ScriptStackTrace)" -Level Error
          
        •     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          
          • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
          • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Write-Log

        Failed to authenticate with Xen Orchestra using provided API token
        Au caractère E:\Téléchargements\Get-XenOrchestraBackupReport.ps1:1658 : 13

        •         throw "Failed to authenticate with Xen Orchestra using pr ...
          
        •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          
          • CategoryInfo : OperationStopped: (Failed to authe...vided API token:String) [], RuntimeException
          • FullyQualifiedErrorId : Failed to authenticate with Xen Orchestra using provided API token

        I tried with token created by the XOA ui, and by xo-cli
        either way i'm a global admin of XOA with my user

        ?

        1 Reply Last reply Reply Quote 0
        • olivierlambertO Offline
          olivierlambert Vates 🪐 Co-Founder CEO
          last edited by

          Adding @Team-DevOps in the loop

          1 Reply Last reply Reply Quote 0
          • P Offline
            Pilow
            last edited by

            I'm on PWS 5.1, here is the debug log. 5.1 is the culprit ?

            [2025-09-25 23:59:46] [Information] Script execution started
            [2025-09-25 23:59:46] [Debug] PowerShell Version: 5.1.26100.6584
            [2025-09-25 23:59:46] [Information] Using API token provided via command line parameter
            [2025-09-25 23:59:46] [Information] Connecting to Xen Orchestra at: https://10.
            [2025-09-25 23:59:46] [Information] Testing authentication...
            [2025-09-25 23:59:46] [Debug] API Call Attempt 1: GET https://10./rest/v0/vms
            [2025-09-25 23:59:46] [Debug] Configuring custom SSL certificate validation (PS 5.1)
            [2025-09-25 23:59:46] [Debug] Cookie authentication failed, trying Bearer token...
            [2025-09-25 23:59:46] [Debug] API Call Attempt 1: GET https://10./rest/v0/vms
            [2025-09-25 23:59:46] [Debug] Configuring custom SSL certificate validation (PS 5.1)
            [2025-09-25 23:59:46] [Error] Script execution failed: Failed to authenticate with Xen Orchestra using provided API token
            [2025-09-25 23:59:46] [Error] Stack Trace: à <ScriptBlock>, E:\Téléchargements\Get-XenOrchestraBackupReport.ps1 : ligne 1658
            à <ScriptBlock>, <Aucun fichier> : ligne 1
            [2025-09-25 23:59:46] [Debug] Script cleanup completed

            T P 2 Replies Last reply Reply Quote 0
            • T Offline
              tmk @Pilow
              last edited by tmk

              @Pilow I was using Powershell 7. If you are using a self-signed certificate on the XOA server then you'll have issues as the -SkipCertificateCheck parameter isn't available for the Invoke-RestMethod command in Powershell 5.

              1 Reply Last reply Reply Quote 1
              • P Offline
                Pilow @Pilow
                last edited by

                ok, installed pws 7
                4e7c572d-58a4-43bc-8ff6-e61392b51f96-{85124A49-D73A-4EAC-89AE-A7E5617B7933}.png

                and it's working 😃
                6bc0e495-1595-4933-a725-14fc24972b67-{805EF050-DDDB-4C14-ACFD-ADE7ED6420E6}.png

                CyrilleC 1 Reply Last reply Reply Quote 1
                • CyrilleC Offline
                  Cyrille Vates 🪐 DevOps Team @Pilow
                  last edited by

                  Whoo this looks very nice! Thank you for sharing this tool with us!

                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post