PowerShell script exchange
Post Reply
lidergraf
Novice
Posts: 4
Liked: never
Joined: Sep 20, 2013 12:57 pm
Full Name: Miguel Viana
Contact:

Export log file after backup complete

Post by lidergraf »

Hello,

I'm using Veem Backup & Replication 7 and I would like to know if there is a way to automatically export, to a specific location, the backup log result files after completion. Is there a way to retrieve this info from BPjobsessions table via custom Powershell script? Thank you all
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Export log file after backup complete

Post by veremin » 1 person likes this post

Hi, Miguel.

You should write and specify as a post job activity a simple PS script that, using Copy-Item commandlet, will copy corresponding backup logs to a given location, once the backup job is finished. The location where backup logs are stored depends on OS:

• Windows Server 2003: %allusersprofile%\Application Data\Veeam\Backup
• Windows Server 2008 and R2: %allusersprofile%\Veeam\Backup
• Linux servers: /var/log/VeeamBackup/

Otherwise, you can use the following script in order to get information regarding last job session; similar to the one that can be seen in the job statistics. This information can be then re-directed to whatever file you want via “>>” method:

Code: Select all

asnp VeeamPssnapin
$Job = Get-VBRJob -name "Name of the backup Job"
$Lastsession =  $Job.FindLastSession()
$Lastsession.Logger.GetLog().updatedrecords | sort-object starttime| Select starttime, title 
Thanks.
nefes
Veeam Software
Posts: 643
Liked: 162 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

Re: Export log file after backup complete

Post by nefes » 1 person likes this post

You can also utilize new commandlet specially designed for exporting logs.

Code: Select all

Export-VBRLogs -Job $jobname -FolderPath "C:\temp" -Compress -From ([DateTime]::Today.AddDays(-1))
That sample puts all logs for job named $jobname for the last two days into archive file at C:\temp
Please be aware that C:\temp folder should be empty.
lidergraf
Novice
Posts: 4
Liked: never
Joined: Sep 20, 2013 12:57 pm
Full Name: Miguel Viana
Contact:

Re: Export log file after backup complete

Post by lidergraf »

Thank you for your time. I used both scenarios for testing but decided to go with Nefes solutions since it seems to be the simplest and effective one.

Thanks.
lidergraf
Novice
Posts: 4
Liked: never
Joined: Sep 20, 2013 12:57 pm
Full Name: Miguel Viana
Contact:

Re: Export log file after backup complete

Post by lidergraf »

After some more testing, I realised that the above command exports all logs (since day 1) and not the last two days. I'm I doing something wrong?
nefes wrote:You can also utilize new commandlet specially designed for exporting logs.

Code: Select all

Export-VBRLogs -Job $jobname -FolderPath "C:\temp" -Compress -From ([DateTime]::Today.AddDays(-1))
That sample puts all logs for job named $jobname for the last two days into archive file at C:\temp
Please be aware that C:\temp folder should be empty.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Export log file after backup complete

Post by veremin »

I’m wondering what happens if you specify –to parameter, as well.

Code: Select all

$Job = Get-VBRJob -name "Name of the job"
Export-VBRLogs -Job $Job -FolderPath "C:\temp1" -Compress -From ([DateTime]::Today.AddDays(-1)) -to ([DateTime]::Today) 
Thanks.
nefes
Veeam Software
Posts: 643
Liked: 162 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

Re: Export log file after backup complete

Post by nefes »

lidergraf wrote:After some more testing, I realised that the above command exports all logs (since day 1) and not the last two days. I'm I doing something wrong?
As far as I know, that commandlet export all log files for corresponding job, that was touched at the specified period. There is no easy possibility to cut from the log file only strings related to specified dates, or at least I don't know any.
lidergraf
Novice
Posts: 4
Liked: never
Joined: Sep 20, 2013 12:57 pm
Full Name: Miguel Viana
Contact:

Re: Export log file after backup complete

Post by lidergraf »

v.Eremin wrote:I’m wondering what happens if you specify –to parameter, as well.
Hi. It does the same thing - complete log is exported. Unfortunately, this solution does not work for us. If there was a way to only retrieve the log, equivalent to the email notification sent, after job completion it would be great. I only need the "today" log to import to my SQL Server 2005 database. Guess that's not possible.

Thanks anyway.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Export log file after backup complete

Post by veremin »

As mentioned, it’s not possible to export only certain lines via Export-Log commandlet. So, you can either take a closer look at logger property of backup session and see what lines you might want to export from it or look for an inspiration in the following topics that are concerned with advanced PowerShell reporting:

http://forums.veeam.com/viewtopic.php?f=26&t=13422
http://forums.veeam.com/viewtopic.php?f=26&t=8925

Thanks.
nefes
Veeam Software
Posts: 643
Liked: 162 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

Re: Export log file after backup complete

Post by nefes »

Miguel, so you need a brief report of one job run, or a full log for that job run?
The first option is available with the script Vladimir posted above. You can redirect that output to file and store it in any place you want.
For the second option you could try to do the following:

Code: Select all

$target_folder = "C:\temp"
Export-VBRLogs -Job $jobname -FolderPath $target_folder -Compress -From ([DateTime]::Today.AddDays(-1))
Get-ChildItem -Recurse $target_folder -Filter "*.log" | Foreach{
    $Path = $_.FullName
    $content = (Get-Content $Path -Delimiter "===================================================================")[-1]
    $content | Set-Content $Path -Force
}
That code will cut from every log file only the last run (after last "=...=" delimeter) and remove all other runs.
Please note, that some Veeam components starts new part of log more or less frequently, so that set of logs may be not enough for troubleshooting particular situations.
Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests