Offload Backups to Tape

PowerShell script exchange

Offload Backups to Tape

Veeam Logoby dannythake » Tue May 28, 2013 9:38 am

Good Morning all,

I am running B&R 6.5, using the following backup method:

Saturday: Active Full
Monday - Thursday: Incremental

Has anyone got a tested powershell script to offload the backups to tape using BE2012/BE2010 so that on a full backup a post job runs to backup only that file, but then each run of incremental run will offload to tape aswell as any other incrementals since the last full backup?

For Example:

Saturday "Full Active" > Disk > Tape
Monday "Incremental" > Disk > Tape
Tuesday "Incremental" > Disk + Monday "Incremental" >Tape
Wednesday "Incremental > Disk (+ Tuesday "Incremental" + Monday "Incremental") > Tape


The reason i want to do this is in case of tape failure. If a tape fails on the wednesday, but i have a tape on thursday that contains all the incrementals since the last full i will still be able to recover my data.

Any help will be appreciated

Thanks
dannythake
Enthusiast
 
Posts: 39
Liked: 10 times
Joined: Tue May 28, 2013 8:41 am
Full Name: Danny Thake

Re: Offload Backups to Tape

Veeam Logoby v.Eremin » Tue May 28, 2013 11:52 am

Even though, I’m not familiar with Backup Exec commandlets, I can describe in detail the algorithm that should be used:

1. Get actual day number.
2. Check whether the day number is 6 (Saturday) or not.
3. If the day number is equal to six, find and copy the latest .vbk file to tape.
4. If it isn’t, find and copy a given number of latest .vib-files. The number* of vib-files to copy is defined as actual day number plus “1”.

*Note: MS considers Sunday to be “0” day, Monday “1”, etc. So, during Sunday the corresponding script will find and copy 1 latest .vib, during Monday “2”, etc.

Here is an example. Just add to it the special BE comandlets responsible for copying data to tape and everything will work fine:

Code: Select all
$SourcePath = "Path to your Repository"
$DayNumber = (Get-date).DayOfWeek.value__
$DayNumber
If ($DayNumber -eq "6")
{
   $LastVBK = Get-ChildItem $SourcePath\*.vbk| Sort-Object CreationTime -Descending | Select-Object -First 1
   #Copy $LastVBK to tape, using special Backup Exec commandlets
}
Else
{
   $DayNumber = $DayNumber + 1
   $LastVibs = Get-ChildItem $SourcePath\*.vib| Sort-Object CreationTime -Descending | Select-Object -First $DayNumber
   #Copy $LastVibs to tape, using special Backup Exec commandlets

}

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

Re: Offload Backups to Tape

Veeam Logoby dannythake » Tue May 28, 2013 12:48 pm

Thanks very much for taking the time to reply, much appreciated. My issue is more with the script that will run it. I've found the below script (posted by another forum member, full credit to that person), would you be able to assist in fitting it into what i am trying to do? I understand that this may be outside of your scope for support, but any help would be appreciated.

Thanks

Code: Select all
<##
Command to add to Veeam to execute Backup Exec Job
powershell.exe -command "& {Invoke-Command -computername falcon -filepath c:\bescripts\ps\DCs.ps1}"
##>

import-module bemcli
#
$a = get-date
$startdate = ((Get-Date).toshortdatestring()+" 00:01:00")
$dow = ($a).DayOfWeek
$th = ($a).hour
#$ts = $a.toshorttimestring()
#
if ( $dow -eq "Sunday" ) {
   $BESel = New-BEFileSystemSelection -Path "D:\VeeamBackups\Backup Job DCs" -PathIsDirectory -Recurse -IncludeOnlyModifiedFiles -FromDate $startdate
   Get-BEAgentServer falcon | Submit-BEOnetimeBackupJob -BackupSetDescription "DCs to tape" -Name "DCs to tape" `
   -FileSystemSelection $BESel -Storage "Dell LTO5 Robotic Library" `
   -tapestoragemediaset "Tape Media Set Weekend" `
   | Wait-BEJob
   get-bejob -Name "DCs to tape*" | Remove-BEJob -Confirm:$false
   }
   elseif ( $dow -eq "Saturday" ) {
   $BESel = New-BEFileSystemSelection -Path "D:\VeeamBackups\Backup Job DCs" -PathIsDirectory -Recurse -IncludeOnlyModifiedFiles -FromDate $startdate
   Get-BEAgentServer falcon | Submit-BEOnetimeBackupJob -BackupSetDescription "DCs to tape" -name "DCs to tape" `
   -FileSystemSelection $BESel -Storage "Dell LTO5 Robotic Library" `
   -tapestoragemediaset "Tape Media Set Weekend" `
   | Wait-BEJob
   get-bejob -Name "DCs to tape*" | Remove-BEJob -Confirm:$false
   }
   elseif ( $dow -eq "Monday" -and $th -lt "13" ) {
   $BESel = New-BEFileSystemSelection -Path "D:\VeeamBackups\Backup Job DCs" -PathIsDirectory -Recurse -IncludeOnlyModifiedFiles -FromDate $startdate
   Get-BEAgentServer falcon | Submit-BEOnetimeBackupJob -BackupSetDescription "DCs to tape" -name "DCs to tape" `
   -FileSystemSelection $BESel -Storage "Dell LTO5 Robotic Library" `
   -tapestoragemediaset "Tape Media Set Weekend" `
   | Wait-BEJob
   get-bejob -Name "DCs to tape*" | Remove-BEJob -Confirm:$false
   }   
   elseif ( $dow -eq "Friday" -and $th -gt "13" ) {
   $BESel = New-BEFileSystemSelection -Path "D:\VeeamBackups\Backup Job DCs" -PathIsDirectory -Recurse -IncludeOnlyModifiedFiles -FromDate $startdate
   Get-BEAgentServer falcon | Submit-BEOnetimeBackupJob -BackupSetDescription "DCs to tape" -name "DCs to tape" `
   -FileSystemSelection $BESel -Storage "Dell LTO5 Robotic Library" `
   -tapestoragemediaset "Tape Media Set Weekend" `
   | Wait-BEJob
   get-bejob -Name "DCs to tape*" | Remove-BEJob -Confirm:$false
   }
   else {
   $BESel = New-BEFileSystemSelection -Path "D:\VeeamBackups\Backup Job DCs" -PathIsDirectory -Recurse -IncludeOnlyModifiedFiles -FromDate $startdate
   Get-BEAgentServer falcon | Submit-BEOnetimeBackupJob -BackupSetDescription "DCs to tape" -name "DCs to tape" `
   -FileSystemSelection $BESel -Storage "Dell LTO5 Robotic Library" `
   -tapestoragemediaset "Tape Media Set Daily" `
   | Wait-BEJob
   get-bejob -Name "DCs to tape*" | Remove-BEJob -Confirm:$false
   }
dannythake
Enthusiast
 
Posts: 39
Liked: 10 times
Joined: Tue May 28, 2013 8:41 am
Full Name: Danny Thake

Re: Offload Backups to Tape

Veeam Logoby v.Eremin » Tue May 28, 2013 2:18 pm

According to this topic, firstly you have to create the corresponding Backup Exec copy-to-tape job and then execute it from the inside of your script, passing to it a list of files that need to be copied.

So, something like this might do the trick:

Code: Select all
$SourcePath = "Path to your Repository"
$DayNumber = (Get-date).DayOfWeek.value__
$backupExecJob = "Name of your backup exec job"
If ($DayNumber -eq "6")
{
   $LastVBK = Get-ChildItem $SourcePath\*.vbk| Sort-Object CreationTime -Descending | Select-Object -First 1
   & "d:\Program Files\Symantec\Backup Exec\bemcmd.exe" -o2 -j:$backupExecJob -s:$LastVBK -mTapes-Weekdays -r -w
}
Else
{
   $DayNumber = $DayNumber + 1
   $LastVibs = Get-ChildItem $SourcePath\*.vib| Sort-Object CreationTime -Descending | Select-Object -First $DayNumber
   & "d:\Program Files\Symantec\Backup Exec\bemcmd.exe" -o2 -j:$backupExecJob -s:$LastVIBs -mTapes-Weekdays -r -w
}


Please be aware that the script provided above doesn’t take into account file attributes, etc., so, if you’re eager to check/change them, kindly add some auditorial part to your script.

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

Re: Offload Backups to Tape

Veeam Logoby dannythake » Tue May 28, 2013 2:29 pm

Thanks very much!

Based on your first comments about the number of incrementals to backup, will the below line from your code only backup one incremental?

Code: Select all
Else
{
   $DayNumber = $DayNumber + 1


Or would i need additional lines? For example, a Thursday tape backup should include 4 incremental sets (Mon, Tues, Weds, Thurs)

Sorry for all the questions, i havent had time to learn powershell yet, and unfortunately it looks like i now need it!

Thanks again,
dannythake
Enthusiast
 
Posts: 39
Liked: 10 times
Joined: Tue May 28, 2013 8:41 am
Full Name: Danny Thake

Re: Offload Backups to Tape

Veeam Logoby v.Eremin » Tue May 28, 2013 3:10 pm

Based on your first comments about the number of incrementals to backup, will the below line from your code only backup one incremental?

No, the number of increments will vary. On Sunday the script will copy 1 .vib file, on Monday 2, etc.

In general, the script is acting in accordance with the following scheme:

Day number 6: Saturday > copy only 1.vbk
Day number 0: Sunday > copy (day number + 1) .vib file. = 0+1 = 1 .vib file to copy
Day number 1: Monday > copy (day number + 1) .vib file. = 1+1 = 2 .vib files to copy
Day number 2: Tuesday > copy (day number + 1) .vib file. = 2+1 = 3 .vib files to copy
Day number 3: Wednesday > copy (day number + 1) .vib file. = 3+1 = 4 .vib files to copy
Day number 4: Thursday > copy (day number + 1) .vib file. = 4+1 = 5 .vib files to copy
Day number 5: Friday > copy (day number + 1) .vib file. = 5+1 = 6 .vib files to copy


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

Re: Offload Backups to Tape

Veeam Logoby dannythake » Mon Jun 03, 2013 10:06 am

Thanks for your help, i have managed to get most of it working, but struggling with getting it to only backup the last VBK File, its currently backing up all the VBK's in the directory. Everything else works though!

Code: Select all
import-module bemcli
$SourcePath = "D:\Veeam2Tape"
$BackupExecJob = "Veeam2Tape"
$DayNumber = (Get-date).DayOfWeek.value__
#
if ($DayNumber -eq "1") {
$BESel = New-BEFileSystemSelection $SourcePath\*.vbk| Sort-Object CreationTime -Descending | Select-Object -First 1
Get-BEAgentServer pioneer.os.local | Submit-BEOnetimeBackupJob -BackupSetDescription "Veeam2Tape" -Name "Veeam2Tape" `
-FileSystemSelection $BESel -Storage "Pioneer Disk Storage" `
-tapestoragemediaset "Veeam2Tape" `
| Wait-BEJob
get-bejob -Name "Veeam2Tape-Backup" | Remove-BEJob -Confirm:$false
}


Can you spot anything that may be preventing it from only backing up the most recent VBK?

Thanks
dannythake
Enthusiast
 
Posts: 39
Liked: 10 times
Joined: Tue May 28, 2013 8:41 am
Full Name: Danny Thake

Re: Offload Backups to Tape

Veeam Logoby v.Eremin » Wed Jun 05, 2013 1:08 pm

I'm not in the office right at the moment, so it's rather hard to investigate what might be wrong with your code. Nevertheless, what happens if you try to define vbk-files to backup outside &BEsel variable:

Code: Select all
$LastVBK = Get-ChildItem $SourcePath\*.vbk| Sort-Object CreationTime -Descending | Select-Object -First 1
$BESel = New-BEFileSystemSelection $LastVBK


Anyway, the best way to understand what files would be backed up, is to check the value of $BESel variable.

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


Return to PowerShell



Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests