PowerShell script exchange
Post Reply
Aschtra
Novice
Posts: 7
Liked: 1 time
Joined: Aug 08, 2018 8:46 am
Contact:

Surebackup custom script check for file on linux server getting timeout

Post by Aschtra »

Hello,

I am currently trying to put this script:

https://github.com/VeeamHub/powershell/ ... rapper.ps1

into use in our own environment.
I am running into some odd issues.

I have the following script that works when performing this to the original VM:

Code: Select all

<#
	accepts certifs automatically
#>
param (
    [string]$fexist = "/etc/xattr.conf",
    [string]$plink = "C:\temp\plink.exe",
    [string]$ip = "orginal_vm_ip",
    [string]$username = "xx",
    [string]$password = "xx",
    [int]$timeout = 30
)

#prefix write-host with [linuxfexist] and a second prefix if $p is set (default "")
function write-wrapper {
    param($t, $p = "")
    $a = @($t)
    if ($p -ne "") { $p = "$p " }
    $a | % { if ($_ -ne $null -and $_ -ne "" -and $_.trim() -ne "") {write-host ("{0} {1}{2}" -f $logpref, $p, $_)}}
}

write-wrapper "Testing for $fexist @ $ip"
$exitcode = 1

if (test-path $plink) {
    $fcmd = 'fftest="'+$fexist+'";if [ -e "$fftest" ];then echo "FFEXIST $fftest FFEXIST";else echo "DOES NOT EXIST $fftest";fi'
    $argplink = @("-v", $ip, "-l", $username, "-pw", $password, $fcmd)
    
    $pinfo = New-Object System.Diagnostics.ProcessStartInfo
    $pinfo.FileName = $plink
    $pinfo.RedirectStandardError = $true
    $pinfo.RedirectStandardOutput = $true
    $pinfo.RedirectStandardInput = $true
    $pinfo.UseShellExecute = $false
    $pinfo.Arguments = $argplink
    
    $p = New-Object System.Diagnostics.Process
    $p.StartInfo = $pinfo
    $p.Start() | Out-Null
    
    # Check if the process started successfully
    if ($p -ne $null -and $p.StandardInput -ne $null) {
        $p.StandardInput.Write("yes")
    } else {
        write-wrapper "Process failed to start or StandardInput is null"
        exit 1
    }
    
    while ($timeout -gt 0 -and -not $p.HasExited) {
        start-sleep -Seconds 1
        $timeout--
    }
    
    if ($timeout -gt 0 -and $p.HasExited) {
        $stdout = $p.StandardOutput.ReadToEnd()
        $stderr = $p.StandardError.ReadToEnd()
        
        if ($stdout -ne $null -and $stderr -ne $null) {
            if ($stdout.trim() -eq "FFEXIST $fexist FFEXIST") {
                write-wrapper ("File exists {0}" -f $stdout.trim())
                $exitcode = 0
            } else {
                write-wrapper "Something went wrong, ... dumping"
                write-wrapper -t $stderr.Split("`n") -p "stderr"
                write-wrapper -t $stdout.Split("`n") -p "stdout"
            }
        } else {
            write-wrapper "StandardOutput or StandardError is null"
        }
    } else {
        if ($p -ne $null) {
            $p.Kill()
        }
        write-wrapper "Timeout, ... dumping"
        if ($stderr -ne $null) {
            write-wrapper -t $stderr.Split("`n") -p "stderr"
        }
        if ($stdout -ne $null) {
            write-wrapper -t $stdout.Split("`n") -p "stdout"
        }
    }
} else {
    write-wrapper "$plink path does not exist"
}

exit $exitcode
When running Surebackup job I see in the logging that the masked ip is 172.31.255.219.
When I have the application group running, edit the ip in the script to the masked ip I suddenly get timeouts

Code: Select all

PS C:\Windows\system32> C:\temp\linuxcheckfileCopy.ps1
 Testing for /etc/xattr.conf @ original_VM_IP
 File exists FFEXIST /etc/xattr.conf FFEXIST
PS C:\Windows\system32> C:\temp\linuxcheckfileCopy.ps1
 Testing for /etc/xattr.conf @ surebackup_masked_ip
 Timeout, ... dumping
PS C:\Windows\system32>
I can ping the masked IP form the Veeam VBR. Healthcheck and ping test also works.
There is no firewall active on the VBR or restoredVM
Im not sure what im missing.
david.domask
Veeam Software
Posts: 2656
Liked: 615 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Surebackup custom script check for file on linux server getting timeout

Post by david.domask »

Hi Aschtra,

Looking at the script code, it looks like you're getting to this block and this is where it goes a bit sideways:

Code: Select all

    if($timeout -gt 0 -and $p.HasExited) {
        $stdout = ""
        $stderr = ""
        $stdout = $p.StandardOutput.ReadToEnd()
        $stderr = $p.StandardError.ReadToEnd()
        if($stdout.trim() -eq "FFEXIST $fexist FFEXIST") {
            write-wrapper ("File exists {0}" -f $stdout.trim())
            $exitcode = 0
        } else {
            write-wrapper "Something went wrong, ... dumping"
            write-wrapper -t $stderr.Split("`n") -p "stderr"
            write-wrapper -t $stdout.Split("`n") -p "stdout"
        }
    } else {
        $p.Kill()
        write-wrapper "Timeout, ... dumping"
        write-wrapper -t $stderr.Split("`n") -p "stderr"
        write-wrapper -t $stdout.Split("`n") -p "stdout"
It looks like the script fails on this check:
if($stdout.trim() -eq "FFEXIST $fexist FFEXIST") {
I advise start the Surebackup job and leave the Application Group running and run through the code in the script line by line until you get to that point with this VM, and see what $stdout holds when it gets to that point in the loop. Probably because that condition isn't met, the script is timing out, but I cannot tell you what's different about the scenario right now, but start with that.
David Domask | Product Management: Principal Analyst
Aschtra
Novice
Posts: 7
Liked: 1 time
Joined: Aug 08, 2018 8:46 am
Contact:

Re: Surebackup custom script check for file on linux server getting timeout

Post by Aschtra »

Hello,

The checkbox to leave application group running only works when all test succeed. on failure the lab is shutdown.
Am using troubleshoot mode right now.

It has something to do with slow ssh connection. Possibly due to dns not working. The test server is the only server in the application group, no dns servers added.

The command

C:\temp\plink.exe -v -l username -pw password ip_address -batch

is very slow. connecting to putty is also very slow.
Am trying to look for a fix now on the restored vm.

edit:

Disabled several settings in sshd_config to note use dns and gssapiauthentication. Still slow but doesnt go in a timeout..
Not a solution i like to add in our production VM ofcourse.
david.domask
Veeam Software
Posts: 2656
Liked: 615 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Surebackup custom script check for file on linux server getting timeout

Post by david.domask »

Looks like there's a $timeout parameter in the script -- try increasing that and see if it helps without your sshd_config modifications. I was thinking it was probably just that, the cmds took longer than 30 seconds in the virtual lab (maybe routing issue?), but seems that's the main cause.
David Domask | Product Management: Principal Analyst
Aschtra
Novice
Posts: 7
Liked: 1 time
Joined: Aug 08, 2018 8:46 am
Contact:

Re: Surebackup custom script check for file on linux server getting timeout

Post by Aschtra »

initially It's not the script that is timing out as this single command via powershell;

C:\temp\plink.exe -v -l username -pw password ip_address -batch

also timeouts. It's due to resolving issues that cant be done on the restored vm due to not having proper dns.
The main issue has to be fixed on the original VM or somehow add DNS servers in the application group. The check file script also needs a higher timeout but only after fixing main issue.

But for now i can continue with this script.

My next challenge is the following;

i manually added the masked IP in the script that i manually retrieved from the logging.
In the surebackup lab i can use %vm_ip% but how do i use this in my script?

When i put this into the script:

[string]$ip = "%vm_ip%",

and %vm_ip% as argument in the lab

The whole script kinda messes up and shows me this in the logging:

[Console] Testing for 172.31.255.219 @ %vm_ip%

What i want is "Testing for /etc/xattr.conf @ 172.31.255.219"

The creator of the script said:

Parameters:

-ip %vm_ip%
What is the masked IP of the server, use %vm_ip% in the surebackup setup.

but that doesnt work (anymore atleast)
Aschtra
Novice
Posts: 7
Liked: 1 time
Joined: Aug 08, 2018 8:46 am
Contact:

Re: Surebackup custom script check for file on linux server getting timeout

Post by Aschtra » 1 person likes this post

I cant edit my post but I 'fixed' it.
The argument %vm_ip% seemed to go into $fexist which was at the top of list in the param.
I simply moved $ip to the top and now it 'works'
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 18 guests