Host-based backup of VMware vSphere VMs.
Post Reply
Thomas609
Novice
Posts: 7
Liked: 1 time
Joined: Oct 17, 2024 6:22 am
Full Name: Thomas Chang
Contact:

Issue with Executing Pre/Post Job Scripts

Post by Thomas609 »

Hi all,

I'm currently facing an issue with setting up pre-job and post-job scripts in Veeam.
My goal is to use these scripts to achieve a simple air gap mechanism.

Setup Overview:

1.I configured a Linux server to mount an NFS share.

2.In VBR, I added a Linux-based repository, pointing to the mounted folder.

3.On the Linux server, I created two shell scripts:
  • mount.sh – for mounting the share
#!/bin/bash
# NFS for Veeam Pre-Job

MOUNT_POINT="/veeam"
NFS_SERVER="192.168.10.22"
NFS_SHARE="/ifs/veeam"

logger "[Veeam Pre-Job]"
if mountpoint -q "$MOUNT_POINT"; then
logger "[Veeam Pre-Job]"
exit 0
fi

logger "[Veeam Pre-Job] NFS $NFS_SERVER:$NFS_SHARE 到 $MOUNT_POINT"
mkdir -p "$MOUNT_POINT"
sudo mount -t nfs "$NFS_SERVER:$NFS_SHARE" "$MOUNT_POINT"
if [ $? -ne 0 ]; then
logger "[Veeam Pre-Job] if fail"
exit 1
fi

logger "[Veeam Pre-Job] if finish"
  • umount.sh – for unmounting it
4.In VBR, I created two PowerShell scripts:
  • mount.ps1 and umount.ps1 — both scripts use SSH to trigger the corresponding shell scripts on the Linux server.
# call_mount_ssh.ps1 - Mount NFS share on Linux via SSH

$log = "D:\scripts\call_mount_ssh.log"
$outFile = "D:\scripts\call_mount_ssh.log.out"
$errFile = "D:\scripts\call_mount_ssh.log.err"
$ssh = "C:\Windows\System32\OpenSSH\ssh.exe"
$linuxUser = "user1"
$linuxHost = "192.168.10.9"
$remoteScript = "/opt/veeam/scripts/mount_nfs.sh"

"[$(Get-Date)] Starting SSH mount script" | Out-File $log

#fingerprint prompt
$sshCommand = @(
"-o", "StrictHostKeyChecking=no",
"-o", "ConnectTimeout=30",
"$linuxUser@$linuxHost",
$remoteScript
)

"[$(Get-Date)] Executing: ssh $($sshCommand -join ' ')" | Add-Content $log

try {
$process = Start-Process -FilePath $ssh `
-ArgumentList $sshCommand `
-NoNewWindow -Wait -PassThru `
-RedirectStandardOutput $outFile `
-RedirectStandardError $errFile

$exitCode = $process.ExitCode
Add-Content $log "`n--- STDOUT ---`n$(Get-Content $outFile -ErrorAction SilentlyContinue)"
Add-Content $log "`n--- STDERR ---`n$(Get-Content $errFile -ErrorAction SilentlyContinue)"
Add-Content $log "`nExit code: $exitCode"

exit $exitCode
}
catch {
Add-Content $log "`nException: $($_.Exception.Message)"
exit 1
}
When I manually run the PowerShell scripts, they successfully connect and execute the mount/unmount actions via SSH.
I’ve also confirmed that the account used has sufficient permissions to mount the NFS share, so permission does not appear to be the root cause.

Problem:
When I assign these scripts as Pre-job and Post-job scripts in the Veeam backup job, they consistently fail with a timeout error.
<17> Info (3) Executing custom command [powershell.exe], arguments [ -ExecutionPolicy ByPass -Command " try {& 'D:\scripts\call_mount_ssh.ps1' -ErrorAction Stop } catch { exit 1 } "]
[08.05.2025 16:18:20.752] <17> Warning (3) Pre-job script timed out
[08.05.2025 16:18:20.815] <17> Warning (3) Pre-job script timed out
Questions:
Am I missing any required configuration ?
Are there limitations when using PowerShell scripts to trigger remote SSH calls from within a job context?

Any guidance or best practice recommendation would be greatly appreciated.

Thank you!
Andreas Neufert
VP, Product Management
Posts: 7233
Liked: 1551 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Re: Issue with Executing Pre/Post Job Scripts

Post by Andreas Neufert »

Just a guess, but the Veeam Server Service in Windows runs under a specific user that executes this PS script. My guess is that this user does not have the rights to run the PS script or that somehow the interaction is limited. Maybe create a local Admin account, add it to the Veeam Backup Service and try it again.
Andreas Neufert
VP, Product Management
Posts: 7233
Liked: 1551 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Re: Issue with Executing Pre/Post Job Scripts

Post by Andreas Neufert »

Please check this one out: https://www.veeam.com/kb2183
Post Reply

Who is online

Users browsing this forum: MaartenA and 21 guests