$PATH in vzdump hook script not working

ilium007

Active Member
Feb 25, 2020
50
3
28
46
I have a hook script (bash shell script) that simply calls autorestic to perform an offsite backup of the locally dumped vzdump files.

If I run my hook script from the command line (and specify job-end) it runs fine and the autorestic job runs:

Code:
Thu May  9 11:45:47 PM UTC 2024 PVE hook script finish (pve01)

PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
WHICH SSH: /usr/bin/ssh

Using config:    /root/.autorestic.yml
Using lock:      /root/.autorestic.lock.yml




    Backing up location "ext_usb_01"


Backend: storage0
> Executing: /usr/local/bin/restic backup --tag ar:location:ext_usb_01 /mnt/ext_usb_01/dump/
using parent snapshot 4f2b636e


Files:           0 new,     0 changed,     3 unmodified
Dirs:            0 new,     0 changed,     3 unmodified
Added to the repository: 0 B   (0 B   stored)


processed 3 files, 268.867 MiB in 0:00
snapshot 08c763d1 saved




  Forgetting for location "ext_usb_01"


For backend "storage0"
> Executing: /usr/local/bin/restic forget --tag ar:location:ext_usb_01 --keep-weekly 4 --keep-monthly 3
Applying Policy: keep 4 weekly, 3 monthly snapshots
keep 2 snapshots:
ID        Time                 Host        Tags                    Reasons           Paths
---------------------------------------------------------------------------------------------------------
925ca5ed  2024-05-09 22:03:17  pve01       ar:location:ext_usb_01  weekly snapshot   /mnt/ext_usb_01/dump
                                                                   monthly snapshot
08c763d1  2024-05-09 23:47:34  pve01       ar:location:ext_usb_01  weekly snapshot   /mnt/ext_usb_01/dump
                                                                   monthly snapshot
---------------------------------------------------------------------------------------------------------
2 snapshots


remove 1 snapshots:
ID        Time                 Host        Tags                    Paths
---------------------------------------------------------------------------------------
4f2b636e  2024-05-09 23:44:34  pve01       ar:location:ext_usb_01  /mnt/ext_usb_01/dump
---------------------------------------------------------------------------------------
1 snapshots


[0:00] 100.00%  1 / 1 files deleted


Done
Done
Thu May  9 11:47:38 PM UTC 2024 PVE hook script finish (pve01)

If I let vzdump run the hook script it fails saying that autorestic can't find ssh in $PATH. You can see in the script output I am dumping $PATH and the output from $(which ssh). So I have access to $PATH and ssh in in the environment path. It seems that when I call autorestic it doesn't not know about $PATH.

Code:
tail: /mnt/ext_usb_01/pve01.log: file truncated
Thu May  9 23:53:19 UTC 2024 PVE hook script start (pve01) - pve-manager/8.2.2/9355359cd7afbae4 (running kernel: 6.8.4-2-pve)
PATH: /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:.
WHICH SSH: /usr/bin/ssh


PATH: /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:.
WHICH SSH: /usr/bin/ssh
Using config:      /root/.autorestic.yml
Using lock:     /root/.autorestic.lock.yml




    Backing up location "ext_usb_01"


Backend: storage0
> Executing: /usr/local/bin/restic backup --tag ar:location:ext_usb_01 /mnt/ext_usb_01/dump/
Fatal: unable to open repository at sftp:honeyeater-autorestic:/mnt/storage0/winter/pve01/: exec: "ssh": executable file not found in $PATH


ext_usb_01@storage0:
Fatal: unable to open repository at sftp:honeyeater-autorestic:/mnt/storage0/winter/pve01/: exec: "ssh": executable file not found in $PATH
exit status 1


Error: 1 errors were found
Thu May  9 23:53:26 UTC 2024 PVE hook script finish (pve01)

My hook script:

Code:
root@pve01:~# cat /etc/vzdump-hook.sh
#!/bin/bash


PVE_NODE="$(hostname)"
LOG_FILE="/mnt/ext_usb_01/$PVE_NODE.log"


if [ "$1" == "job-start" ]; then
  printf "$(date) PVE hook script start ($PVE_NODE) - $(pveversion)\n" | tee $LOG_FILE
  printf "PATH: $PATH\n" | tee -a $LOG_FILE
  printf "WHICH SSH: $( which ssh)\n" | tee -a $LOG_FILE
fi


if [ "$1" == "job-end" ]; then
  printf "PATH: $PATH\n" | tee -a $LOG_FILE
  printf "WHICH SSH: $( which ssh)\n" | tee -a $LOG_FILE
  /usr/local/bin/autorestic -c /root/.autorestic.yml --restic-bin /usr/local/bin/restic backup --verbose --all 2>&1 | tee -a $LOG_FILE
  printf "$(date) PVE hook script finish ($PVE_NODE)\n" | tee -a $LOG_FILE
fi
 
I have re-written the script in Perl and the same thing happens:

Script:

Code:
root@pve01:~# cat /etc/vzdump-hook.pl
#!/usr/bin/perl


use strict;
use warnings;


print "GUEST HOOK: " . join(' ', @ARGV). "\n";


my $phase = shift;
my $mode = shift;
my $vmid = shift;


if ($phase eq 'job-start') {


    print "Job is starting\n";
    my $cmd = qq[printf "\$(date) PVE hook script start pve01 - \$(pveversion)\n" | tee /mnt/ext_usb_01/pve01.log];
    system $cmd;


} elsif ($phase eq 'job-end') {


    print "Job is ending\n";
    my $cmd = qq[/usr/local/bin/autorestic -c /root/.autorestic.yml --restic-bin /usr/local/bin/restic backup --verbose --all 2>&1 | tee -a /mnt/ext_usb_01/pve01.log];
    system $cmd;


}


exit(0);

Same error:

Code:
root@pve01:~# cat /mnt/ext_usb_01/pve01.log
Fri May 10 01:32:10 UTC 2024 PVE hook script start pve01 - pve-manager/8.2.2/9355359cd7afbae4 (running kernel: 6.8.4-2-pve)
Using config:      /root/.autorestic.yml
Using lock:     /root/.autorestic.lock.yml




    Backing up location "ext_usb_01"


Backend: storage0
> Executing: /usr/local/bin/restic backup --tag ar:location:ext_usb_01 /mnt/ext_usb_01/dump/
Fatal: unable to open repository at sftp:honeyeater-autorestic:/mnt/storage0/winter/pve01/: exec: "ssh": executable file not found in $PATH


ext_usb_01@storage0:
Fatal: unable to open repository at sftp:honeyeater-autorestic:/mnt/storage0/winter/pve01/: exec: "ssh": executable file not found in $PATH
exit status 1


Error: 1 errors were found
root@pve01:~#
 
If I remove hard coded paths to the --restic-bin command it fails... It seems /usr/local/bin/autorestic is found without hardcoding path but when autorestic calls 'restic' it fails on PATH as well.


Code:
tail: /mnt/ext_usb_01/pve01.log: file truncated
Fri May 10 01:38:43 UTC 2024 PVE hook script start pve01 - pve-manager/8.2.2/9355359cd7afbae4 (running kernel: 6.8.4-2-pve)


Using config:      /root/.autorestic.yml
Using lock:     /root/.autorestic.lock.yml


    Backing up location "ext_usb_01"

Backend: storage0
> Executing: restic backup --tag ar:location:ext_usb_01 /mnt/ext_usb_01/dump/

ext_usb_01@storage0:
exec: "restic": executable file not found in $PATH

Error: 1 errors were found
 
Again - if I run the Perl script manually from the command line and pass in job-end it runs fine with no PATH issues.

Code:
root@pve01:~# /etc/vzdump-hook.pl job-end
GUEST HOOK: job-end
Job is ending
Using config:      /root/.autorestic.yml
Using lock:     /root/.autorestic.lock.yml




    Backing up location "ext_usb_01"


Backend: storage0
> Executing: /usr/local/bin/restic backup --tag ar:location:ext_usb_01 /mnt/ext_usb_01/dump/
using parent snapshot 08c763d1


Files:           3 new,     0 changed,     0 unmodified
Dirs:            0 new,     3 changed,     0 unmodified
Added to the repository: 128.855 MiB (128.804 MiB stored)


processed 3 files, 268.868 MiB in 0:37
snapshot 73360270 saved




  Forgetting for location "ext_usb_01"


For backend "storage0"
> Executing: /usr/local/bin/restic forget --tag ar:location:ext_usb_01 --keep-weekly 4 --keep-monthly 3
Applying Policy: keep 4 weekly, 3 monthly snapshots
keep 2 snapshots:
ID        Time                 Host        Tags                    Reasons           Paths
---------------------------------------------------------------------------------------------------------
925ca5ed  2024-05-09 22:03:17  pve01       ar:location:ext_usb_01  weekly snapshot   /mnt/ext_usb_01/dump
                                                                   monthly snapshot
73360270  2024-05-10 01:45:42  pve01       ar:location:ext_usb_01  weekly snapshot   /mnt/ext_usb_01/dump
                                                                   monthly snapshot
---------------------------------------------------------------------------------------------------------
2 snapshots


remove 1 snapshots:
ID        Time                 Host        Tags                    Paths
---------------------------------------------------------------------------------------
08c763d1  2024-05-09 23:47:34  pve01       ar:location:ext_usb_01  /mnt/ext_usb_01/dump
---------------------------------------------------------------------------------------
1 snapshots


[0:00] 100.00%  1 / 1 files deleted


Done
Done
root@pve01:~#
 
Thanks for the reply but I don’t think that’s it. The script runs fine if I call it from a cmd line, it fails when it’s called from Proxmox vzdump.
 
I got the shell script running by defining $PATH within the shell script:

Code:
#!/bin/bash


PVE_NODE="$(hostname)"
LOG_FILE="/mnt/ext_usb_01/$PVE_NODE.log"

export PATH=$PATH
export HOME="/root"


if [ "$1" == "job-start" ]; then
  printf "$(date) PVE hook script start ($PVE_NODE) - $(pveversion)\n" | tee $LOG_FILE
fi


if [ "$1" == "job-end" ]; then
  export
  /usr/local/bin/autorestic -c /root/.autorestic.yml --restic-bin /usr/local/bin/restic backup --verbose --all 2>&1 | tee -a $LOG_FILE
  printf "$(date) PVE hook script finish ($PVE_NODE)\n" | tee -a $LOG_FILE
fi
 
  • Like
Reactions: Kingneutron
Scheduled backup ran fine last night using the above kludge. Does anyone know why PATH=$PATH, redefining an EVN variable worked?
 
Similar problem. Trying to get hook script working with Restic. Needed to add
Code:
export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
export HOME='/root'
In script before call to restic.
Otherwise Restic complains of 'ssh not found' - fixed by path, and of no cache - fixed by setting home.
With these lines script works OK.
 
Yeah - same as what I found above:

Code:
export PATH=$PATH
export HOME="/root"

I just redefined existing ENV variables and it worked.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!