Author Posts

July 29, 2016 at 3:22 pm

So I have a share where files will get dumped in to, to get backed up by BAckupExec. So I wrote a script to check if there was at least 1 file, and if there is, run the job.

That part works great, but I need to append to a CSV after every job, which files were backup up and to which tape.

I can get the log using

Get-BEJob JobName | Get-BEJobHistory -FromLastJobRun | Get-BEJobLog | Add-Content c:\logs\backup.csv

But that outputs the whole job log.

Also, it doesn't work in the context of the rest of the script.

$Targetdrive='\\share\folder'
$TargetCount=(Get-ChildItem -Recurse $TargetDrive | Measure-Object).count
If ($TargetCount -gt 1) {
Get-ChildItem -Recurse $TargetDrive | Select-Object -ExpandProperty name
Write-Host 'Its Greater. It is'$TargetCount
Start-BEJob -InputObject Sam-Archive-Full
Get-BEJob Archive-Full | Get-BEJobHistory -FromLastJobRun | Get-BEJobLog | Add-Content c:\Logs\BackUps.csv
}
Else{Write-Host 'Nothing to Backup'}

The Else is there just for testing purposes.

So if I run the script as is, nothing gets added to the CSV.

If I run the line with 'Add-Content' alone after the job is complete, it fills out.

I can't be sure how long it will be before the job is complete, so I can't add a wait to the script.

And, to reiterate, I want to avoid saving the whole log.

Thanks in advance!

  • This topic was modified 2 years ago by  Andrew.

July 29, 2016 at 4:02 pm

It has been awhile since it had to script for BackupExec so long in fact that it was with vbs and using a com object to start the jobs and get the status of backup jobs.

There is a Wait-BEJob that should allow the script to wait until the end of the job before getting the log

Start-BEJob -InputObject Sam-Archive-Full|Wait-BEJob

As for appending to a csv, you will need to parse the content of the log file to capture what you want and then add it to your csv.
You will need to provide a sample of the content and what you are looking to include.

July 29, 2016 at 4:13 pm

I am not familiar with backupexec. Does Get-BEJobLog output to text file? Will you provide a sample of log output?
The concept is to:
1. create objects from the backupexec log file
2. Filter object properties
3. Export filtered content to csv

July 29, 2016 at 5:31 pm

Ah, Wait-BEJob is exactly what I would need.

Here is the output. What I want is;

Job started: Wednesday, July 27, 2016 at 3:41:46 PM

Media Label: SB0010L6

Directory \
Directory \$RECYCLE.BIN
Directory \$RECYCLE.BIN\S-1-5-21-3576781278-737976348-346508652-10439
desktop.ini
Directory \00
Directory \00\01
01234567
01234568
01234569
Directory \System Volume Information
tracking.log



		Job server: BackupServer
Job name: Archive-Full

Job started: Wednesday, July 27, 2016 at 3:41:46 PM
Job type: Back Up and Delete
Job Log: BEX_BackupServer_00148.xml
Job Backup Method: Full

		
Drive and media mount requested: 7/27/2016 3:41:46 PM

Drive and media information from media mount: 7/27/2016 3:42:51 PM
Robotic Library Name: Robotic library 0001
Drive Name: Tape drive 0001
Slot: 5
Media Label: SB0010L6
Media GUID: {8b1927db-df1a-44a4-b6da-64b90f5dcaae}
Overwrite Protected Until: 12/30/9999 7:00:00 PM
Appendable Until: 12/30/9999 7:00:00 PM
Targeted Media Set Name: FullArchive
Keep for: 365242 Day(s)



		Job Operation - Back Up and Delete
Media operation - Append to media, overwrite if no appendable media is available.
Compression Type: Hardware [if available, otherwise none]
Encryption Type: None

		Backup Exec server is running Backup Exec version 14.2.1180.2621 with FP-4.
Agent for Windows(\\TARGET-SERVER.CORP.COM) is running Backup Exec version 14.2.1180.2621 with FP-4.

Snapshot Technology: Started for resource: "\\TARGET-SERVER.CORP.COM\F:". Snapshot technology used: Microsoft Volume Shadow Copy Service (VSS).
The snapshot technology used by VSS for volume F: - Microsoft Software Shadow Copy provider 1.0 (Version 1.0.0.7).
Network control connection is established between [FE80::305C:F23:72CF:78C1%20]:55723  [FE80::315B:FBB0:6FFD:20C2]:10000
Network data connection is established between    [FE80::305C:F23:72CF:78C1%20]:55733  [FE80::315B:FBB0:6FFD:20C2]:57564

Family Name: "Media created 7/27/2016 11:07:22 AM"
Backup of "\\TARGET-SERVER.CORP.COM\F:"
Backup set #5 on storage media #1
Backup set description: ""
Backup Method: Full - Back up files (using modified time)

Backup started on 7/27/2016 at 3:43:07 PM.
Directory \
Directory \$RECYCLE.BIN
Directory \$RECYCLE.BIN\S-1-5-21-3576781278-737976348-346508652-10439
  desktop.ini
Directory \00
Directory \00\01
  01234567
  01234568
  01234569
Directory \System Volume Information
  tracking.log
Backup completed on 7/27/2016 at 3:43:18 PM.

Backed up 5 files in 6 directories.
Processed 22,913 bytes in  11 seconds.
Throughput rate: 0.119 MB/min
Compression Type: Hardware
----------------------------------------------------------------------


		Job Operation - Verify

		
Verify of "\\TARGET-SERVER.CORP.COM\F: Sam Archive"
Backup set #5 on storage media #1
Backup set description: ""

Verify started on 7/27/2016 at 3:43:19 PM.
Directory \
Directory \$RECYCLE.BIN
Directory \$RECYCLE.BIN\S-1-5-21-3576781278-737976348-346508652-10439
  desktop.ini
Directory \00
Directory \00\01
  01234567
  01234568
  01234569
Directory \System Volume Information
  tracking.log
Verify completed on 7/27/2016 at 3:43:19 PM.

Verified 5 files in 6 directories.
Processed 22,913 bytes in  1 second.
Throughput rate: 1.31 MB/min
----------------------------------------------------------------------


		Job Operation - Delete

		Backup of "\\TARGET-SERVER.CORP.COM\F: Sam Archive "
Backup set #5 on storage media #1
Backup set description: ""

Deletion started on 7/27/2016 at 3:43:21 PM.
  desktop.ini
Directory \$RECYCLE.BIN\S-1-5-21-3576781278-737976348-346508652-10439
Directory \$RECYCLE.BIN
  01234567
  01234568
  01234569
Directory \00\01
Directory \00
  tracking.log
Directory \System Volume Information
Deletion completed on 7/27/2016 at 3:43:21 PM.

Deleted 5 files and 5 directories.
Processed 20,609 bytes in  1 second.
----------------------------------------------------------------------
14.2.1180.2621eng-no_fs-backupENRetailWindows_V-6.2.9200_SP-0.0_PL-0x2_SU-0x110_PT-0x3

		Job ended: Wednesday, July 27, 2016 at 3:43:21 PM

Completed status: Successful

  • This reply was modified 2 years ago by  Andrew.

July 29, 2016 at 7:22 pm

Here is a basic parsing

$log = gc .\test.log # this was for my testing 
# this may work for you $log = Get-BEJob Archive-Full | Get-BEJobHistory -FromLastJobRun | Get-BEJobLog
$log|Select-String -SimpleMatch -Pattern "Job started:"
$log|Select-String -SimpleMatch -Pattern "Media Label:"
$detailstart = ($log|Select-String -SimpleMatch -Pattern "Backup started on" | Select-Object LineNumber).LineNumber
$detailend = ($log|Select-String -SimpleMatch -Pattern "Backup completed on" | Select-Object LineNumber).LineNumber
$log[$detailstart..($detailend - 2)]

July 29, 2016 at 8:09 pm

Oh wow, that gave me exactly what I wanted. Still new to Powershell but man do I ever hope to get to the level that I can pop out a script like that.

A million thank yous!

July 29, 2016 at 8:24 pm

So if you have time and if you don't I totally understand, but I'm trying to understand how you got it to work.

$detailstart = ($log|Select-String -SimpleMatch -Pattern "Backup started on" | Select-Object LineNumber).LineNumber
$detailend = ($log|Select-String -SimpleMatch -Pattern "Backup completed on" | Select-Object LineNumber).LineNumber
$log[$detailstart..($detailend - 2)]

So that takes everything between Detailstart and Detailend and displays it? Minus one line, i guess?

July 30, 2016 at 10:44 am

You have the concept down. Select-string returns the line number but evaluates from line 1.

$log[$detailstart..($detailend - 2)]

This is returning the lines from the $log object as an array. Array enumeration is 0 based. You wanted a return starting with the line after "Backup started on" ending on the line before "Backup completed on". Because of the difference between select-string and array enumeration the value of $detailstart in the $log array will be one line ahead. The same goes for $detailend but because it needs to end one line before that you must subtract 2.

August 1, 2016 at 2:09 pm

You're the best, Jonathan!