Backup Copy Job - prevent execution

PowerShell script exchange

Backup Copy Job - prevent execution

Veeam Logoby rriess » Thu Nov 19, 2015 10:06 am

Hello,

we use Veeam B&R v8 together with a QNAP NAS. A RDX drive is connected to the QNAP by USB3. In Veeam I have configured the QNAP as linux host and two backup repositories on this host. One repository is the main backup location on the QNAP harddrives (/share/CACHEDEV1_DATA/Backup/). The second one is the destination for backup copies on the RDX drive (/share/external/DEV3301_1/). This one is configured for drive rotation.
The backup job runs from monday to saturday keeping 12 restore points. The backup copy job copies the data to RDX afterwards (copy method: direct). A post-run script of the copy job ejects the RDX cartridge. Everything works great until the RDX drive is not mounted (e.g. bank holiday). If the RDX drive is not mounted, Veeam creates the folder on its own (/share/external/DEV3301_1/) and starts copying data. This fails because the directory is created on the QNAPs ramdisk with 60MB left space. The ramdisk fills up and I have to restart the QNAP (or delete the data through ssh).

Now my question: How can I prevent the execution of the copy job if the drive is not mounted (the target folder does not exist)? It would be OK if the job fails an retries the execution at the next copy job interval. I tried already the pre-run script with exit code 1. Nevertheless Veeam executes the copy job with a warning and does not fail.

I hope someone can help me :-)
rriess
Novice
 
Posts: 4
Liked: 6 times
Joined: Thu Nov 19, 2015 9:38 am
Full Name: Robert Rieß

Re: Backup Copy Job - prevent execution

Veeam Logoby PTide » Thu Nov 19, 2015 10:57 am

Hi,

I'd place a while-loop inside your pre-run script with "folder does not exist" condition. Once the condition is not met (RDX is mounted) then your script should return zero. Also please make sure that you have "require succesful script execution" option enabled.

Thank you.
PTide
Veeam Software
 
Posts: 3017
Liked: 245 times
Joined: Tue May 19, 2015 1:46 pm

Re: Backup Copy Job - prevent execution

Veeam Logoby rriess » Thu Nov 19, 2015 11:13 am

Hi,

thank You for Your answer! The "require succesful script execution" option is only available for backup jobs. It is not available for backup copy jobs. :-(

The while-loop is an idea. But I think it will not work because the scripts have a maximum execution time. Even if the loop works, what happens at the next copy job interval? Will it abort? Will it execute twice once the directory exists?
rriess
Novice
 
Posts: 4
Liked: 6 times
Joined: Thu Nov 19, 2015 9:38 am
Full Name: Robert Rieß

Re: Backup Copy Job - prevent execution

Veeam Logoby v.Eremin » Thu Nov 19, 2015 12:58 pm

If the dates when a disk is not present are known in advance, would not it be easier to specify a script via Windows Task Scheduler that disables a backup copy job for the specified period and re-enables it afterwards?
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Backup Copy Job - prevent execution

Veeam Logoby rriess » Thu Nov 19, 2015 1:22 pm 3 people like this post

Thank You!

The dates are not always known in advance. Sometimes someone forgets to replace the RDX cartridge. This shouldn't happen, but it does. :-) If it happens it should not screw up the NAS. But I used Your idea.

I wrote a little script which executes after the main backup job. It disables the copy job if the directory does not exist and exits with a warning. Otherwise it enables the copy job. I think this should work.

Code: Select all
Add-PSSnapin VeeamPSSnapin

New-SshSession -ComputerName NAS -Username ... -KeyFile "D:\Scripts\Veeam\id_rsa"
$Query = Invoke-SshCommand -ComputerName NAS -Command "mount | grep /dev/sdg1"
Remove-SshSession -RemoveAll

$CopyJob = Get-VBRJob -Name "Copy to RDX"

if ($Query) {
    Write-Host "RDX drive ready. Enable copy job."
    Enable-VBRJob -Job $CopyJob
} else {
    Write-Host "RDX drive not ready! Disable copy job."
    Disable-VBRJob -Job $CopyJob
    exit 1
}


I also tried this script as pre-run script for the copy job. But the copying starts before Veeam notices the disabled state of the job.
rriess
Novice
 
Posts: 4
Liked: 6 times
Joined: Thu Nov 19, 2015 9:38 am
Full Name: Robert Rieß

Re: Backup Copy Job - prevent execution

Veeam Logoby v.Eremin » Thu Nov 19, 2015 2:25 pm 1 person likes this post

Yep, your solution should work fine. The source backup job should run, then, check whether the given directory exists, and act in accordance either enabling or disabling the backup copy job. Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Backup Copy Job - prevent execution

Veeam Logoby rriess » Fri Nov 20, 2015 10:20 am 3 people like this post

Hi,

Great!

Now I have also extended my script which ejects the RDX cartridge. It only ejects the cartridge if everything was OK and disables the copy job after ejecting.
This should also avoid the run of the copy job on sunday (the primary backup job doesn't run on sunday) and Veeam could reschedule the job if something wents wrong during copying.

I think this should cover nearly each possibility. (Only if somebody ejects the cartridge manually there is a small chance that the backup copy job runs onto the ramdisk.)

Perhaps somebody needs a similar script, so I post it here:
Code: Select all
Add-PSSnapin VeeamPSSnapin

$CopyJob = Get-VBRJob -Name "Copy to RDX"
$CopySession = $CopyJob.FindLastSession()
$CopyTasks = $CopySession.GetTaskSessions() | ? { $_.Status -ne "Success" }

if (! $CopyTasks) {
    Start-Sleep -Seconds 10
    New-SshSession -ComputerName NAS -Username ...-KeyFile "D:\Scripts\Veeam\id_rsa"
    $Query = Invoke-SshCommand -ComputerName NAS -Command "/opt/bin/eject /dev/sdg1"
    Remove-SshSession -RemoveAll

    Write-Host "Copy job finished. Disable copy job."
    Disable-VBRJob -Job $CopyJob
}


The disabling of the job in the first script should now be unnecessary. But it doesn't hurt.

(Everything would be much easier if there would be a possibility to prevent the execution of copy job by pre-run script. Feature request?)
rriess
Novice
 
Posts: 4
Liked: 6 times
Joined: Thu Nov 19, 2015 9:38 am
Full Name: Robert Rieß


Return to PowerShell



Who is online

Users browsing this forum: quazer and 5 guests