restic: escape environment variables
This allows better handling of, e.g., file names with spaces.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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"):
|
||||
|
||||
Reference in New Issue
Block a user