restic: escape environment variables

This allows better handling of, e.g., file names with spaces.
This commit is contained in:
Robert Helgesson
2026-04-06 08:39:40 +02:00
parent 7e7269ac06
commit 5de7dbd151
3 changed files with 28 additions and 5 deletions
+2 -2
View File
@@ -27,7 +27,7 @@ let
(upper: "RCLONE_" + upper)
];
toEnvVal = v: if lib.isBool v then lib.boolToString v else toString v;
toEnvVal = v: if lib.isBool v then lib.boolToString v else lib.escapeShellArg v;
attrsToEnvs =
attrs:
@@ -55,7 +55,7 @@ let
(attrsToEnvs (
{
RESTIC_PROGRESS_FPS = backup.progressFps;
RESTIC_PASSWORD_COMMAND = lib.escapeShellArg backup.passwordCommand;
RESTIC_PASSWORD_COMMAND = backup.passwordCommand;
RESTIC_PASSWORD_FILE = backup.passwordFile;
RESTIC_REPOSITORY = backup.repository;
RESTIC_REPOSITORY_FILE = backup.repositoryFile;
@@ -52,6 +52,12 @@ in
repository = "/home/alice/repos/basic";
};
repository-spaced = {
inherit passwordFile paths exclude;
initialize = true;
repository = "/home/alice/repos/repository with spaces!";
};
repo-file = {
inherit passwordFile paths exclude;
initialize = true;
+20 -3
View File
@@ -134,6 +134,23 @@ in
f"expected diff -ur restore/basic/home/alice/files files to contain \
{expected1} and {expected2}, but got {actual}"
with subtest("Repository with spaces backup"):
systemctl_succeed_as_alice("start restic-backups-repository-spaced.service")
actual = succeed_as_alice("restic-repository-spaced ls latest")
assert_list("restic-repository-spaced ls latest", expectedIncluded, actual)
assert "exclude" not in actual, \
f"Paths containing \"*exclude*\" got backed up incorrectly. output: {actual}"
with subtest("Repository with spaces restore"):
succeed_as_alice("restic-repository-spaced restore latest --target restore/repository-spaced")
actual = fail_as_alice("diff -urNa restore/repository-spaced/home/alice/files files")
expected1 = "alices-secret-diary"
expected2 = "alices-bank-details"
assert expected1 in actual and expected2 in actual, \
f"expected diff -ur restore/repository-spaced/home/alice/files files to contain \
{expected1} and {expected2}, but got {actual}"
with subtest("Basic backup (password command)"):
systemctl_succeed_as_alice("start restic-backups-basic-command.service")
actual = succeed_as_alice("restic-basic-command ls latest")
@@ -143,12 +160,12 @@ in
f"Paths containing \"*exclude*\" got backed up incorrectly. output: {actual}"
with subtest("Basic restore (password command)"):
succeed_as_alice("restic-basic-command restore latest --target restore/basic")
actual = fail_as_alice("diff -urNa restore/basic/home/alice/files files")
succeed_as_alice("restic-basic-command restore latest --target restore/basic-command")
actual = fail_as_alice("diff -urNa restore/basic-command/home/alice/files files")
expected1 = "alices-secret-diary"
expected2 = "alices-bank-details"
assert expected1 in actual and expected2 in actual, \
f"expected diff -ur restore/basic/home/alice/files files to contain \
f"expected diff -ur restore/basic-command/home/alice/files files to contain \
{expected1} and {expected2}, but got {actual}"
with subtest("Fails to start with an un-initialized repo"):