script to copy recent .vbk to tape

PowerShell script exchange

Re: script to copy recent .vbk to tape

Veeam Logoby v.Eremin » Fri Apr 11, 2014 3:40 pm

Apologies, ignore the last line. What I was asking was can the script rather than build up a separate folder location with hard links. Run through the loop writing the file location into a variable that could be passed to the backup job to run.

This is essentially what the script referenced in the second post does. The only prerequisite is that the "hardlink" directory should exist, and file to tape job should be pointed to it(either in the GUI or in the initial script that creates job). Currently, there is no other way, apart from "staggering area" (that virtually uses the same concept as hardlink approach does).

Is this possible?

Kindly, see the answers provided above.

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

Re: script to copy recent .vbk to tape

Veeam Logoby infrateluq » Mon Apr 14, 2014 2:56 pm

Hi, I try this script and I always have folders item in the job objects instead of file.

Code: Select all
#This script backup to tape the most recent vbk file from all of our backup repositoy
if ( (Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue) -eq $null )
{
 Add-PsSnapin VeeamPSSnapIn
}

#Get the most recent vbk from a folder
function GetNewestVBKFile($folder) {
    $items = Get-ChildItem $folder -File -Filter *.vbk;
    if($items -is [Array]) {
        return $items | Sort-Object -Property LastWriteTime -Descending | Select-Object -First:1
    }
    return $items;
}


#Clean the old jobs that has been created from this script
foreach($job in (Get-VBRTapeJob | Where-Object {$_.Name -match "^backutpToTape-Hebdo"})) {
    Remove-VBRJob -Job $job -Confirm:$false
}
#Seeting variables
$hebdoMP = Get-VBRTapeMediaPool -Name "Hebdomadaire"
$veeamCred = Get-VBRCredentials -Name "tlquebec1\svc-veeam"
$svrs = @();
#ServerName is used for the backup repository server name
#Folders2Backup is used for the backup folders to use as local folder name in the repository server
#Folders is used by Get-ChildItem from the server where the script is executed (same number of folders as Folders2Backup
#JobName is the job name
$svr = "" | select ServerName,Folders,Folders2Backup,JobName;
$svr.ServerName = "This server";
$svr.Folders = "E:\Backups\backup SVR1";
$svr.Folders2Backup = "E:\Backups\backup SV1";
$svr.JobName = "backutpToTape-Hebdo (SVR1)"
$svrs += $svr;
$svr = "" | select ServerName,Folders,Folders2Backup,JobName;
$svr.ServerName = "SVR2";
$svr.Folders2Backup = "F:\Backups\backup SVR2","F:\Backups\Backup SVR-2";
$svr.Folders = "\\SV2\f$\Backups\backup SVR2","\\SV2\f$\Backups\Backup SVR2-2";
$svr.JobName = "backutpToTape-Hebdo (SVR2)"
$svrs += $svr;
$previousJob = $null;
$currentJob = $null;
$firstJob = $null;
#For each server, create a backup job if any file has to be backuped
foreach($svr in $svrs) {
    #Get the backup files that has not been backuped
    $files2Backup = $null;
    foreach($folder in $svr.Folders) {
        $item = GetNewestVBKFile $folder;
        $file = Find-VBRTapeCatalog -Name $item.Name
        #if null, then the file has not been backuped
        #so, the file has to be backuped
        if($file -eq $null) {
            $fileName = "$($svr.Folders2Backup[$idx])\$($item.Name)";
            $files2Backup += $fileName;
        }
    }
    #If no file to backup, then continue to other server
    if($files2Backup.Count -eq 0) {
        continue;
    }
    $veeamSvr = Get-VBRServer -Name $svr.ServerName;
    $currentJob = Add-VBRTapeFilesJob -Name $svr.JobName -Server $veeamSvr -Path $files2Backup -MediaPool $hebdoMP -Credentials $veeamCred; #-Masks $mask
    if($previousJob -ne $null) {
        #Set the job's schedule as after the previous
        $sched = Set-VBRJobSchedule -Job $currentJob -After -AfterJob $previousJob
    }
    if($firstJob -eq $null) {
        $firstJob = $currentJob;
    }
    $previousJob = $currentJob;
}
Start-VBRJob -Job $firstJob


What is the problem with the way I use the Add-VBTTapeFilesJob cmdlet?

Christian Poirier
TELUQ
Christian Poirier
for infrastructure TELUQ
TELUQ
infrateluq
Lurker
 
Posts: 2
Liked: never
Joined: Mon Apr 14, 2014 2:18 pm
Location: Québec, Québec, Canada
Full Name: Infrastructure TELUQ

Re: script to copy recent .vbk to tape

Veeam Logoby v.Eremin » Tue Apr 15, 2014 8:59 am

Hi, Christian,

It must be a bug with the way "Add-VBRTapeFilesJob" commandlet works with individual files. If individual file is present to the said commandlet, it will be automatically added as a folder, and file to tape job will eventually fail with "nothing to backup" message.

According to the plan, this problem along with many others related to tape PS functionality will be fixed in the next release. For now, you have to use certain workarounds to bypass existing limitation.

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

Re: script to copy recent .vbk to tape

Veeam Logoby menthol » Wed Jun 18, 2014 11:11 am

Hello,

I've installed the latest patch but this functionality hasn't been fixed?

Please can you advise on a workaround?

Here's my script (the affected part)

Code: Select all
# Time to get our latest full backup file and store it into a variable, ready for duplication


$logger.AppendLine("Selecting latest full backup of SRV60")
$SRV60_Latest = Get-ChildItem $SRV60_b2d -filter *.vbk | Sort-Object LastWriteTime -descending | select-object -first 1


# Now we have the latest file in a variable, create the job that will duplicate the backup


try
{
    $logger.AppendLine("Creating job for duplicating $SRV60_Latest")
    Add-VBRTapeFilesJob -Name "SRV60 to Tape" -Server "This server" -Path "$SRV60_b2d\$SRV60_Latest" -MediaPool "DSG Tape Media"
    $logger.AppendLine("Successfully created job")
}
catch
{
    $logger.AppendLine("Error while creating duplication job: $error")
    $logger.AppendLine("Script execution FAILED")
    $smtp.Send($emailFrom, $emailTo, $subject_failure, $logger.ToString())
    exit
}


As the OP says, it tries to duplicate it as a folder and fails.
menthol
Influencer
 
Posts: 12
Liked: 2 times
Joined: Fri Jan 24, 2014 10:02 am
Full Name: Brad Wyatt

Re: script to copy recent .vbk to tape

Veeam Logoby v.Eremin » Wed Jun 18, 2014 11:17 am

As I've said, the problems with tape PS functionality will be addressed in the next release, not patch. For now, you can use the script referenced in the second post. Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: script to copy recent .vbk to tape

Veeam Logoby menthol » Thu Jun 19, 2014 9:38 am

Thanks.

However it still doesn't work, it's still trying to copy a folder even with hard links.

Can anyone who has successfully done this advise?
menthol
Influencer
 
Posts: 12
Liked: 2 times
Joined: Fri Jan 24, 2014 10:02 am
Full Name: Brad Wyatt

Re: script to copy recent .vbk to tape

Veeam Logoby v.Eremin » Thu Jun 19, 2014 9:43 am

The Add-VBRTapeFilesJob currently doesn't allow you to pass a single file to the newly created file to tape job. So, you have to create a folder called "Latest .vbk" or something, specify it as a source for a file to tape job via GUI, and, then, use the referenced script that creates a hard link to the latest .vbk file and execute file to tape job in accordance. Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: script to copy recent .vbk to tape

Veeam Logoby menthol » Thu Jun 19, 2014 10:14 am

That did it!

Thank you.

When I get some time I will add my script to the forum, hopefully it will help people.
menthol
Influencer
 
Posts: 12
Liked: 2 times
Joined: Fri Jan 24, 2014 10:02 am
Full Name: Brad Wyatt

Re: script to copy recent .vbk to tape

Veeam Logoby v.Eremin » Thu Jun 19, 2014 10:32 am

Glad to hear that you've nailed it. According to the plan, the next version of PS snap-in will provide more flexibility in terms of working with tapes, so, there would be no need for using creative workarounds such hardlinks and similar. Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: script to copy recent .vbk to tape

Veeam Logoby menthol » Thu Jun 19, 2014 10:33 am

Thanks Eremin - and that's in B&R v8 yes? I look forward to it. :)
menthol
Influencer
 
Posts: 12
Liked: 2 times
Joined: Fri Jan 24, 2014 10:02 am
Full Name: Brad Wyatt

Re: script to copy recent .vbk to tape

Veeam Logoby v.Eremin » Thu Jun 19, 2014 10:38 am

Correct. Stay tuned. :)
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Previous

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 6 guests