query if a backup task is running

RockNLol

Member
Sep 13, 2020
45
2
13
hi,
in my homelab I'm running PBS as a VM on my workstation. Before each scheduled backup I wake it up via WoL. Now I'm looking for a way to shut it down, when the backup is complete.
Can I somehow query, if a backup task is currently running? I then could just cron check, and if no backup task is active shut down the workstation again.

thanks in advance!
 
Need to do something similar soon but a bit more dvanced with also checking if a GC, Verify or Prune job is running.

Would be great if someone could give an example how to check that using the API. And how to shutdown the PBS using API too.
 
/api2/json/nodes/{node}/tasks?running=true lists currently running tasks and has a total count in the returned json, which can be checked if zero. This also lists GC, Verify and Prune jobs.
Heres the link to the documentation: PBS Documentation

*edit: Yeah, no idea on how to query this repeatedly by a script. I don't get the authentication to work outside of logged in browser.
 
Last edited:
  • Like
Reactions: Dunuin
Does the API deliver tasks for PVE & PBS when they are on same server or do I need to query both by using different ports?
 
*edit: Yeah, no idea on how to query this repeatedly by a script. I don't get the authentication to work outside of logged in browser.
Hi,
an API Token should be used for authorization from scripts.

A basic curl example: curl -H 'Authorization: PBSAPIToken=<username>@pam!<tokenname>:<token-secret-value>' "https://<domainname-or-ip>:8007/api2/json/nodes/localhost/tasks?running=true. For self signed certificates, curls -k option is required to accept the certificate and continue with the connection.
 
Does the API deliver tasks for PVE & PBS when they are on same server or do I need to query both by using different ports?
Those are two completely separated api servers, so you will have to query them individually. PVE listens on port 8006, PBS on port 8007

Edit: Of course also with different credentials/api tokens
 
Last edited:
  • Like
Reactions: uihuizui
Bash to check (using python and JSON so you can get other values as well)
Code:
result=$(curl -s -k -H 'Authorization: PBSAPIToken=<username>@pam!<tokenname>:<token-secret-value>' "https://<domainname-or-ip>:8007/api2/json/nodes/localhost/tasks?running=true")
tasks=$(echo $result | python3 -c "import sys, json; print(json.load(sys.stdin)['total'])")
 
trying in my local network:
Code:
curl -s -k -H 'Authorization: PBSAPIToken=root@pam!testN:<token-secret-value>' "https://192.168.0.201:8007/api2/json/nodes/localhost/tasks?running=true"
Always returning
Code:
{"total":0,"data":[]}
 

Attachments

  • Screenshot from 2023-06-10 20-03-34.png
    Screenshot from 2023-06-10 20-03-34.png
    111 KB · Views: 17
  • Screenshot from 2023-06-10 20-02-19.png
    Screenshot from 2023-06-10 20-02-19.png
    51.3 KB · Views: 12
Last edited:
Hi,
an API Token should be used for authorization from scripts.

A basic curl example: curl -H 'Authorization: PBSAPIToken=<username>@pam!<tokenname>:<token-secret-value>' "https://<domainname-or-ip>:8007/api2/json/nodes/localhost/tasks?running=true. For self signed certificates, curls -k option is required to accept the certificate and continue with the connection.

here the returned number increments when the new backup task finishes
Code:
 ....https://192.168.0.201:8007/api2/json/nodes/localhost/tasks\?running=false\&limit=10000 | jq .total

following returns always 0 (even when backup task is started manually from the Proxmox server and from the web interface it is obvious task is still running)
Code:
 ....https://192.168.0.201:8007/api2/json/nodes/localhost/tasks\?running=true\&limit=10000 | jq .total
 
Last edited:
here the returned number increments when the new backup task finishes
Code:
 ....https://192.168.0.201:8007/api2/json/nodes/localhost/tasks\?running=false\&limit=10000 | jq .total

following returns always 0 (even when backup task is started manually from the Proxmox server and from the web interface it is obvious task is still running)
Code:
 ....https://192.168.0.201:8007/api2/json/nodes/localhost/tasks\?running=true\&limit=10000 | jq .total
Set the permissions to /
 
Yes, you can even set it to
Code:
/system/tasks
And I assume you added the API tokenas well to the curl command.
Yes, I use the token.
New problem arise, there are short breaks between backups (multiple Proxmox VMs are backed up) .
I would like to shut the backup server down when the running=false query returns 0 (my backups are once a day starting 23:55 and the time of execution of all backups is in the interval 2minutes - 5 hours).
How to discover if/how many backup tasks are in the schedule waiting to be executed in the future?
 

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!