Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Keep configuration snapshot rotation in its literal instance namespace

pulse-triage[bot]befecbdc84f7
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index ae226a6768..dee8b97d79 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -16,6 +16,24 @@
## Purpose
+### Configuration snapshot rotation stays in its literal instance namespace
+
+The installer's configuration snapshot rotation treats the configured basename
+as literal pathname data. Only its final snapshot-suffix wildcard expands;
+brackets, question marks, asterisks and embedded newlines in a custom name must
+not select another instance's recovery copies or split into a different live
+configuration path. Complete paths remain individual shell words, ordered in
+the C locale. Only immediate real directories qualify: regular files, directory
+symlinks, broken links and absent inventories are not removal candidates.
+
+Default/fixed retention counts, explicit zero retention and preservation of the
+current completed snapshot after a backwards clock step remain unchanged. The
+existing registered `TestRootInstallScriptConfigBackupPublicationPreservesPriorSnapshots`
+executes the real backup/rotation with literal-name, embedded-newline, foreign
+state, file/link and empty-inventory controls. These private text-file fixtures
+prove pathname selection and retention, not application-consistent backups,
+original guest recovery or published/native update acceptance.
+
### macOS native contract Python prerequisite
The native Unix installer inventory invokes the registered frontend workflow
diff --git a/install.sh b/install.sh
index 8a7813393e..e6004dcdff 100644
--- a/install.sh
+++ b/install.sh
@@ -3062,16 +3062,23 @@ prune_config_backups() {
local snapshot_prefix="$2"
local keep="${CONFIG_BACKUP_KEEP_COUNT:-5}"
local current_backup="${3:-}" current_count=0
+ local LC_ALL=C
local backups=()
local entry
- while IFS= read -r entry; do
+ # Expand only the final wildcard, never the instance's literal prefix.
+ # A find -name pattern borrows []?* from a custom config name; line-based
+ # output also turns an embedded newline into a different deletion target.
+ # Bash's ordered pathname expansion keeps each complete path as one word.
+ # Match find's non-following directory scope, including an empty inventory.
+ for entry in "$backup_parent/$snapshot_prefix"*; do
+ [[ -d "$entry" && ! -L "$entry" ]] || continue
if [[ "$entry" == "$current_backup" ]] && (( keep > 0 )); then
current_count=1
continue
fi
- [[ -n "$entry" ]] && backups+=("$entry")
- done < <(find "$backup_parent" -maxdepth 1 -mindepth 1 -type d -name "${snapshot_prefix}*" 2>/dev/null | sort)
+ backups+=("$entry")
+ done
local excess=$(( ${#backups[@]} + current_count - keep ))
if (( excess <= 0 )); then
diff --git a/scripts/installtests/root_install_sh_test.go b/scripts/installtests/root_install_sh_test.go
index 75c4851660..16fd10e96d 100644
--- a/scripts/installtests/root_install_sh_test.go
+++ b/scripts/installtests/root_install_sh_test.go
@@ -2990,6 +2990,9 @@ func TestRootInstallScriptConfigBackupPublicationPreservesPriorSnapshots(t *test
"test_failed_publication_does_not_rotate_or_publish_a_snapshot",
"test_exit_zero_skipped_publication_preserves_file_directory_and_link",
"test_current_snapshot_survives_rotation_even_after_clock_moves_backwards",
+ "test_rotation_uses_the_literal_config_namespace",
+ "test_rotation_keeps_embedded_newlines_inside_each_path",
+ "test_rotation_skips_files_links_and_an_empty_inventory",
"test_incomplete_copy_is_not_another_invocations_rotation_candidate",
"test_discard_removes_only_this_invocations_new_snapshot",
"test_missing_config_clears_stale_ownership_without_deleting_prior_snapshot",
diff --git a/scripts/tests/test_server_config_backups.py b/scripts/tests/test_server_config_backups.py
index fcf14b8dfc..d45bb66a8d 100644
--- a/scripts/tests/test_server_config_backups.py
+++ b/scripts/tests/test_server_config_backups.py
@@ -60,10 +60,13 @@ class ConfigBackupPublication(unittest.TestCase):
return result
def completed(self):
- return sorted(self.config.parent.glob(self.config.name + ".backup.*"))
+ # The configured namespace is data, not a glob in the oracle either.
+ return sorted(p for p in self.config.parent.iterdir()
+ if p.name.startswith(self.config.name + ".backup."))
def assert_no_stages(self):
- self.assertEqual(list(self.config.parent.glob("." + self.config.name + ".backup.*")), [])
+ self.assertEqual([p for p in self.config.parent.iterdir()
+ if p.name.startswith("." + self.config.name + ".backup.")], [])
def assert_prior(self, old):
self.assertEqual((old / "settings.json").read_text(), "prior recovery state\n")
@@ -240,6 +243,69 @@ test -z "$LAST_CONFIG_BACKUP_DIR"
self.assertFalse((self.config.parent / (self.config.name + ".backup.20261024-154500")).exists())
self.assert_no_stages()
+ def test_rotation_uses_the_literal_config_namespace(self):
+ for case, (name, other_name) in enumerate((("config[1]", "config1"),
+ ("config?", "configA"),
+ ("config*", "config-extra"))):
+ for keep in (0, 1, 5):
+ with self.subTest(config=name, keep=keep):
+ self.config = self.root / f"case-{case}-{keep}" / name
+ self.config.mkdir(parents=True)
+ (self.config / "settings.json").write_text("current state\n")
+ prior = [self.old_snapshot(f"202610{day:02d}-154500") for day in range(1, 7)]
+ others = []
+ for day in range(1, 7):
+ path = self.config.parent / f"{other_name}.backup.202610{day:02d}-154500"
+ path.mkdir()
+ (path / "settings.json").write_text("other instance recovery state\n")
+ others.append(path)
+ self.shell('backup_existing\n', CONFIG_BACKUP_KEEP_COUNT=str(keep))
+ for path in others:
+ self.assertEqual((path / "settings.json").read_text(), "other instance recovery state\n")
+ self.assertEqual(len(self.completed()), keep)
+ # The fresh snapshot counts toward retention; remove only
+ # the oldest selected-instance copies, never a peer's.
+ self.assertEqual([p for p in prior if p.exists()], prior[7 - keep:])
+ self.assertEqual((self.config / "settings.json").read_text(), "current state\n")
+ self.assert_no_stages()
+
+ def test_rotation_keeps_embedded_newlines_inside_each_path(self):
+ self.config = self.config.parent / "config\nselected"
+ self.config.mkdir()
+ (self.config / "settings.json").write_text("current state\n")
+ # Splitting find's output used this unrelated live directory as the
+ # first deletion target, rather than the complete snapshot pathname.
+ other = self.config.parent / "config"
+ other.mkdir()
+ (other / "settings.json").write_text("other live instance state\n")
+ prior = [self.old_snapshot(f"202610{day:02d}-154500") for day in range(1, 7)]
+ self.shell('backup_existing\n')
+ self.assertEqual((other / "settings.json").read_text(), "other live instance state\n")
+ self.assertEqual(len(self.completed()), 5)
+ self.assertEqual([p for p in prior if p.exists()], prior[2:])
+ self.assertEqual((self.config / "settings.json").read_text(), "current state\n")
+ self.assert_no_stages()
+
+ def test_rotation_skips_files_links_and_an_empty_inventory(self):
+ prefix = self.config.name + ".backup."
+ outside = self.root / "other instance"
+ outside.mkdir()
+ (outside / "settings.json").write_text("other live instance state\n")
+ link = self.config.parent / (prefix + "20261001-154500")
+ link.symlink_to(outside, target_is_directory=True)
+ broken = self.config.parent / (prefix + "20261002-154500")
+ broken.symlink_to(self.root / "absent")
+ regular = self.config.parent / (prefix + "20261003-154500")
+ regular.write_text("not a snapshot directory\n")
+ self.shell(r'''
+prune_config_backups "$(dirname "$CONFIG_DIR")" "$(basename "$CONFIG_DIR").backup."
+prune_config_backups "$FIXTURE/absent-parent" "absent.backup."
+''', CONFIG_BACKUP_KEEP_COUNT="0")
+ self.assertTrue(link.is_symlink())
+ self.assertTrue(broken.is_symlink())
+ self.assertEqual(regular.read_text(), "not a snapshot directory\n")
+ self.assertEqual((outside / "settings.json").read_text(), "other live instance state\n")
+
def test_incomplete_copy_is_not_another_invocations_rotation_candidate(self):
self.shell(r'''
cp() {