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