Export log file after backup complete

PowerShell script exchange

Export log file after backup complete

Veeam Logoby lidergraf » Fri Sep 27, 2013 4:18 pm

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
lidergraf
Novice
 
Posts: 4
Liked: never
Joined: Fri Sep 20, 2013 12:57 pm
Full Name: Miguel Viana

Re: Export log file after backup complete

Veeam Logoby v.Eremin » Mon Sep 30, 2013 11:39 am 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.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Export log file after backup complete

Veeam Logoby nefes » Mon Sep 30, 2013 11:55 am 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.
nefes
Veeam Software
 
Posts: 534
Liked: 125 times
Joined: Mon Dec 10, 2012 8:44 am
Full Name: Nikita Efes

Re: Export log file after backup complete

Veeam Logoby lidergraf » Wed Oct 02, 2013 8:44 am

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: Fri Sep 20, 2013 12:57 pm
Full Name: Miguel Viana

Re: Export log file after backup complete

Veeam Logoby lidergraf » Wed Oct 02, 2013 10:50 am

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.
lidergraf
Novice
 
Posts: 4
Liked: never
Joined: Fri Sep 20, 2013 12:57 pm
Full Name: Miguel Viana

Re: Export log file after backup complete

Veeam Logoby v.Eremin » Wed Oct 02, 2013 11:07 am

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.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Export log file after backup complete

Veeam Logoby nefes » Wed Oct 02, 2013 11:22 am

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.
nefes
Veeam Software
 
Posts: 534
Liked: 125 times
Joined: Mon Dec 10, 2012 8:44 am
Full Name: Nikita Efes

Re: Export log file after backup complete

Veeam Logoby lidergraf » Thu Oct 03, 2013 8:36 am

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.
lidergraf
Novice
 
Posts: 4
Liked: never
Joined: Fri Sep 20, 2013 12:57 pm
Full Name: Miguel Viana

Re: Export log file after backup complete

Veeam Logoby v.Eremin » Thu Oct 03, 2013 9:43 am

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:

viewtopic.php?f=26&t=13422
viewtopic.php?f=26&t=8925

Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Export log file after backup complete

Veeam Logoby nefes » Thu Oct 03, 2013 10:19 am

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.
nefes
Veeam Software
 
Posts: 534
Liked: 125 times
Joined: Mon Dec 10, 2012 8:44 am
Full Name: Nikita Efes


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 5 guests