none
Pipe output of Backup-SPFarm to a file RRS feed

  • Question

  • Hi,

     

    I'd like to grab the output of Backup-SPFarm to a file for logging purposes but I can't get it to work. I've tried several options but with no success (the file is created but it doesn't have any content after the backup is finished):

    PS: c:\> .\backup.ps1 | out-file c:\temp\backup_log.txt
    PS: c:\> .\backup.ps1 > c:\temp\backup_log.txt
    PS: c:\> Backup-SPFarm -Directory c:\backups\ -BackupMethod Full -Verbose > c:\temp\backup_log.txt

    This is a scheduled backup in the middle of the night and  I need to grab the output to verify that the backup has went well. 


    Lumbago www.thefirstsql.com
    Friday, June 25, 2010 11:03 AM

Answers

  • Have you looked at the spbackup.log file in the directory created by the backup process? It should contain the data that you're looking for from the backup process.

    The backup script I'm currently trying to get finished up does a scan of that file after a backup to determine if there are any errors in it or not...here's the code I use to make that check (please note that there's some variables and functions referenced in this block that come from elsewhere in the script, it won't work for you verbatim):

      # Get the most recently modified backup folder
      $newestFolder = (Get-ChildItem -path $backupDir | Sort -property LastWriteTime `
                      | Select-Object -last 1 -property FullName | format-table `
                      -hidetableheaders | out-string| foreach { $_.trim() } )
                     
      # Build the file path for the most recently created backup log file
      $newestLog = Join-Path -path $newestFolder -childpath "spbackup.log"
     
      # Getting the number of errors in the backups log file
      #  (subtracting 1 for the reporting line at the end of the document)
      $errorLog = Get-Content $newestLog | Out-String
      $errorCount = [regex]::matches($errorLog,"error").count - 1
     
      # If there is an error, report it
      If ($errorCount -gt 0)
      {
       # Create Error Message
       $eventMsg = $eventMsg + "At least one error was found while making a " `
           + $backupMethod + "backup, stored in the " + $newestFolder + "directory. " `
           + "Please review the spbackup.log file in that directory carefully to " `
           + "diagnose and resolve the issue before running another backup."
          
       # Report an error
       Record-Event -eventMsg $eventMsg -entryType "Error"

       # Set the Error flag to "On"
       $errorFlag = 1

     

    John


    MCTS: WSS v3, MOSS 2007, and SCOM 2007

    Now Available on Amazon - The SharePoint 2007 Disaster Recovery Guide. Coming Soon - The SharePoint 2010 Disaster Recovery Guide.
    My blog: My Central Admin.
    Friday, June 25, 2010 12:40 PM

All replies

  • Have you looked at the spbackup.log file in the directory created by the backup process? It should contain the data that you're looking for from the backup process.

    The backup script I'm currently trying to get finished up does a scan of that file after a backup to determine if there are any errors in it or not...here's the code I use to make that check (please note that there's some variables and functions referenced in this block that come from elsewhere in the script, it won't work for you verbatim):

      # Get the most recently modified backup folder
      $newestFolder = (Get-ChildItem -path $backupDir | Sort -property LastWriteTime `
                      | Select-Object -last 1 -property FullName | format-table `
                      -hidetableheaders | out-string| foreach { $_.trim() } )
                     
      # Build the file path for the most recently created backup log file
      $newestLog = Join-Path -path $newestFolder -childpath "spbackup.log"
     
      # Getting the number of errors in the backups log file
      #  (subtracting 1 for the reporting line at the end of the document)
      $errorLog = Get-Content $newestLog | Out-String
      $errorCount = [regex]::matches($errorLog,"error").count - 1
     
      # If there is an error, report it
      If ($errorCount -gt 0)
      {
       # Create Error Message
       $eventMsg = $eventMsg + "At least one error was found while making a " `
           + $backupMethod + "backup, stored in the " + $newestFolder + "directory. " `
           + "Please review the spbackup.log file in that directory carefully to " `
           + "diagnose and resolve the issue before running another backup."
          
       # Report an error
       Record-Event -eventMsg $eventMsg -entryType "Error"

       # Set the Error flag to "On"
       $errorFlag = 1

     

    John


    MCTS: WSS v3, MOSS 2007, and SCOM 2007

    Now Available on Amazon - The SharePoint 2007 Disaster Recovery Guide. Coming Soon - The SharePoint 2010 Disaster Recovery Guide.
    My blog: My Central Admin.
    Friday, June 25, 2010 12:40 PM
  • Backup-SPFarm does not output logs into command line. You should check the log files as John said.

    Saturday, June 26, 2010 3:39 AM