public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Shannon Sterz <s.sterz@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH manager 09/21] api: node: add endpoints for listing backups for a node
Date: Fri, 28 Aug 2026 15:30:18 +0200	[thread overview]
Message-ID: <20260828133030.351140-10-s.sterz@proxmox.com> (raw)
In-Reply-To: <20260828133030.351140-1-s.sterz@proxmox.com>

GET /nodes/{node}/host-backup now lists backups of a host

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
---
 PVE/API2/HostBackup.pm | 140 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 140 insertions(+)

diff --git a/PVE/API2/HostBackup.pm b/PVE/API2/HostBackup.pm
index 9a0b0dc1d..fe1263a85 100644
--- a/PVE/API2/HostBackup.pm
+++ b/PVE/API2/HostBackup.pm
@@ -18,6 +18,7 @@ use PVE::PBSClient;
 use PVE::Storage::PBSPlugin;
 use PVE::Storage;
 use PVE::Systemd;
+use PVE::Tools qw(extract_param);
 use PVE::VZDump;
 use PVE::pvecfg;
 
@@ -316,6 +317,145 @@ sub complete_proxmox_backup_storage(@) {
     return $res;
 }
 
+__PACKAGE__->register_method({
+    name => 'index',
+    path => '',
+    method => 'GET',
+    proxyto => 'node',
+    protected => 1,
+    description => "List backups for specified node.",
+    permissions => {
+        check => [
+            'and',
+            ['perm', '/', ['Sys.Audit']],
+            [
+                'perm',
+                '/storage/{storage}',
+                ['Datastore.Audit', 'Datastore.AllocateSpace'],
+                any => 1,
+            ],
+        ],
+
+    },
+    parameters => {
+        additionalProperties => 0,
+        properties => {
+            node => get_standard_option('pve-node'),
+            storage => get_standard_option(
+                'pve-storage-id',
+                {
+                    description =>
+                        "The Proxmox Backup Server storage to scan for host backups.",
+                    completion => \&complete_proxmox_backup_storage,
+                    optional => 0,
+                },
+            ),
+        },
+    },
+    returns => {
+        type => 'array',
+        items => {
+            type => 'object',
+            properties => {
+                volid => {
+                    description => "Volume identifier.",
+                    type => 'string',
+                },
+                'format' => {
+                    description => "Always 'pbs-host'.",
+                    type => 'string',
+                },
+                size => {
+                    description =>
+                        "Volume size in bytes. 0 if the size couldn't be determined.",
+                    type => 'integer',
+                    renderer => 'bytes',
+                },
+                ctime => {
+                    description => "Creation time (seconds since the UNIX Epoch).",
+                    type => 'integer',
+                    minimum => 0,
+                    optional => 1,
+                },
+                notes => {
+                    description =>
+                        "Optional notes. If they are multiple lines long, only the first line will "
+                        . "be returned.",
+                    type => 'string',
+                    optional => 1,
+                },
+                encrypted => {
+                    description => "Fingerprint of the encrypted backup if it is encrypted.",
+                    type => 'string',
+                    optional => 1,
+                },
+                verification => {
+                    description => "Last backup verification result.",
+                    type => 'object',
+                    properties => {
+                        state => {
+                            description => "Last backup verification state.",
+                            type => 'string',
+                        },
+                        upid => {
+                            description => "Last backup verification UPID.",
+                            type => 'string',
+                        },
+                    },
+                    optional => 1,
+                },
+                protected => {
+                    description => "Protection status.",
+                    type => 'boolean',
+                    optional => 1,
+                },
+            },
+        },
+        links => [{ rel => 'child', href => "{backup-time}" }],
+    },
+    code => sub($param) {
+        my $storeid = extract_param($param, 'storage');
+        my $cfg = PVE::Storage::config();
+        my $scfg = PVE::Storage::storage_check_enabled($cfg, $storeid, undef, 1);
+
+        croak "storage is not enabled or not available on this host\n" if !defined($scfg);
+        croak "currently only proxmox backup server is supported for host backups\n"
+            if $scfg->{type} ne PVE::Storage::PBSPlugin::type();
+
+        my $pbs = PVE::PBSClient->new($scfg, $storeid);
+
+        my $nodename = extract_param($param, 'node');
+        my $snapshots = $pbs->get_snapshots("host/$nodename");
+
+        my $res = [];
+
+        foreach my $item (@$snapshots) {
+            my ($type, $id, $time) = $item->@{qw(backup-type backup-id backup-time)};
+            next if $type ne 'host';
+
+            my @pxar = grep { $_->{filename} eq 'pve-backup.pxar.didx' } @{ $item->{files} };
+            next if (scalar(@pxar) != 1);
+
+            my $info = {
+                volid => PVE::Storage::PBSPlugin::print_volid($storeid, $type, $id, $time),
+                format => "pbs-$type",
+                size => int($item->{size}),
+                content => 'backup',
+                ctime => $time,
+                subtype => 'host',
+            };
+
+            $info->{verification} = $item->{verification} if defined($item->{verification});
+            $info->{notes} = $item->{comment} if defined($item->{comment});
+            $info->{protected} = 1 if $item->{protected};
+
+            push @$res, $info;
+        }
+
+        return $res;
+    },
+});
+
 __PACKAGE__->register_method({
     name => 'create_backup',
     path => '',
-- 
2.47.3





  parent reply	other threads:[~2026-08-28 13:31 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-28 13:30 [RFC cluster/common/container/docs/installer/manager 00/21] add rudimentary host backup mechanism Shannon Sterz
2026-08-28 13:30 ` [PATCH cluster 01/21] pmxcfs: status: fix formatting of parameters in checked_mkdir() Shannon Sterz
2026-08-28 13:30 ` [PATCH cluster 02/21] pmxcfs: correctly log message when directory can't be created Shannon Sterz
2026-08-28 13:30 ` [PATCH cluster 03/21] pmxcfs: add live backup capability Shannon Sterz
2026-08-28 13:30 ` [PATCH cluster 04/21] pmxcfs: add ability to query backup progress Shannon Sterz
2026-08-28 13:30 ` [PATCH common 05/21] systemd: move parse_os_release() helper to PVE::Systemd Shannon Sterz
2026-08-28 13:30 ` [PATCH container 06/21] setup: use parse_os_release from PVE::Systemd Shannon Sterz
2026-08-28 13:30 ` [PATCH manager 07/21] jobs/api: add basic host backup job logic Shannon Sterz
2026-08-28 13:30 ` [PATCH manager 08/21] api: cluster: add endpoints for manage host backup jobs Shannon Sterz
2026-08-28 13:30 ` Shannon Sterz [this message]
2026-08-28 13:30 ` [PATCH manager 10/21] api: host backup: include global, disk and network options for restore Shannon Sterz
2026-08-28 13:30 ` [PATCH manager 11/21] api: host backup: add warnings in case zfs snapdir is disabled Shannon Sterz
2026-08-28 13:30 ` [PATCH manager 12/21] ui: node: add panel to manage backups of a host Shannon Sterz
2026-08-28 13:30 ` [PATCH manager 13/21] ui: dc: add panel for managing host backup jobs Shannon Sterz
2026-08-28 13:30 ` [PATCH installer 14/21] bump proxmox-installer-types to 0.2 Shannon Sterz
2026-08-28 13:30 ` [PATCH installer 15/21] make tidy and clean up whitespace in unconfigured.sh Shannon Sterz
2026-08-28 13:30 ` [PATCH installer 16/21] installer-common: add option to verify TLS connections via callback Shannon Sterz
2026-08-28 13:30 ` [PATCH installer 17/21] low-level-installer: add support for restoring backups Shannon Sterz
2026-08-28 13:30 ` [PATCH installer 18/21] installer-common/tui-installer: implement restore tui Shannon Sterz
2026-08-28 13:30 ` [PATCH installer 19/21] unconfigured: add restore mode to unconfigured.sh Shannon Sterz
2026-08-28 13:30 ` [PATCH installer 20/21] tui-installer: unmount a potentially mounted backup on abort Shannon Sterz
2026-08-28 13:30 ` [PATCH docs 21/21] examples: add example hook script for host backup jobs Shannon Sterz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260828133030.351140-10-s.sterz@proxmox.com \
    --to=s.sterz@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal