PowerShell script exchange
Post Reply
MLeandro
Lurker
Posts: 1
Liked: never
Joined: May 18, 2021 8:38 pm
Full Name: Leandro Ezequiel Martinez
Contact:

Powershell - Automate Tapes Job - Help

Post by MLeandro »

Hello everybody,

Is my first question in this forum, I need help with something

My idea is automate the tapes job process, which I need Clone olders Tapes job, In the new Cloned tapes job I have delete old objects and add the new objects which are files, for example in a Linux server "/Home/Backups/Servers/" I have many .vbk as files, I need add these .vbk files to the new Tapes Jobs

I have the following code:

Code: Select all

$CurrentDate = Get-Date
$LastMonth = (($CurrentDate).AddMonths(-1)).ToUniversalTime().Month
$LastMonthName = $LastMonth | %{(Get-Culture).DateTimeFormat.GetMonthName($_)}
$Last2Month = (($CurrentDate).AddMonths(-2)).ToUniversalTime().Month
$Last2MonthName = $LastMonth | %{(Get-Culture).DateTimeFormat.GetMonthName($_)}



$TapeJob = Get-VBRTapeJob -Name Test-LM-*;

$TapeName = (Split-Path $TapeJob -leaf).ToString();
$DealerName = $TapeName.Split('- ')[3];

$TapeClone Copy-VBRJob -Job $tapejob -Name Test-LM-$LastMonthName-$DealerName -Description "Created by Leandro Martinez 5-20"

But the problem is that I cannot delete old objects and I cannot add the new files .vbk.
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Powershell - Automate Tapes Job - Help

Post by oleg.feoktistov »

Hi,

I see no issues when modifying backup directories for a file to tape job. Was it copied or not - doesn't matter in this case.
After you cloned the needed job, try to set directory objects for it. Example:

Code: Select all

$server = Get-VBRServer -Name 'localhost'
$paths = ('C:\Users\Administrator\Contacts', 'C:\Users\Administrator\.vscode', 'C:\Users\Administrator\Favorites')
$tapeJob = Get-VBRTapeJob
$ObjectArray = @()
foreach ($path in $paths) {
    $object = New-VBRFileToTapeObject -Path $path -Server $server
    $ObjectArray += $object
}
Set-VBRFileToTapeJob -Job $tapeJob -Object $ObjectArray
Set cmdlet clears all old job objects and add new ones in this case. If you want to preserve older objects and just expand the array with the other ones,
you need to add them all to $ObjectArray primarily to invoking Set.

Thanks,
Oleg
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests