From 16a694a210a6c20bb2d904e9468732dfdf11d6d5 Mon Sep 17 00:00:00 2001 From: Timo Wilken Date: Thu, 2 Nov 2023 23:57:18 +0100 Subject: Cache restic repos depending on repository type It makes more sense never to use a cache for local repositories (since they're on local disk already), but to use it (and keep it clean) for remote REST repositories. --- tw/services/restic.scm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tw/services/restic.scm b/tw/services/restic.scm index 7c912251..7deea24a 100644 --- a/tw/services/restic.scm +++ b/tw/services/restic.scm @@ -55,7 +55,15 @@ password-store entry.") (or (restic-local-repository? thing) (restic-rest-repository? thing))) +(define (restic-cache-policy repository) + "Choose a cache policy restic argument for operating on REPOSITORY." + (cond + ((restic-local-repository? repository) "--no-cache") + ((restic-rest-repository? repository) "--cleanup-cache") + (else (error "Unknown repository type" repository)))) + (define (set-restic-variables repository password-source) + "Return a gexp that sets the right environment variables to access REPOSITORY." (define repo-string (match repository (($ path) @@ -247,7 +255,8 @@ true." #~(begin #$(set-restic-variables repo password) (execl #$(file-append restic "/bin/restic") - "restic" "forget" "--no-cache" + "restic" "forget" + #$(restic-cache-policy repo) #$@(arg-with-value "--prune" prune?) #$@(arg-with-value "--host" snapshot-host) #$@(arg-with-value "--path" snapshot-paths) @@ -317,7 +326,8 @@ must be given. Leading @code{~/} are replaced with @code{$HOME}.") path)) #$(set-restic-variables repo password) (apply execl #$(file-append restic "/bin/restic") - "restic" "backup" "--cleanup-cache" + "restic" "backup" + #$(restic-cache-policy repo) #$@(append-map (lambda (tag) (list "--tag" tag)) tags) (map replace-home '#$paths))))))) (map cronjob configs)) -- cgit v1.2.3