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 installer 17/21] low-level-installer: add support for restoring backups
Date: Fri, 28 Aug 2026 15:30:26 +0200	[thread overview]
Message-ID: <20260828133030.351140-18-s.sterz@proxmox.com> (raw)
In-Reply-To: <20260828133030.351140-1-s.sterz@proxmox.com>

and integrate it with the tui restoring installer.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
---
 Proxmox/Install.pm        | 63 +++++++++++++++++++++++++++++++++++++--
 Proxmox/Install/Config.pm |  6 ++++
 2 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/Proxmox/Install.pm b/Proxmox/Install.pm
index 7bb8e29..1d4f56b 100644
--- a/Proxmox/Install.pm
+++ b/Proxmox/Install.pm
@@ -849,6 +849,9 @@ sub extract_data {
     my $bootloader_err;
     my $diskcount = 0;
 
+    my $backup_mp = Proxmox::Install::Config::get_restore_mount_point();
+    my $kapi;
+
     eval {
         my $maxper = 0.25;
 
@@ -1488,7 +1491,7 @@ _EOD
 
         my $ask_for_patience = "";
         $ask_for_patience = " (multiple disks detected, please be patient)" if $diskcount > 3;
-        update_progress(0.8, 0.95, 1, "make system bootable$ask_for_patience");
+        update_progress(0.5, 0.95, 1, "make system bootable$ask_for_patience");
 
         setup_proxmox_first_boot_service($targetdir);
         stage_subscription_key($targetdir);
@@ -1538,7 +1541,6 @@ _EOD
         diversion_remove($targetdir, "/usr/sbin/update-grub");
         diversion_remove($targetdir, "/usr/sbin/update-initramfs");
 
-        my $kapi;
         foreach my $fn (<$targetdir/lib/modules/*>) {
             if ($fn =~ m!/(\d+\.\d+\.\d+-\d+(?:-\w+)?-pve)$!) {
                 die "found multiple kernels\n" if defined($kapi);
@@ -1610,6 +1612,10 @@ _EOD
 
         diversion_remove($targetdir, "/sbin/start-stop-daemon");
 
+        # return early, the next setup steps are overwritten by the backup and might fail (for
+        # example, setting a root password).
+        return if defined($backup_mp);
+
         setup_root_password($targetdir);
 
         # set root ssh keys
@@ -1697,7 +1703,9 @@ _EOD
 
     my $err = $@;
 
-    update_progress(1, 0, 1, "installation finished");
+    if ($err || !defined($kapi) || !defined($backup_mp)) {
+        update_progress(1, 0, 1, "installation finished");
+    }
 
     print STDERR $err if $err && $err ne "\n";
 
@@ -1709,6 +1717,55 @@ _EOD
             "chroot $targetdir /usr/bin/dpkg-query -W --showformat='\${package}\n'> final.pkglist");
     }
 
+    if (!$err && defined($kapi) && defined($backup_mp)) {
+        eval {
+            update_progress(0.8, 0.95, 1, "restoring backup, this may take a little while...");
+            my @backup_files = glob("$backup_mp/*");
+
+            foreach my $file (@backup_files) {
+                if ($file !~ m/\/(dev|run|tmp|sys|proc|mnt)\/?$/) {
+                    syscmd(["cp", "--archive", "--recursive", "--force", $file, $targetdir]) ==
+                        0
+                        || die("could not restore backup - $!\n");
+                }
+            }
+
+            # Copy the latest pmxcfs backup into the "live" position.
+            my @backed_up_dbs =
+                sort(glob($backup_mp . "/var/lib/pve-cluster/backup/config-backup*.db"));
+            my $db = $backed_up_dbs[-1];
+
+            die "could not restore live pmxcfs db.\n" if !defined($db);
+
+            syscmd([
+                "cp", "--archive", "--force", $db, "$targetdir/var/lib/pve-cluster/config.db",
+                ]) == 0
+                || die("could not restore live pmxcfs backup - $!\n");
+
+            # unmount backup location as we are done restoring. ignore failures,
+            # nothing bad should happen if we reboot here while it's still
+            # mounted.
+            syscmd(["umount", "$backup_mp"]);
+
+            if (!is_test_mode()) {
+                syscmd("mount -n --bind /dev $targetdir/dev"); # re-bind mount dev
+
+                syscmd("chroot $targetdir /usr/sbin/update-initramfs -c -k $kapi") == 0
+                    || die "unable to install initramfs on restore\n";
+
+                syscmd("chroot $targetdir /usr/sbin/update-grub") == 0
+                    || die "unable to update boot loader config on restore\n";
+            }
+        };
+
+        $err = $@;
+        update_progress(1, 0, 1, "installation finished");
+
+        if (!is_test_mode()) {
+            syscmd("umount $targetdir/dev"); # unmount again
+        }
+    }
+
     syscmd("umount $targetdir/run");
     syscmd("umount $targetdir/mnt/hostrun");
     syscmd("umount $targetdir/tmp/pkg");
diff --git a/Proxmox/Install/Config.pm b/Proxmox/Install/Config.pm
index dba3692..00b713f 100644
--- a/Proxmox/Install/Config.pm
+++ b/Proxmox/Install/Config.pm
@@ -121,6 +121,9 @@ my sub init_cfg {
             # and the service files in the proxmox-first-boot package
             ordering_target => 'multi-user', # one of `network-pre`, `network-online` or `multi-user`
         },
+
+        # directory to restore contents from
+        restore_mount_point => undef,
     };
 
     $initial = parse_kernel_cmdline($initial);
@@ -310,4 +313,7 @@ sub get_first_boot_opt {
     return defined($k) ? $opts->{$k} : $opts;
 }
 
+sub get_restore_mount_point { return get('restore_mount_point'); }
+sub set_restore_mount_point { set_key('restore_mount_point', $_[0]); }
+
 1;
-- 
2.47.3





  parent reply	other threads:[~2026-08-28 13:32 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 ` [PATCH manager 09/21] api: node: add endpoints for listing backups for a node Shannon Sterz
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 ` Shannon Sterz [this message]
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-18-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