[SOLVED] Where to add post backup script to scheduled backup?

Hello everyone,

I am planning to make my own post backup script to automaticly upload all the backup files to an S3 Complaint bucket.
I have seen that this can be done via the --script option when manually creating a backup.

My backups however are configured via the GUI so that they are automatic.
So I would like to know how I can add a backup script hook to backups that are created via the GUI. (Datacenter > Backup)

And does anyone also know if the post script get the backup retention settings?
Since I would like to code my script to use the configured retention settings instead of having the retention periods hardcoded.
 
Hi,
it's currently only possible to set the script via CLI (see the /etc/pve/jobs.cfg file for backup job ID), e.g:
pvesh set /cluster/backup/backup-e9ee601b-41ad --script /path/to/your/executable/script.pl

And unfortunately, the retention settings are not passed to the hook script. You could try reading them from the /etc/pve/jobs.cfg file too. See the example hook script /usr/share/doc/pve-manager/examples/vzdump-hook-script.pl for what is set in the environment.
 
Thanks for the info.

When doing it this way it seems to work as I wanted it to.
When I run the backup however I get an error message saying that my script file does not exists even though it does.
ERROR: could not notify via target `mail-to-root`: could not notify via endpoint(s): mail-to-root: At least one recipient has to be specified!
TASK ERROR: command '/custom-scripts/backup_upload.sh job-init' failed: open3: exec of /custom-scripts/backup_upload.sh job-init failed: No such file or directory at /usr/share/perl5/PVE/Tools.pm line 494.

The script itself is located at /custom-scripts/ since that is where I store all my custom created scripts.
The custom-scripts folder has a 755 permission and is owned by root.
The script files inside also have a 755 permission and are also owned by root.
So it should be also to access and execute the script itself.
 
Thanks for the info.

When doing it this way it seems to work as I wanted it to.
When I run the backup however I get an error message saying that my script file does not exists even though it does.


The script itself is located at /custom-scripts/ since that is where I store all my custom created scripts.
The custom-scripts folder has a 755 permission and is owned by root.
The script files inside also have a 755 permission and are also owned by root.
So it should be also to access and execute the script itself.
Hmm, it works for me. Are you sure this is on the same node where the job is executed?

If yes, please share the output of
Code:
pveversion -v
stat /custom-scripts
stat /custom-scripts/backup_upload.sh
cat /etc/pve/jobs.cfg
 
pveversion -v
root@metal-1:~# pveversion -v
proxmox-ve: 8.1.0 (running kernel: 6.5.11-7-pve)
pve-manager: 8.1.3 (running version: 8.1.3/b46aac3b42da5d15)
proxmox-kernel-helper: 8.1.0
pve-kernel-5.15: 7.4-9
proxmox-kernel-6.5: 6.5.11-7
proxmox-kernel-6.5.11-7-pve-signed: 6.5.11-7
pve-kernel-5.15.131-2-pve: 5.15.131-3
ceph-fuse: 16.2.11+ds-2
corosync: 3.1.7-pve3
criu: 3.17.1-2
glusterfs-client: 10.3-5
ifupdown: residual config
ifupdown2: 3.2.0-1+pmx7
ksm-control-daemon: 1.4-1
libjs-extjs: 7.0.0-4
libknet1: 1.28-pve1
libproxmox-acme-perl: 1.5.0
libproxmox-backup-qemu0: 1.4.1
libproxmox-rs-perl: 0.3.3
libpve-access-control: 8.0.7
libpve-apiclient-perl: 3.3.1
libpve-common-perl: 8.1.0
libpve-guest-common-perl: 5.0.6
libpve-http-server-perl: 5.0.5
libpve-network-perl: 0.9.5
libpve-rs-perl: 0.8.7
libpve-storage-perl: 8.0.5
libspice-server1: 0.15.1-1
lvm2: 2.03.16-2
lxc-pve: 5.0.2-4
lxcfs: 5.0.3-pve4
novnc-pve: 1.4.0-3
proxmox-backup-client: 3.1.2-1
proxmox-backup-file-restore: 3.1.2-1
proxmox-kernel-helper: 8.1.0
proxmox-mail-forward: 0.2.2
proxmox-mini-journalreader: 1.4.0
proxmox-offline-mirror-helper: 0.6.3
proxmox-widget-toolkit: 4.1.3
pve-cluster: 8.0.5
pve-container: 5.0.8
pve-docs: 8.1.3
pve-edk2-firmware: 4.2023.08-2
pve-firewall: 5.0.3
pve-firmware: 3.9-1
pve-ha-manager: 4.0.3
pve-i18n: 3.1.5
pve-qemu-kvm: 8.1.2-6
pve-xtermjs: 5.3.0-3
qemu-server: 8.0.10
smartmontools: 7.3-pve1
spiceterm: 3.3.0
swtpm: 0.8.0+pve1
vncterm: 1.8.0
zfsutils-linux: 2.2.2-pve1
stat /custom-scripts
root@metal-1:~# stat /custom-scripts
File: /custom-scripts
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 8,2 Inode: 447 Links: 2
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2024-01-14 19:35:27.793030837 +0100
Modify: 2024-01-14 19:35:30.416994873 +0100
Change: 2024-01-14 19:35:30.416994873 +0100
Birth: 2023-12-26 16:37:10.536553461 +010
stat /custom-scripts/backup_upload.sh
root@metal-1:~# stat /custom-scripts/backup_upload.sh
File: /custom-scripts/backup_upload.sh
Size: 185 Blocks: 8 IO Block: 4096 regular file
Device: 8,2 Inode: 46 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2024-01-15 09:11:52.159083103 +0100
Modify: 2024-01-14 19:35:27.717031878 +0100
Change: 2024-01-15 09:11:29.655392983 +0100
Birth: 2024-01-14 19:35:27.697032152 +0100
cat /etc/pve/jobs.cfg
root@metal-1:~# cat /etc/pve/jobs.cfg
vzdump: backup-f3135cb2-1805
schedule 03:00
all 1
compress zstd
enabled 1
exclude 900,901
mailnotification always
mode snapshot
node metal-1
notes-template {{node}} - {{vmid}}
prune-backups keep-daily=7
storage Backups

vzdump: backup-cdb383d2-945c
schedule 21:00
all 1
compress zstd
enabled 1
exclude 901,900,103,102
mailnotification always
mode snapshot
node metal-1
notes-template trash - {{vmid}}
prune-backups keep-last=1
script /custom-scripts/backup_upload.sh
storage Backup
And I run the backup script via the run now button in the web GUI for testing the script.
 
Last edited:
pveversion -v

stat /custom-scripts

stat /custom-scripts/backup_upload.sh

cat /etc/pve/jobs.cfg

And I run the backup script via the run now button in the web GUI for testing the script.
Looks essentially the same for me, but it works. Can you share the full backup task log? What kind of filesystem is /custom-scripts on? Do you have any special security hardenings activated? Anything in the system logs/journal around the time the issue occurs?
 
Looks essentially the same for me, but it works. Can you share the full backup task log? What kind of filesystem is /custom-scripts on? Do you have any special security hardenings activated? Anything in the system logs/journal around the time the issue occurs?
unfortunately, I already have provided the full backup log. (Unless the web GUI backup log output does not show the full log.)
For the filesystem I use the following:
root@metal-1:~# df -Th
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 126G 0 126G 0% /dev
tmpfs tmpfs 26G 1.4M 26G 1% /run
/dev/sda2 ext4 63G 5.7G 54G 10% /
tmpfs tmpfs 126G 46M 126G 1% /dev/shm
tmpfs tmpfs 5.0M 4.0K 5.0M 1% /run/lock
/dev/sda3 ext4 1.8T 4.1G 1.7T 1% /var/lib/vz
/dev/fuse fuse 128M 36K 128M 1% /etc/pve
/dev/sdd1 ext4 1.8T 15G 1.7T 1% /mnt/pve/Backups
tmpfs tmpfs 26G 0 26G 0% /run/user/0

And as far as I know I do not have any extra security hardening that is not included by proxmox VE itself.
And I managed to find this in the journal but it is not really any more usefull. :(
Jan 15 09:44:25 metal-1.danielhosting.nl pvedaemon[3822887]: <root@pam> end task UPID:metal-1:00080668:0A0BF8EA:65A4E8E1:vncshell::>
Jan 15 09:44:32 metal-1.danielhosting.nl pvedaemon[3822886]: <root@pam> starting task UPID:metal-1:00081C55:0A0EEC9B:65A4F070:vzdum>
Jan 15 09:44:32 metal-1.danielhosting.nl pvedaemon[531541]: command '/custom-scripts/backup_upload.sh job-init' failed: open3: exec of /custom-scripts/backup_upload.sh job-init failed: No such file or directory at /usr/share/perl5/PVE/Tools.pm line 494.>
Jan 15 09:44:32 metal-1.danielhosting.nl pvedaemon[3822886]: <root@pam> end task UPID:metal-1:00081C55:0A0EEC9B:65A4F070:vzdump:101:root@pam: command '/custom-scripts/backup_upload.sh job-init' failed: open3: exec of /custom-scripts/backup_upload.sh job-init failed: No such file or directory at /usr/share/perl5/PVE/Tools.pm line 494.>
 
Last edited:
that error can also happen if your script has an interpreter that does not exist. could you paste the first line of your script, and also double-check that whatever is referenced there exists and is executable by root?
 
that error can also happen if your script has an interpreter that does not exist. could you paste the first line of your script, and also double-check that whatever is referenced there exists and is executable by root?
In my case it would be bash
#!/bin/bash
root@metal-1:~# which bash
/usr/bin/bash

But I found the problem.
It was Windows encoded instead of Unix. :mad:
Thanks @fabian for the help and the pointers. Without it, I would probably never guest it was an interpreter issue.
 
  • Like
Reactions: fabian
How about "pre" scripts. I was hoping to be able to do some preparation of data for backups before executing it. I've seen some feature requests for pre and post backup scripts but understand they are not being considered.
I am guessing I would have do them as my own script and cron on the host with an unscheduled backup job executed via the CLI or are there better alternatives?
 
Hi,
How about "pre" scripts. I was hoping to be able to do some preparation of data for backups before executing it. I've seen some feature requests for pre and post backup scripts but understand they are not being considered.
I am guessing I would have do them as my own script and cron on the host with an unscheduled backup job executed via the CLI or are there better alternatives?
there already are hooks called before and after a backup job (job-init and job-end), see the example hook script in /usr/share/doc/pve-manager/examples/vzdump-hook-script.pl
 
Thanks, but any documentation for that? Do i understand that is a general script that gets executed for every scheduled backup or do I need to identify a job ID there?
 

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!