PowerShell script exchange
Post Reply
dognose
Influencer
Posts: 10
Liked: 1 time
Joined: May 02, 2017 1:58 pm
Full Name: dognose
Contact:

Invoking Copy2Tape-Job (not working)

Post by dognose »

Hello,

since the original scheduler and the available backup Options where not exactly, what we are looking for, we created a powershell script to manage the backups "as required".

Base-Idea:
- The script runs daily.
- Every day (except on FIRST and LAST of month) it invokes the reverse incremental backup-job.
- If the day is the LAST of month, it performs another reverse incremetal backup, and THEN copies all the reverse-incremental backup files of the CURRENT MONTH to a staging location. Finally it is supposed to invoke the copy2tape job.
- If the day is the FIRST of the month, It performs a fullbackup.

Everything is working as expected so far, except that the invocation of the copy2tape job fails. There is no error, as the job is invoked
async, the script terminates afterwards - but VEEAM does not perform the job.

Maybe any idea, why it's not working as expected?

(Invocation att the end of the IF fails)

Code: Select all

# This script calls the VEEAM Backup Job "Manner Komplett".
# - On Every day it is invoked as defined (reverse incremental)
# - On Every last of a month it is invoked as reverse incremental, file copy, tape-job.
# - On every 1st of a month it is invoked as Full Backup.
#
# Transcript is written to C:\daily_backup.txt

#definitions
$backupJobName = "Backup Komplett"
$backupCopyJobName = "CopyToTape"
$backupFileLocation = "V:\BackupKomplett"
$backupFileToTapeLocation = "Z:\"

##############################################################
# Modify content bellow only if aware of what you are doing! #
##############################################################
. C:\shared.ps1

Start-Transcript -Path "C:\daily_backup.txt" -Append

# imports
Add-PSSnapin VeeamPSSnapIn

#script
$dateTime = Get-Date;
$firstDayOfMonth = getFirstDayOfMonth
$lastDayOfMonth = getLastDayOfMonth

if (isSameDay $dateTime $lastDayOfMonth){
  $dateTime.ToString() + ": Last day of Month:"
  $dateTime.ToString() + ": 1.) Run final incremental Backup of this month."
  $job = Get-VBRJob | where {$_.Name –eq $backupJobName} | Start-VBRJob
  
  #output for logs
  $job
  
  #Copy Files to staging folder.
  $dateTime = Get-Date;
  $dateTime.ToString() + ": 2.) Copy Files to Tape-Staging-Location"
  $elements = Get-ChildItem -Path $backupFileLocation -filter "*.vrb"| ? { $_.lastwritetime.month -eq $dateTime.month -and $_.lastwritetime.year -eq $dateTime.year}
  $elements_vbk = Get-ChildItem -Path $backupFileLocation -filter "*.vbk" | ? { $_.lastwritetime.day -eq $dateTime.day -and $_.lastwritetime.month -eq $dateTime.month -and $_.lastwritetime.year -eq $dateTime.year}
  $elements_vbm = Get-ChildItem -Path $backupFileLocation -filter "*.vbm" 
  
  "List of relevant vrb files"
  $elements | Select Name | ForEach-Object { write-host $_.Name } #output for logs
  
  "List of relevant vbk files"
  $elements_vbk | Select Name | ForEach-Object { write-host $_.Name } #output for logs
  
  # copy elements to Staging location
  # copy: vrb from current month
  # copy: vbk from today.
  "Copy invoked for:"
  $elements_vbm | Select Name | ForEach-Object {robocopy $backupFileLocation $backupFileToTapeLocation $_.name}
  $elements_vbk | Select Name | ForEach-Object {robocopy $backupFileLocation $backupFileToTapeLocation $_.name}
  $elements | Select Name | ForEach-Object {robocopy $backupFileLocation $backupFileToTapeLocation $_.name}
  
  #Now, invoke the copy-to-tape job on the copied folder.
  #No need to wait until it's finished, cause a tape exchange might be required.
  $dateTime = Get-Date;
  $dateTime.ToString() + ": 3.) Copy last month to Tape! Invoked Async."
  Get-VBRJob | where {$_.Name –eq $backupCopyJobName} | Start-VBRJob -FullBackup -RunAsync
  
} elseif (isSameDay $dateTime $firstDayOfMonth){

  #do full Backup.
  $dateTime.ToString() + ": First day of month: Running Full Backup this time."
  $job = Get-VBRJob | where {$_.Name –eq $backupJobName} | Start-VBRJob -FullBackup
  #Output for logs
  $job
}else{
  #do Reverse Incremental Backup.
  $dateTime.ToString() + ": Regular Day of Month: Running Reverse Incremental Backup."
  
  $job = Get-VBRJob | where {$_.Name –eq $backupJobName} | Start-VBRJob
  
  #Output for logs
  $job
}

Stop-Transcript
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Invoking Copy2Tape-Job (not working)

Post by veremin »

By "copy2tape-job" do you refer to "backup to tape" type of job? If so, use Get-VBRTapeJob instead of Get-VBRJob in the following line:

Code: Select all

Get-VBRJob | where {$_.Name –eq $backupCopyJobName} | Start-VBRJob -FullBackup -RunAsync
Thanks.
dognose
Influencer
Posts: 10
Liked: 1 time
Joined: May 02, 2017 1:58 pm
Full Name: dognose
Contact:

Re: Invoking Copy2Tape-Job (not working)

Post by dognose »

Oh, that sounds ... straight forward. So I guess it's "Start-VBRTapeJob" rather than "START-VBRJob" as well?
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Invoking Copy2Tape-Job (not working)

Post by veremin » 1 person likes this post

And here comes the difference - nope, it's Start-VBRJob. :)
dognose
Influencer
Posts: 10
Liked: 1 time
Joined: May 02, 2017 1:58 pm
Full Name: dognose
Contact:

Re: Invoking Copy2Tape-Job (not working)

Post by dognose »

Oh, that sounds ... straight forward... NOT :lol:

I'll give it a try and report back in 31 days (unless I have a typo) :o

(just kidding)
dognose
Influencer
Posts: 10
Liked: 1 time
Joined: May 02, 2017 1:58 pm
Full Name: dognose
Contact:

Re: Invoking Copy2Tape-Job (not working)

Post by dognose » 1 person likes this post

Okay, seems legit :)

Thx for your (very quick) help!

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

Re: Invoking Copy2Tape-Job (not working)

Post by veremin »

You're welcome. Happy that my input has been helpful for you. Contact us, should other help be needed.
Post Reply

Who is online

Users browsing this forum: Baidu [Spider] and 14 guests