GNU logs - #72803, boring messages


Message sent to guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] Add restic commands to the restic-guix package
Resent-From: paul <goodoldpaul@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: guix-patches@HIDDEN
Resent-Date: Sun, 25 Aug 2024 13:57:02 +0000
Resent-Message-ID: <handler.72803.B.172459416926984 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: report 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: 72803 <at> debbugs.gnu.org
X-Debbugs-Original-To: guix-patches@HIDDEN
Received: via spool by submit <at> debbugs.gnu.org id=B.172459416926984
          (code B ref -1); Sun, 25 Aug 2024 13:57:02 +0000
Received: (at submit) by debbugs.gnu.org; 25 Aug 2024 13:56:09 +0000
Received: from localhost ([127.0.0.1]:43086 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1siDiy-00071A-KH
	for submit <at> debbugs.gnu.org; Sun, 25 Aug 2024 09:56:09 -0400
Received: from lists.gnu.org ([209.51.188.17]:42250)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <goodoldpaul@HIDDEN>) id 1siDiv-000710-Lg
 for submit <at> debbugs.gnu.org; Sun, 25 Aug 2024 09:56:06 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <goodoldpaul@HIDDEN>)
 id 1siDi7-0008Iw-FW
 for guix-patches@HIDDEN; Sun, 25 Aug 2024 09:55:15 -0400
Received: from confino.investici.org ([2a11:7980:1::2:0])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <goodoldpaul@HIDDEN>)
 id 1siDi3-0006Ja-GH
 for guix-patches@HIDDEN; Sun, 25 Aug 2024 09:55:14 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1724594095;
 bh=Vz4VSDfdJ/LyrTrg6upNKi9qoKxmavoHzmUWAk+bq0M=;
 h=Date:To:From:Subject:From;
 b=ERFKIqo1AT5KMUZqrqc3KexFHGGFHAph+qOitlgaco3qINIRYp3fnTbtusrIeWzEP
 Eew8pJjh+WNAst8jm6wy+LBHfwJyNh2wXIxOOjZkDLY/q3coryxq8RhvdzZAg9GVHV
 wo70pLEbTXit07vmVb6EfVLHaA/7ur66sl6KMSkQ=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4WsFg34Jbwz114Q
 for <guix-patches@HIDDEN>; Sun, 25 Aug 2024 13:54:55 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4WsFg33xvzz112c
 for <guix-patches@HIDDEN>; Sun, 25 Aug 2024 13:54:55 +0000 (UTC)
Content-Type: multipart/alternative;
 boundary="------------9Llavbym5vDHYS1kfkBlgJnK"
Message-ID: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
Date: Sun, 25 Aug 2024 15:54:55 +0200
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
 Thunderbird/102.15.0
Content-Language: en-US
From: paul <goodoldpaul@HIDDEN>
Received-SPF: pass client-ip=2a11:7980:1::2:0;
 envelope-from=goodoldpaul@HIDDEN; helo=confino.investici.org
X-Spam_score_int: -27
X-Spam_score: -2.8
X-Spam_bar: --
X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001,
 RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001,
 T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.4 (-)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.4 (--)

This is a multi-part message in MIME format.
--------------9Llavbym5vDHYS1kfkBlgJnK
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Dear all,

I'm sending a patch adding some more restic commands to the restic-guix 
package provided by the restic-backup-service-type. It allows for 
commands like the following:

restic-guix restore remote-ftp -t `pwd`/restored -i .config/guix/channels.scm latest


Thank you for your work,

giacomo

--------------9Llavbym5vDHYS1kfkBlgJnK
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Dear all,<br>
      <br>
      I'm sending a patch adding some more restic commands to the
      restic-guix package provided by the restic-backup-service-type. It
      allows for commands like the following:<br>
      <br>
    </p>
    <pre>restic-guix restore remote-ftp -t `pwd`/restored -i .config/guix/channels.scm latest
</pre>
    <p><br>
    </p>
    <p>Thank you for your work,<br>
      <br>
      giacomo<br>
    </p>
  </body>
</html>

--------------9Llavbym5vDHYS1kfkBlgJnK--




Message sent:


Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-Mailer: MIME-tools 5.505 (Entity 5.505)
Content-Type: text/plain; charset=utf-8
X-Loop: help-debbugs@HIDDEN
From: help-debbugs@HIDDEN (GNU bug Tracking System)
To: paul <goodoldpaul@HIDDEN>
Subject: bug#72803: Acknowledgement (Add restic commands to the
 restic-guix package)
Message-ID: <handler.72803.B.172459416926984.ack <at> debbugs.gnu.org>
References: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
X-Gnu-PR-Message: ack 72803
X-Gnu-PR-Package: guix-patches
Reply-To: 72803 <at> debbugs.gnu.org
Date: Sun, 25 Aug 2024 13:57:02 +0000

Thank you for filing a new bug report with debbugs.gnu.org.

This is an automatically generated reply to let you know your message
has been received.

Your message is being forwarded to the package maintainers and other
interested parties for their attention; they will reply in due course.

Your message has been sent to the package maintainer(s):
 guix-patches@HIDDEN

If you wish to submit further information on this problem, please
send it to 72803 <at> debbugs.gnu.org.

Please do not send mail to help-debbugs@HIDDEN unless you wish
to report a problem with the Bug-tracking system.

--=20
72803: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D72803
GNU Bug Tracking System
Contact help-debbugs@HIDDEN with problems


Message sent to pelzflorian@HIDDEN, ludo@HIDDEN, matt@HIDDEN, maxim.cournoyer@HIDDEN, guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] [PATCH] services: restic-backup: Add more restic commands to the restic-guix package.
References: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
In-Reply-To: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
Resent-From: Giacomo Leidi <goodoldpaul@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: pelzflorian@HIDDEN, ludo@HIDDEN, matt@HIDDEN, maxim.cournoyer@HIDDEN, guix-patches@HIDDEN
Resent-Date: Sun, 25 Aug 2024 13:58:02 +0000
Resent-Message-ID: <handler.72803.B72803.172459426927369 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: 72803 <at> debbugs.gnu.org
Cc: Giacomo Leidi <goodoldpaul@HIDDEN>, Florian Pelz <pelzflorian@HIDDEN>, Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, Matthew Trzcinski <matt@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>
X-Debbugs-Original-Xcc: Florian Pelz <pelzflorian@HIDDEN>, Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, Matthew Trzcinski <matt@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.172459426927369
          (code B ref 72803); Sun, 25 Aug 2024 13:58:02 +0000
Received: (at 72803) by debbugs.gnu.org; 25 Aug 2024 13:57:49 +0000
Received: from localhost ([127.0.0.1]:43091 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1siDkb-00077M-6v
	for submit <at> debbugs.gnu.org; Sun, 25 Aug 2024 09:57:49 -0400
Received: from confino.investici.org ([93.190.126.19]:57469)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <goodoldpaul@HIDDEN>) id 1siDkZ-00077C-61
 for 72803 <at> debbugs.gnu.org; Sun, 25 Aug 2024 09:57:47 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1724594216;
 bh=obTm9VPEfy4bu0nhnzP6EaZ233KgHgSRRgaVBiUO5MA=;
 h=From:To:Cc:Subject:Date:From;
 b=ouY7Tyr3LBJqhFa4edtamjqvXWkZao4rIEn3T0B3/VrrhDSrY9X0RtDWLAD5M4eGI
 2sjyxLUDZDHDc95ESeEtCZe+zPfC6XlhvN749vc+7HCEw3FX7f615VW5+Fp5LISwY3
 KGXDLgm1v8d12tWqaqxBP/rnZm11DLxPDng6cGdA=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4WsFjN1CB1z112m;
 Sun, 25 Aug 2024 13:56:56 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4WsFjN0Ry3z112c; Sun, 25 Aug 2024 13:56:56 +0000 (UTC)
From: Giacomo Leidi <goodoldpaul@HIDDEN>
Date: Sun, 25 Aug 2024 15:56:41 +0200
Message-ID: <1084765da10bf285803cbb7457997f73f785983d.1724594201.git.goodoldpaul@HIDDEN>
X-Mailer: git-send-email 2.45.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

This patch refactors the way restic commands can be added to the
restic-guix package with a more general approach.  This way new
subcommands for restic-guix can be added more easily.

* gnu/services/backup.scm (restic-backup-job-program): Generalize to
restic-action-program;
(restic-guix): allow for multiple actions.

* doc/guix.texi: Document it.

Change-Id: Ib2b5d74bebc51e35f1ae6e1aa32cedee0da59697
---
 doc/guix.texi           |  10 +++-
 gnu/services/backup.scm | 116 +++++++++++++++++++++++++++++-----------
 2 files changed, 93 insertions(+), 33 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index fcaf6b3fbb..9bbc2694ec 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -41589,7 +41589,15 @@ Miscellaneous Services
 configuration, without waiting for the scheduled job:
 
 @example
-restic-guix backup remote-ftp
+restic-guix run remote-ftp
+@end example
+
+All arguments passed after the job name will be passed to the underlying
+@code{restic} command, together with the @code{extra-flags} field from the
+@code{restic-backup-job} record:
+
+@example
+restic-guix restore remote-ftp -t `pwd`/restored -i .config/guix/channels.scm latest
 @end example
 
 @c %start of fragment
diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm
index 555e9fc959..f304361263 100644
--- a/gnu/services/backup.scm
+++ b/gnu/services/backup.scm
@@ -46,7 +46,7 @@ (define-module (gnu services backup)
             restic-backup-configuration-fields
             restic-backup-configuration-jobs
 
-            restic-backup-job-program
+            restic-action-program
             restic-backup-job->mcron-job
             restic-guix
             restic-guix-wrapper-package
@@ -107,15 +107,18 @@ (define-configuration/no-serialization restic-backup-configuration
    (list-of-restic-backup-jobs '())
    "The list of backup jobs for the current system."))
 
-(define (restic-backup-job-program config)
+(define %restic-guix-supported-actions
+  '("backup" "mount" "prune" "restore" "run" "unlock"))
+
+(define* (restic-action-program config action)
   (let ((restic
          (file-append (restic-backup-job-restic config) "/bin/restic"))
+        (name
+         (restic-backup-job-name config))
         (repository
          (restic-backup-job-repository config))
         (password-file
          (restic-backup-job-password-file config))
-        (files
-         (restic-backup-job-files config))
         (extra-flags
          (restic-backup-job-extra-flags config))
         (verbose
@@ -123,55 +126,104 @@ (define (restic-backup-job-program config)
              '("--verbose")
              '())))
     (program-file
-     "restic-backup-job.scm"
+     (string-append "restic-" action "-" name "-program.scm")
      #~(begin
          (use-modules (ice-9 popen)
-                      (ice-9 rdelim))
+                      (ice-9 rdelim)
+                      (srfi srfi-1))
+
+         (define cli-arguments
+           (let* ((cl (command-line))
+                  (argc (length cl)))
+             (if (> argc 1)
+                 (take-right cl (- argc 1))
+                 '())))
+
          (setenv "RESTIC_PASSWORD"
                  (with-input-from-file #$password-file read-line))
 
-         (execlp #$restic #$restic #$@verbose
-                 "-r" #$repository
-                 #$@extra-flags
-                 "backup" #$@files)))))
+         (apply execlp `(#$restic #$restic #$@verbose
+                         "-r" #$repository
+                         #$@extra-flags
+                         #$action ,@cli-arguments))))))
+
+(define* (restic-guix jobs #:key (supported-actions
+                                  %restic-guix-supported-actions))
+  (define action-table
+    (map
+     (lambda (action)
+       (list action
+             (map (lambda (job)
+                    (list (restic-backup-job-name job)
+                          (restic-action-program job action)))
+                  jobs)))
+     ;; run is an alias for backup
+     (filter (lambda (a) (not (string=? a "run"))) supported-actions)))
 
-(define (restic-guix jobs)
   (program-file
    "restic-guix"
    #~(begin
        (use-modules (ice-9 match)
                     (srfi srfi-1))
 
+       (define action-table '#$action-table)
+       (define (assoc-table key table)
+         (first
+          (filter-map
+           (match-lambda
+             ((k v)
+              (and (string=? key k) v)))
+           table)))
        (define names '#$(map restic-backup-job-name jobs))
-       (define programs '#$(map restic-backup-job-program jobs))
+       (define backup-files
+         '#$(map restic-backup-job-files jobs))
+
+       (define (get-program action name)
+         (assoc-table name (assoc-table action action-table)))
 
-       (define (get-program name)
+       (define (get-backup-files name)
          (define idx
            (list-index (lambda (n) (string=? n name)) names))
-         (unless idx
-           (error (string-append "Unknown job name " name "\n\n"
-                                 "Possible job names are: "
-                                 (string-join names " "))))
-         (list-ref programs idx))
-
-       (define (backup args)
-         (define name (third args))
-         (define program (get-program name))
-         (execlp program program))
+         (list-ref backup-files idx))
 
        (define (validate-args args)
-         (when (not (>= (length args) 3))
-           (error (string-append "Usage: " (basename (car args))
-                                 " backup NAME"))))
+         (unless (>= (length args) 2)
+           (error (string-append "Usage: " (basename (first args))
+                                 " ACTION [ARGS]\n\nSupported actions are: "
+                                 #$(string-join supported-actions ", ") ".")))
+         (unless (member (second args) '#$supported-actions)
+           (error (string-append "Unknown action: " (second args) ". Supported"
+                                 "actions are: "
+                                 #$(string-join supported-actions ", ") "."))))
+
+       (define (validate-action-args action args)
+         (define argc (length args))
+         (when (not (>= argc 3))
+           (error (string-append "Usage: " (basename (first args))
+                                 " " action " JOB_NAME [ARGS]\n\nPossible job "
+                                 "names are: " (string-join names ", ") ".")))
+         (define job-name (third args))
+         (unless (member job-name names)
+           (error (string-append "Unknown job name: " job-name ". Possible job "
+                                 "names are: " (string-join names ", ") ".")))
+         (let ((program
+                (get-program
+                 ;; run is just backup called with restic-backup-job-files
+                 (if (string=? action "run") "backup" action)
+                 job-name))
+               (rest (if (> argc 3)
+                         (take-right args (- argc 3))
+                         '())))
+           (values program
+                   (if (string=? action "run")
+                       (append rest (get-backup-files job-name))
+                       rest))))
 
        (define (main args)
          (validate-args args)
          (define action (second args))
-         (match action
-           ("backup"
-            (backup args))
-           (_
-            (error (string-append "Unknown action: " action)))))
+         (define-values (program action-args) (validate-action-args action args))
+         (apply execlp (append (list program program) action-args)))
 
        (main (command-line)))))
 
@@ -183,7 +235,7 @@ (define (restic-backup-job->mcron-job config)
         (name
          (restic-backup-job-name config)))
     #~(job #$schedule
-           #$(string-append "restic-guix backup " name)
+           #$(string-append "restic-guix run " name)
            #:user #$user)))
 
 (define (restic-guix-wrapper-package jobs)

base-commit: d48af5cca84914d44b032d0bf0820640ebbe7a4b
-- 
2.45.2





Message sent to guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] Add restic commands to the restic-guix package
References: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
Resent-From: Fabio Natali <me@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: guix-patches@HIDDEN
Resent-Date: Mon, 02 Sep 2024 22:52:02 +0000
Resent-Message-ID: <handler.72803.B72803.17253174914735 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: 72803 <at> debbugs.gnu.org
Cc: Giacomo Leidi <goodoldpaul@HIDDEN>
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.17253174914735
          (code B ref 72803); Mon, 02 Sep 2024 22:52:02 +0000
Received: (at 72803) by debbugs.gnu.org; 2 Sep 2024 22:51:31 +0000
Received: from localhost ([127.0.0.1]:52863 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1slFtS-0001EJ-JQ
	for submit <at> debbugs.gnu.org; Mon, 02 Sep 2024 18:51:31 -0400
Received: from relay7-d.mail.gandi.net ([217.70.183.200]:45891)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <me@HIDDEN>) id 1slFtP-0001Dy-5E
 for 72803 <at> debbugs.gnu.org; Mon, 02 Sep 2024 18:51:29 -0400
Received: by mail.gandi.net (Postfix) with ESMTPSA id 0276020002;
 Mon,  2 Sep 2024 22:50:18 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fabionatali.com;
 s=gm1; t=1725317419;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 in-reply-to:in-reply-to; bh=zVwD/Hx7vdZFJhIk5GDsRn673VPz4/5kMwYrr0fM0fE=;
 b=Vt2lesrIFuR1uRv2RqeKHTpF54DDporhHOKlQ/jF43KpPuio4d+7tIxlBAb3xIeFocn5f4
 Up3OG7wboT02ab9P/mevL0tgdTg2ffMk+UmGMO5o3urlrVG6NtRGN/PxXSFpxuoi1BWaxf
 fn4b5/N9GiZFEcj18ONqmHzJ8gQgXtd497t0wOQGyU/Iw9QI1yx59ZMk0rKHxKPY51L+nt
 4T2Bl+HjmSTd++PavUO4kqbTWEq3MxisIfTdixoDUqainB6OqWTTdJXoIkb1uv7ry+oRcs
 dvpH6ms4ax4eYYsha7cFvNDdDbbmya/g7DDGcE3WsH917gIRvbGyB4Sv9asz9Q==
From: Fabio Natali <me@HIDDEN>
In-Reply-To: <1084765da10bf285803cbb7457997f73f785983d.1724594201.git.goodoldpaul@HIDDEN>
Date: Mon, 02 Sep 2024 23:50:17 +0100
Message-ID: <8734mhfz6e.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-GND-Sasl: me@HIDDEN
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

Hi Giacomo,

Thanks for the patch and for the Restic service in the first place.

> diff --git a/doc/guix.texi b/doc/guix.texi

In the manual, consider the "extra-flags" section where we say:

> A list of values that are lowered to strings. These will be passed as
> command-line arguments to the current job restic backup invokation.

Perhaps this should now read "...the current job restic invokation..."
or "...the current restic invokation...", as the action is no longer
limited to "backup"?

>      (program-file
> -     "restic-backup-job.scm"
> +     (string-append "restic-" action "-" name "-program.scm")

Should 'name' be slug-ified in any way here? E.g. to avoid spaces,
capital letters, symbols that might be confusing when part of a file
name, etc.

> +  (define action-table
> +    (map
> +     (lambda (action)
> +       (list action
> +             (map (lambda (job)
> +                    (list (restic-backup-job-name job)
> +                          (restic-action-program job action)))
> +                  jobs)))
> +     ;; run is an alias for backup
> +     (filter (lambda (a) (not (string=? a "run"))) supported-actions)))

Could this be (marginally) simpler if we used two nested association
lists? That way, 'get-program' might simply use 'assoc-ref' (twice) and
'assoc-table' would be redundant?

Everything else looks fine to me. For what it's worth, here's how I've
been testing this.

Initialise a Restic repository as follows (warning: this overwrites
'/some-temporary-folder/password'):

--8<---------------cut here---------------start------------->8---
mkdir /some-temporary-folder
export RESTIC_PASSWORD=password
restic init --repo=/some-temporary-folder/repository
echo "${RESTIC_PASSWORD}" > /some-temporary-folder/password
--8<---------------cut here---------------end--------------->8---

Save the following system definition as
'/some-temporary-folder/config.scm'.

--8<---------------cut here---------------start------------->8---
(use-modules (gnu))
(use-package-modules backup)
(use-service-modules backup)

(operating-system
  (host-name "host")
  (bootloader (bootloader-configuration
               (bootloader grub-bootloader)
               (targets '("/dev/vda"))))
  (file-systems (cons (file-system
                        (device "/dev/vda1")
                        (mount-point "/")
                        (type "ext4"))
                      %base-file-systems))
  (packages (cons* restic %base-packages))
  (services (cons*
             (service restic-backup-service-type
                      (restic-backup-configuration
                       (jobs
                        (list (restic-backup-job
                               (name "test")
                               (repository "/restic/repository")
                               (password-file "/restic/password")
                               (schedule "* * * * *")
                               (files '("/root")))))))
             %base-services)))
--8<---------------cut here---------------end--------------->8---

From a Guix checkout where this patch has been applied, launch a test VM
as follows:

--8<---------------cut here---------------start------------->8---
$(./pre-inst-env guix system vm \
    --no-graphic \
    --share=/some-temporary-folder=/restic \
    /tmp/config.scm) \
    -m 2048 -smp 2
--8<---------------cut here---------------end--------------->8---

Log in as root, then check that the cron schedule is correctly defined
with 'herd schedule mcron', backup jobs should be scheduled every
minute.

Mount the Restic repository to see that snapshots have been actually
created every minute since boot. This can be done either on the guest or
on the host system. E.g. on the guest:

--8<---------------cut here---------------start------------->8---
restic mount \
    --password-file=/restic/password \
    --repo=/restic/repository \
    /mnt
--8<---------------cut here---------------end--------------->8---

Unfortunately I don't have commit access to push this, but hopefully
someone else will have a second look and push it soon.

It'd be nice to have a little test suite for this, but in case this can
be part of a future patch.

HTH, thanks, Fabio.




Message sent to guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] Add restic commands to the restic-guix package
References: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
Resent-From: Fabio Natali <me@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: guix-patches@HIDDEN
Resent-Date: Mon, 02 Sep 2024 23:04:01 +0000
Resent-Message-ID: <handler.72803.B72803.17253181856423 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: 72803 <at> debbugs.gnu.org
Cc: Giacomo Leidi <goodoldpaul@HIDDEN>, Fabio Natali <me@HIDDEN>
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.17253181856423
          (code B ref 72803); Mon, 02 Sep 2024 23:04:01 +0000
Received: (at 72803) by debbugs.gnu.org; 2 Sep 2024 23:03:05 +0000
Received: from localhost ([127.0.0.1]:52887 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1slG4f-0001fV-0W
	for submit <at> debbugs.gnu.org; Mon, 02 Sep 2024 19:03:05 -0400
Received: from relay7-d.mail.gandi.net ([217.70.183.200]:39915)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <me@HIDDEN>) id 1slG4b-0001el-N1
 for 72803 <at> debbugs.gnu.org; Mon, 02 Sep 2024 19:03:03 -0400
Received: by mail.gandi.net (Postfix) with ESMTPSA id 7A70C20005;
 Mon,  2 Sep 2024 23:01:53 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fabionatali.com;
 s=gm1; t=1725318113;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 in-reply-to:in-reply-to; bh=YoLMbn0Frt9hrziQFuh/qhto9XBxskKAfmlmo+xsbmE=;
 b=CD7PABTgIbM8+YW/WDu5vY8FMckLy6z8piMYnZ5Bf7ZL5n1Iayiw2K91wFrts9rOmif7r4
 2cz+13CjACRO9xo7ZLEt9Dv5lqPW/pmH90bQTaqM5gluXriXeTt+66vabnnw+X/3bGudD/
 iTJ0D8/bXlLm6Jlth416ShAE1qgNNO5qkWvmJvIvUh4ApaqijEPezUIVYVepoVdRD5RkYi
 6/WvKD1TLU+nLHywYRLStHuujB5pXc55tDLvyonEzXn8P7iFb77RfUmkbeFalaTtLWp6bD
 p77o+sP7PCxlwUpb6mSQd+XllRf6fykJU4va0QUmPZDfw2sX/RkaIoqqpxlNGg==
From: Fabio Natali <me@HIDDEN>
In-Reply-To: <8734mhfz6e.fsf@HIDDEN>
Date: Tue, 03 Sep 2024 00:01:53 +0100
Message-ID: <87zfopek2m.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-GND-Sasl: me@HIDDEN
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

> Mount the Restic repository to see that snapshots have been actually
> created every minute since boot.

Ha, sorry, I should have mentioned the revised 'restic-guix' script too,
which I tested with various commands and that also seemed to be working
fine.

Thanks, cheers, Fabio.




Message sent to guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] Add restic commands to the restic-guix package
Resent-From: paul <goodoldpaul@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: guix-patches@HIDDEN
Resent-Date: Wed, 04 Sep 2024 22:29:02 +0000
Resent-Message-ID: <handler.72803.B72803.172548891213639 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: Fabio Natali <me@HIDDEN>, 72803 <at> debbugs.gnu.org
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.172548891213639
          (code B ref 72803); Wed, 04 Sep 2024 22:29:02 +0000
Received: (at 72803) by debbugs.gnu.org; 4 Sep 2024 22:28:32 +0000
Received: from localhost ([127.0.0.1]:35668 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1slyUJ-0003Xv-Qv
	for submit <at> debbugs.gnu.org; Wed, 04 Sep 2024 18:28:32 -0400
Received: from confino.investici.org ([93.190.126.19]:53753)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <goodoldpaul@HIDDEN>) id 1slyUH-0003Xm-Gi
 for 72803 <at> debbugs.gnu.org; Wed, 04 Sep 2024 18:28:30 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1725488370;
 bh=vT0v2NinRalB07FtU5TYR734hAVl9aFfeLVRv6hEXno=;
 h=Date:Subject:To:References:From:In-Reply-To:From;
 b=lncECCmmyp3dWmzhDEcJwQTx0Aa6wNMpMNhBc+23Px5F6NG6hSn2ru4mbLp0RlE1i
 sITSltcirCLPgiIg4ZQCp95wQ8RrVkfAN1GsqdMZ6CKP0vxlwPznRrQilwtezpPE/2
 z0wsZaBdz+oJXbhYw2wtoFNDnJsVfc/NgnFIYqhQ=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4WzcNf5PGGz1143;
 Wed,  4 Sep 2024 22:19:30 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4WzcNf4mcGz112X; Wed,  4 Sep 2024 22:19:30 +0000 (UTC)
Message-ID: <2d83c75b-b750-b80d-5d7c-b4a6c89b4434@HIDDEN>
Date: Thu, 5 Sep 2024 00:19:30 +0200
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
 Thunderbird/102.15.0
References: <8734mhfz6e.fsf@HIDDEN>
Content-Language: en-US
From: paul <goodoldpaul@HIDDEN>
In-Reply-To: <8734mhfz6e.fsf@HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Spam-Score: -1.9 (-)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.9 (--)

Hi Fabio,

thank you very much for your detailed testing and review.

On 9/3/24 00:50, Fabio Natali wrote:
> Perhaps this should now read "...the current job restic invokation..."
> or "...the current restic invokation...", as the action is no longer
> limited to "backup"?

Definitely, good catch.

>>       (program-file
>> -     "restic-backup-job.scm"
>> +     (string-append "restic-" action "-" name "-program.scm")
> Should 'name' be slug-ified in any way here? E.g. to avoid spaces,
> capital letters, symbols that might be confusing when part of a file
> name, etc.
It should, right. I'll use the same approach used for the 
home-dotfiles-service-type (i.e. replacing illegal characters with "-").
>> +  (define action-table
>> +    (map
>> +     (lambda (action)
>> +       (list action
>> +             (map (lambda (job)
>> +                    (list (restic-backup-job-name job)
>> +                          (restic-action-program job action)))
>> +                  jobs)))
>> +     ;; run is an alias for backup
>> +     (filter (lambda (a) (not (string=? a "run"))) supported-actions)))
> Could this be (marginally) simpler if we used two nested association
> lists? That way, 'get-program' might simply use 'assoc-ref' (twice) and
> 'assoc-table' would be redundant?
I thought that as well, in fact my first implementation was with Guile's 
vhashes but it appears that neither alists nor vhashesh can be correctly 
ungexped, or at least I didn't find a way to do so. This is why I'm 
using plain lists and I need assoc-table. If you have some pointer where 
I could look how to lower alists it would be very helpful.
> It'd be nice to have a little test suite for this, but in case this can
> be part of a future patch.

There are already some tests Richard made at #71639 , once they get in 
I'll make sure to expand them for additional restic-guix subcommands.

Thank your for your review Fabio, I'm sending a patchset addressing your 
comments.

giacomo





Message sent to pelzflorian@HIDDEN, ludo@HIDDEN, maxim.cournoyer@HIDDEN, guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] [PATCH v2] services: restic-backup: Add more restic commands to the restic-guix package.
References: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
In-Reply-To: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
Resent-From: Giacomo Leidi <goodoldpaul@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: pelzflorian@HIDDEN, ludo@HIDDEN, maxim.cournoyer@HIDDEN, guix-patches@HIDDEN
Resent-Date: Wed, 04 Sep 2024 22:31:02 +0000
Resent-Message-ID: <handler.72803.B72803.172548903213980 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: 72803 <at> debbugs.gnu.org
Cc: Giacomo Leidi <goodoldpaul@HIDDEN>, Florian Pelz <pelzflorian@HIDDEN>, Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>
X-Debbugs-Original-Xcc: Florian Pelz <pelzflorian@HIDDEN>, Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.172548903213980
          (code B ref 72803); Wed, 04 Sep 2024 22:31:02 +0000
Received: (at 72803) by debbugs.gnu.org; 4 Sep 2024 22:30:32 +0000
Received: from localhost ([127.0.0.1]:35678 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1slyWF-0003dP-If
	for submit <at> debbugs.gnu.org; Wed, 04 Sep 2024 18:30:32 -0400
Received: from confino.investici.org ([93.190.126.19]:60313)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <goodoldpaul@HIDDEN>) id 1slyWE-0003dI-Dr
 for 72803 <at> debbugs.gnu.org; Wed, 04 Sep 2024 18:30:31 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1725488958;
 bh=7HwOFB1BF1Uq8kEoj3V/SDn9X2A6eD4zAo9AVcKztT0=;
 h=From:To:Cc:Subject:Date:From;
 b=Lwhvgbn1Kv+TkuMHHf8v7zrbmxdcBMqwbrc/br/23Xs10l/EByEjCQ5+rPSOqLnBs
 kedMmywa9YWIVoadZ7JN2aLA/dY+lSHRPlcbpgSDPzotAlXCNCn+ZHpJQ6o+xtVEWk
 7b5y2/GcKakl/RvTuftGciWoz/TqOJHIz7xNwH10=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4Wzcby3hwQz115w;
 Wed,  4 Sep 2024 22:29:18 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4Wzcby2wR3z114S; Wed,  4 Sep 2024 22:29:18 +0000 (UTC)
From: Giacomo Leidi <goodoldpaul@HIDDEN>
Date: Thu,  5 Sep 2024 00:29:04 +0200
Message-ID: <cba87a67ff4b6dfdc7620b45c9fec4d1ee0321bc.1725488944.git.goodoldpaul@HIDDEN>
X-Mailer: git-send-email 2.45.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

This patch refactors the way restic commands can be added to the
restic-guix package with a more general approach.  This way new
subcommands for restic-guix can be added more easily.

* gnu/services/backup.scm (restic-backup-job-program): Generalize to
restic-action-program;
(restic-guix): allow for multiple actions.

* doc/guix.texi: Document it.

Change-Id: Ib2b5d74bebc51e35f1ae6e1aa32cedee0da59697
---
 doc/guix.texi           |  13 +++-
 gnu/services/backup.scm | 127 +++++++++++++++++++++++++++++-----------
 2 files changed, 104 insertions(+), 36 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 16c697586a..8e3ecb80c2 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -41611,7 +41611,15 @@ Miscellaneous Services
 configuration, without waiting for the scheduled job:
 
 @example
-restic-guix backup remote-ftp
+restic-guix run remote-ftp
+@end example
+
+All arguments passed after the job name will be passed to the underlying
+@code{restic} command, together with the @code{extra-flags} field from the
+@code{restic-backup-job} record:
+
+@example
+restic-guix restore remote-ftp -t `pwd`/restored -i .config/guix/channels.scm latest
 @end example
 
 @c %start of fragment
@@ -41667,8 +41675,7 @@ Miscellaneous Services
 
 @item @code{extra-flags} (default: @code{'()}) (type: list-of-lowerables)
 A list of values that are lowered to strings.  These will be passed as
-command-line arguments to the current job @command{restic backup}
-invokation.
+command-line arguments to the current @command{restic} invokation.
 
 @end table
 
diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm
index 555e9fc959..83d388143e 100644
--- a/gnu/services/backup.scm
+++ b/gnu/services/backup.scm
@@ -46,7 +46,7 @@ (define-module (gnu services backup)
             restic-backup-configuration-fields
             restic-backup-configuration-jobs
 
-            restic-backup-job-program
+            restic-action-program
             restic-backup-job->mcron-job
             restic-guix
             restic-guix-wrapper-package
@@ -97,7 +97,7 @@ (define-configuration/no-serialization restic-backup-job
   (extra-flags
    (list-of-lowerables '())
    "A list of values that are lowered to strings.  These will be passed as
-command-line arguments to the current job @command{restic backup} invokation."))
+command-line arguments to the current @command{restic} invokation."))
 
 (define list-of-restic-backup-jobs?
   (list-of restic-backup-job?))
@@ -107,15 +107,27 @@ (define-configuration/no-serialization restic-backup-configuration
    (list-of-restic-backup-jobs '())
    "The list of backup jobs for the current system."))
 
-(define (restic-backup-job-program config)
+(define %restic-guix-supported-actions
+  '("backup" "mount" "prune" "restore" "run" "snapshots" "unlock"))
+
+(define* (restic-action-program config action)
+  (define (format name)
+    ;; Remove from NAME characters that cannot be used in the store.
+    (string-map (lambda (chr)
+                  (if (and (char-set-contains? char-set:ascii chr)
+                           (char-set-contains? char-set:graphic chr)
+                           (not (memv chr '(#\. #\/ #\space))))
+                      chr
+                      #\-))
+                name))
   (let ((restic
          (file-append (restic-backup-job-restic config) "/bin/restic"))
+        (name
+         (restic-backup-job-name config))
         (repository
          (restic-backup-job-repository config))
         (password-file
          (restic-backup-job-password-file config))
-        (files
-         (restic-backup-job-files config))
         (extra-flags
          (restic-backup-job-extra-flags config))
         (verbose
@@ -123,55 +135,104 @@ (define (restic-backup-job-program config)
              '("--verbose")
              '())))
     (program-file
-     "restic-backup-job.scm"
+     (string-append "restic-" action "-" (format name) "-program.scm")
      #~(begin
          (use-modules (ice-9 popen)
-                      (ice-9 rdelim))
+                      (ice-9 rdelim)
+                      (srfi srfi-1))
+
+         (define cli-arguments
+           (let* ((cl (command-line))
+                  (argc (length cl)))
+             (if (> argc 1)
+                 (take-right cl (- argc 1))
+                 '())))
+
          (setenv "RESTIC_PASSWORD"
                  (with-input-from-file #$password-file read-line))
 
-         (execlp #$restic #$restic #$@verbose
-                 "-r" #$repository
-                 #$@extra-flags
-                 "backup" #$@files)))))
+         (apply execlp `(#$restic #$restic #$@verbose
+                         "-r" #$repository
+                         #$@extra-flags
+                         #$action ,@cli-arguments))))))
+
+(define* (restic-guix jobs #:key (supported-actions
+                                  %restic-guix-supported-actions))
+  (define action-table
+    (map
+     (lambda (action)
+       (list action
+             (map (lambda (job)
+                    (list (restic-backup-job-name job)
+                          (restic-action-program job action)))
+                  jobs)))
+     ;; run is an alias for backup
+     (filter (lambda (a) (not (string=? a "run"))) supported-actions)))
 
-(define (restic-guix jobs)
   (program-file
    "restic-guix"
    #~(begin
        (use-modules (ice-9 match)
                     (srfi srfi-1))
 
+       (define action-table '#$action-table)
+       (define (assoc-table key table)
+         (first
+          (filter-map
+           (match-lambda
+             ((k v)
+              (and (string=? key k) v)))
+           table)))
        (define names '#$(map restic-backup-job-name jobs))
-       (define programs '#$(map restic-backup-job-program jobs))
+       (define backup-files
+         '#$(map restic-backup-job-files jobs))
+
+       (define (get-program action name)
+         (assoc-table name (assoc-table action action-table)))
 
-       (define (get-program name)
+       (define (get-backup-files name)
          (define idx
            (list-index (lambda (n) (string=? n name)) names))
-         (unless idx
-           (error (string-append "Unknown job name " name "\n\n"
-                                 "Possible job names are: "
-                                 (string-join names " "))))
-         (list-ref programs idx))
-
-       (define (backup args)
-         (define name (third args))
-         (define program (get-program name))
-         (execlp program program))
+         (list-ref backup-files idx))
 
        (define (validate-args args)
-         (when (not (>= (length args) 3))
-           (error (string-append "Usage: " (basename (car args))
-                                 " backup NAME"))))
+         (unless (>= (length args) 2)
+           (error (string-append "Usage: " (basename (first args))
+                                 " ACTION [ARGS]\n\nSupported actions are: "
+                                 #$(string-join supported-actions ", ") ".")))
+         (unless (member (second args) '#$supported-actions)
+           (error (string-append "Unknown action: " (second args) ". Supported"
+                                 "actions are: "
+                                 #$(string-join supported-actions ", ") "."))))
+
+       (define (validate-action-args action args)
+         (define argc (length args))
+         (when (not (>= argc 3))
+           (error (string-append "Usage: " (basename (first args))
+                                 " " action " JOB_NAME [ARGS]\n\nPossible job "
+                                 "names are: " (string-join names ", ") ".")))
+         (define job-name (third args))
+         (unless (member job-name names)
+           (error (string-append "Unknown job name: " job-name ". Possible job "
+                                 "names are: " (string-join names ", ") ".")))
+         (let ((program
+                (get-program
+                 ;; run is just backup called with restic-backup-job-files
+                 (if (string=? action "run") "backup" action)
+                 job-name))
+               (rest (if (> argc 3)
+                         (take-right args (- argc 3))
+                         '())))
+           (values program
+                   (if (string=? action "run")
+                       (append rest (get-backup-files job-name))
+                       rest))))
 
        (define (main args)
          (validate-args args)
          (define action (second args))
-         (match action
-           ("backup"
-            (backup args))
-           (_
-            (error (string-append "Unknown action: " action)))))
+         (define-values (program action-args) (validate-action-args action args))
+         (apply execlp (append (list program program) action-args)))
 
        (main (command-line)))))
 
@@ -183,7 +244,7 @@ (define (restic-backup-job->mcron-job config)
         (name
          (restic-backup-job-name config)))
     #~(job #$schedule
-           #$(string-append "restic-guix backup " name)
+           #$(string-append "restic-guix run " name)
            #:user #$user)))
 
 (define (restic-guix-wrapper-package jobs)

base-commit: 9a03ab25ba889be27b34d5cebea05d5ac3b0a033
-- 
2.45.2





Message sent to guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] Add restic commands to the restic-guix package
References: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
In-Reply-To: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
Resent-From: paul <goodoldpaul@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: guix-patches@HIDDEN
Resent-Date: Sun, 20 Oct 2024 22:59:02 +0000
Resent-Message-ID: <handler.72803.B72803.17294651418834 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: 72803 <at> debbugs.gnu.org
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.17294651418834
          (code B ref 72803); Sun, 20 Oct 2024 22:59:02 +0000
Received: (at 72803) by debbugs.gnu.org; 20 Oct 2024 22:59:01 +0000
Received: from localhost ([127.0.0.1]:49267 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1t2et3-0002IO-Cg
	for submit <at> debbugs.gnu.org; Sun, 20 Oct 2024 18:59:01 -0400
Received: from confino.investici.org ([93.190.126.19]:42323)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <goodoldpaul@HIDDEN>) id 1t2et2-0002IH-5l
 for 72803 <at> debbugs.gnu.org; Sun, 20 Oct 2024 18:59:00 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1729465106;
 bh=naoZA5+Bl0ONg4fz7DziC0fcpvd8l2Wz/hAB061hA/E=;
 h=Date:To:From:Subject:From;
 b=C8Y4malt1mYbgGLDyns/vTDeK5lJ4Lu1LiqWWyEyYED5HdsYZ/5D9/KLRY/DKi0wm
 jvEhslNS1NFZENy/ACIHnrmtYsVgSky48FU9KvljA6RBJC3xrwveAB09WI5PvJNl5D
 OoLf6PSYqL79LelJgm+CGZ2jerzcCuVzNl69faq8=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4XWv4L4gZ1z10y2
 for <72803 <at> debbugs.gnu.org>; Sun, 20 Oct 2024 22:58:26 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4XWv4L4GzLz10xr
 for <72803 <at> debbugs.gnu.org>; Sun, 20 Oct 2024 22:58:26 +0000 (UTC)
Content-Type: multipart/alternative;
 boundary="------------2pT8kZ5kP4Ob0Y3A60w5rWFC"
Message-ID: <dd908cb9-d4b7-4c5e-84f8-d9a7d6e625c9@HIDDEN>
Date: Mon, 21 Oct 2024 00:58:26 +0200
MIME-Version: 1.0
User-Agent: Icedove Daily
Content-Language: en-US
From: paul <goodoldpaul@HIDDEN>
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

This is a multi-part message in MIME format.
--------------2pT8kZ5kP4Ob0Y3A60w5rWFC
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Guix , this is a friendly ping. I'm sending a patchset rebased on 
current master.

Thank you for your work,

giacomo

--------------2pT8kZ5kP4Ob0Y3A60w5rWFC
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE html>
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p> </p>
    <div class="moz-text-html" lang="x-unicode">
      <p> </p>
      <div class="moz-text-flowed"
        style="font-family: -moz-fixed; font-size: 12px;"
        lang="x-unicode">Hi Guix , this is a friendly ping. I'm sending
        a patchset rebased on current master. <br>
        <br>
        Thank you for your work, <br>
        <br>
        giacomo <br>
        <br>
      </div>
    </div>
  </body>
</html>

--------------2pT8kZ5kP4Ob0Y3A60w5rWFC--




Message sent to ludo@HIDDEN, maxim.cournoyer@HIDDEN, guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] [PATCH v2] services: restic-backup: Add more restic commands to the restic-guix package.
References: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
In-Reply-To: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
Resent-From: Giacomo Leidi <goodoldpaul@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: ludo@HIDDEN, maxim.cournoyer@HIDDEN, guix-patches@HIDDEN
Resent-Date: Sun, 20 Oct 2024 23:00:02 +0000
Resent-Message-ID: <handler.72803.B72803.17294651498879 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: 72803 <at> debbugs.gnu.org
Cc: Giacomo Leidi <goodoldpaul@HIDDEN>, Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>
X-Debbugs-Original-Xcc: Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.17294651498879
          (code B ref 72803); Sun, 20 Oct 2024 23:00:02 +0000
Received: (at 72803) by debbugs.gnu.org; 20 Oct 2024 22:59:09 +0000
Received: from localhost ([127.0.0.1]:49271 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1t2etA-0002J8-PA
	for submit <at> debbugs.gnu.org; Sun, 20 Oct 2024 18:59:09 -0400
Received: from confino.investici.org ([93.190.126.19]:61213)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <goodoldpaul@HIDDEN>) id 1t2et8-0002J0-Qh
 for 72803 <at> debbugs.gnu.org; Sun, 20 Oct 2024 18:59:07 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1729465120;
 bh=f67Gt87r8aNspn8YlYsFKNef2NKrXCJNKPq2YcLH4bQ=;
 h=From:To:Cc:Subject:Date:From;
 b=OFZN2eQpSmCfD90yIilvkxgE/PTtHyHhbZUhXZDwPHjRDjG1XP3vUsP7/PYJwYMOX
 DrV2WS3u9SlPXhrxOgfgJN95EC/Cjp0qkvs9aWYC9E6upLDnjYFq2N4CovKcVkOPDm
 FN6SjRLu65sIC+WRTnexT8qV2a4szMUlz10mok6s=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4XWv4c4CfKz10y2;
 Sun, 20 Oct 2024 22:58:40 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4XWv4b6J04z10xr; Sun, 20 Oct 2024 22:58:39 +0000 (UTC)
From: Giacomo Leidi <goodoldpaul@HIDDEN>
Date: Mon, 21 Oct 2024 00:58:31 +0200
Message-ID: <31413c193ddf6caccb7e23dd75796b6d89d5ceb7.1729465111.git.goodoldpaul@HIDDEN>
X-Mailer: git-send-email 2.46.0
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

This patch refactors the way restic commands can be added to the
restic-guix package with a more general approach.  This way new
subcommands for restic-guix can be added more easily.

* gnu/services/backup.scm (restic-backup-job-program): Generalize to
restic-action-program;
(restic-guix): allow for multiple actions.

* doc/guix.texi: Document it.

Change-Id: Ib2b5d74bebc51e35f1ae6e1aa32cedee0da59697
---
 doc/guix.texi           |  13 +++-
 gnu/services/backup.scm | 127 +++++++++++++++++++++++++++++-----------
 2 files changed, 104 insertions(+), 36 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index ac3a7adef0..f8a73abdce 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -41711,7 +41711,15 @@ Miscellaneous Services
 configuration, without waiting for the scheduled job:
 
 @example
-restic-guix backup remote-ftp
+restic-guix run remote-ftp
+@end example
+
+All arguments passed after the job name will be passed to the underlying
+@code{restic} command, together with the @code{extra-flags} field from the
+@code{restic-backup-job} record:
+
+@example
+restic-guix restore remote-ftp -t `pwd`/restored -i .config/guix/channels.scm latest
 @end example
 
 @c %start of fragment
@@ -41767,8 +41775,7 @@ Miscellaneous Services
 
 @item @code{extra-flags} (default: @code{'()}) (type: list-of-lowerables)
 A list of values that are lowered to strings.  These will be passed as
-command-line arguments to the current job @command{restic backup}
-invokation.
+command-line arguments to the current @command{restic} invokation.
 
 @end table
 
diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm
index 555e9fc959..83d388143e 100644
--- a/gnu/services/backup.scm
+++ b/gnu/services/backup.scm
@@ -46,7 +46,7 @@ (define-module (gnu services backup)
             restic-backup-configuration-fields
             restic-backup-configuration-jobs
 
-            restic-backup-job-program
+            restic-action-program
             restic-backup-job->mcron-job
             restic-guix
             restic-guix-wrapper-package
@@ -97,7 +97,7 @@ (define-configuration/no-serialization restic-backup-job
   (extra-flags
    (list-of-lowerables '())
    "A list of values that are lowered to strings.  These will be passed as
-command-line arguments to the current job @command{restic backup} invokation."))
+command-line arguments to the current @command{restic} invokation."))
 
 (define list-of-restic-backup-jobs?
   (list-of restic-backup-job?))
@@ -107,15 +107,27 @@ (define-configuration/no-serialization restic-backup-configuration
    (list-of-restic-backup-jobs '())
    "The list of backup jobs for the current system."))
 
-(define (restic-backup-job-program config)
+(define %restic-guix-supported-actions
+  '("backup" "mount" "prune" "restore" "run" "snapshots" "unlock"))
+
+(define* (restic-action-program config action)
+  (define (format name)
+    ;; Remove from NAME characters that cannot be used in the store.
+    (string-map (lambda (chr)
+                  (if (and (char-set-contains? char-set:ascii chr)
+                           (char-set-contains? char-set:graphic chr)
+                           (not (memv chr '(#\. #\/ #\space))))
+                      chr
+                      #\-))
+                name))
   (let ((restic
          (file-append (restic-backup-job-restic config) "/bin/restic"))
+        (name
+         (restic-backup-job-name config))
         (repository
          (restic-backup-job-repository config))
         (password-file
          (restic-backup-job-password-file config))
-        (files
-         (restic-backup-job-files config))
         (extra-flags
          (restic-backup-job-extra-flags config))
         (verbose
@@ -123,55 +135,104 @@ (define (restic-backup-job-program config)
              '("--verbose")
              '())))
     (program-file
-     "restic-backup-job.scm"
+     (string-append "restic-" action "-" (format name) "-program.scm")
      #~(begin
          (use-modules (ice-9 popen)
-                      (ice-9 rdelim))
+                      (ice-9 rdelim)
+                      (srfi srfi-1))
+
+         (define cli-arguments
+           (let* ((cl (command-line))
+                  (argc (length cl)))
+             (if (> argc 1)
+                 (take-right cl (- argc 1))
+                 '())))
+
          (setenv "RESTIC_PASSWORD"
                  (with-input-from-file #$password-file read-line))
 
-         (execlp #$restic #$restic #$@verbose
-                 "-r" #$repository
-                 #$@extra-flags
-                 "backup" #$@files)))))
+         (apply execlp `(#$restic #$restic #$@verbose
+                         "-r" #$repository
+                         #$@extra-flags
+                         #$action ,@cli-arguments))))))
+
+(define* (restic-guix jobs #:key (supported-actions
+                                  %restic-guix-supported-actions))
+  (define action-table
+    (map
+     (lambda (action)
+       (list action
+             (map (lambda (job)
+                    (list (restic-backup-job-name job)
+                          (restic-action-program job action)))
+                  jobs)))
+     ;; run is an alias for backup
+     (filter (lambda (a) (not (string=? a "run"))) supported-actions)))
 
-(define (restic-guix jobs)
   (program-file
    "restic-guix"
    #~(begin
        (use-modules (ice-9 match)
                     (srfi srfi-1))
 
+       (define action-table '#$action-table)
+       (define (assoc-table key table)
+         (first
+          (filter-map
+           (match-lambda
+             ((k v)
+              (and (string=? key k) v)))
+           table)))
        (define names '#$(map restic-backup-job-name jobs))
-       (define programs '#$(map restic-backup-job-program jobs))
+       (define backup-files
+         '#$(map restic-backup-job-files jobs))
+
+       (define (get-program action name)
+         (assoc-table name (assoc-table action action-table)))
 
-       (define (get-program name)
+       (define (get-backup-files name)
          (define idx
            (list-index (lambda (n) (string=? n name)) names))
-         (unless idx
-           (error (string-append "Unknown job name " name "\n\n"
-                                 "Possible job names are: "
-                                 (string-join names " "))))
-         (list-ref programs idx))
-
-       (define (backup args)
-         (define name (third args))
-         (define program (get-program name))
-         (execlp program program))
+         (list-ref backup-files idx))
 
        (define (validate-args args)
-         (when (not (>= (length args) 3))
-           (error (string-append "Usage: " (basename (car args))
-                                 " backup NAME"))))
+         (unless (>= (length args) 2)
+           (error (string-append "Usage: " (basename (first args))
+                                 " ACTION [ARGS]\n\nSupported actions are: "
+                                 #$(string-join supported-actions ", ") ".")))
+         (unless (member (second args) '#$supported-actions)
+           (error (string-append "Unknown action: " (second args) ". Supported"
+                                 "actions are: "
+                                 #$(string-join supported-actions ", ") "."))))
+
+       (define (validate-action-args action args)
+         (define argc (length args))
+         (when (not (>= argc 3))
+           (error (string-append "Usage: " (basename (first args))
+                                 " " action " JOB_NAME [ARGS]\n\nPossible job "
+                                 "names are: " (string-join names ", ") ".")))
+         (define job-name (third args))
+         (unless (member job-name names)
+           (error (string-append "Unknown job name: " job-name ". Possible job "
+                                 "names are: " (string-join names ", ") ".")))
+         (let ((program
+                (get-program
+                 ;; run is just backup called with restic-backup-job-files
+                 (if (string=? action "run") "backup" action)
+                 job-name))
+               (rest (if (> argc 3)
+                         (take-right args (- argc 3))
+                         '())))
+           (values program
+                   (if (string=? action "run")
+                       (append rest (get-backup-files job-name))
+                       rest))))
 
        (define (main args)
          (validate-args args)
          (define action (second args))
-         (match action
-           ("backup"
-            (backup args))
-           (_
-            (error (string-append "Unknown action: " action)))))
+         (define-values (program action-args) (validate-action-args action args))
+         (apply execlp (append (list program program) action-args)))
 
        (main (command-line)))))
 
@@ -183,7 +244,7 @@ (define (restic-backup-job->mcron-job config)
         (name
          (restic-backup-job-name config)))
     #~(job #$schedule
-           #$(string-append "restic-guix backup " name)
+           #$(string-append "restic-guix run " name)
            #:user #$user)))
 
 (define (restic-guix-wrapper-package jobs)

base-commit: 5ab3c4c1e43ebb637551223791db0ea3519986e1
-- 
2.46.0





Message sent to guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] Add restic commands to the restic-guix package
Resent-From: paul <goodoldpaul@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: guix-patches@HIDDEN
Resent-Date: Mon, 23 Dec 2024 11:25:02 +0000
Resent-Message-ID: <handler.72803.B72803.173495305130687 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: 72803 <at> debbugs.gnu.org
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.173495305130687
          (code B ref 72803); Mon, 23 Dec 2024 11:25:02 +0000
Received: (at 72803) by debbugs.gnu.org; 23 Dec 2024 11:24:11 +0000
Received: from localhost ([127.0.0.1]:53533 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tPgXj-0007yr-20
	for submit <at> debbugs.gnu.org; Mon, 23 Dec 2024 06:24:11 -0500
Received: from confino.investici.org ([93.190.126.19]:52283)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <goodoldpaul@HIDDEN>) id 1tPgXg-0007yi-TO
 for 72803 <at> debbugs.gnu.org; Mon, 23 Dec 2024 06:24:09 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1734953047;
 bh=UrAJCIbpoBRDZf2it0lTid5iQZw9BZdJbl566iEpp5Q=;
 h=Date:Subject:From:To:References:In-Reply-To:From;
 b=XrdvD034Kisny6aACTpUJZdO5znbDntm00b0o5oBlipExGFabNPwUAm0oKspTxq8c
 F/Z5VvfCQlIi8JQAlUgq9XS2r+2LmvQ4ts0nnKFSzhBO7TtAljTk8fTEn1N03I08wx
 T2R4zpUVIeo0kWzVhY/wFbpC+jGrSCWOnmu617CY=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4YGwdg4CGzz10wp
 for <72803 <at> debbugs.gnu.org>; Mon, 23 Dec 2024 11:24:07 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4YGwdg3jYcz10w5
 for <72803 <at> debbugs.gnu.org>; Mon, 23 Dec 2024 11:24:07 +0000 (UTC)
Message-ID: <c5977a15-dedd-4396-8327-fa9a52710f80@HIDDEN>
Date: Mon, 23 Dec 2024 12:24:07 +0100
MIME-Version: 1.0
User-Agent: Icedove Daily
From: paul <goodoldpaul@HIDDEN>
References: <dd908cb9-d4b7-4c5e-84f8-d9a7d6e625c9@HIDDEN>
Content-Language: en-US
In-Reply-To: <dd908cb9-d4b7-4c5e-84f8-d9a7d6e625c9@HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

Hi,


I'm sending a v3 based on issue#75045.


Thank you for your work,

cheers

giacomo





Message sent to ludo@HIDDEN, maxim.cournoyer@HIDDEN, guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] [PATCH v3] services: restic-backup: Add more restic commands to the restic-guix package.
References: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
In-Reply-To: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
Resent-From: Giacomo Leidi <goodoldpaul@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: ludo@HIDDEN, maxim.cournoyer@HIDDEN, guix-patches@HIDDEN
Resent-Date: Mon, 23 Dec 2024 11:25:02 +0000
Resent-Message-ID: <handler.72803.B72803.173495309230775 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: 72803 <at> debbugs.gnu.org
Cc: Giacomo Leidi <goodoldpaul@HIDDEN>, Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>
X-Debbugs-Original-Xcc: Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.173495309230775
          (code B ref 72803); Mon, 23 Dec 2024 11:25:02 +0000
Received: (at 72803) by debbugs.gnu.org; 23 Dec 2024 11:24:52 +0000
Received: from localhost ([127.0.0.1]:53540 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tPgYN-00080I-L7
	for submit <at> debbugs.gnu.org; Mon, 23 Dec 2024 06:24:52 -0500
Received: from confino.investici.org ([93.190.126.19]:42205)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <goodoldpaul@HIDDEN>) id 1tPgYL-000805-JQ
 for 72803 <at> debbugs.gnu.org; Mon, 23 Dec 2024 06:24:50 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1734953089;
 bh=r1VcuuOk4BSX38U0UpLYPs7vHmd4BVzkLlQRAUCEw7k=;
 h=From:To:Cc:Subject:Date:From;
 b=UdGR9BnvDydHqeSxtswDTYUdb9eJ0/N54EUdZAffbSgACQimll1627Y7MKjRjM9Eo
 L4bUcjFSMshLLaEP6F5lvDsrRBIUKNxUHA8LDv5ixaMVHFPY1lNHALmrQSNNiS52Nn
 GvefuYmuspbK9l/iCjkLNdCcvP3s6mhy0ATsZiBA=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4YGwfT14KCz10vx;
 Mon, 23 Dec 2024 11:24:49 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4YGwfT04sbz10vv; Mon, 23 Dec 2024 11:24:48 +0000 (UTC)
From: Giacomo Leidi <goodoldpaul@HIDDEN>
Date: Mon, 23 Dec 2024 12:24:35 +0100
Message-ID: <9e1eec4968529a6f8bdcf6b4a14c91ce1595d0ad.1734953075.git.goodoldpaul@HIDDEN>
X-Mailer: git-send-email 2.46.0
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

This patch refactors the way restic commands can be added to the
restic-guix package with a more general approach.  This way new
subcommands for restic-guix can be added more easily.

* gnu/services/backup.scm (restic-backup-job-program): Generalize to
restic-action-program;
(restic-guix): allow for multiple actions.

* doc/guix.texi: Document it.

Change-Id: Ib2b5d74bebc51e35f1ae6e1aa32cedee0da59697
---
 doc/guix.texi           |  20 ++++++-
 gnu/services/backup.scm | 125 ++++++++++++++++++++++++++++++----------
 2 files changed, 111 insertions(+), 34 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index f77b765933..aca87c7274 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -41999,6 +41999,23 @@ Miscellaneous Services
 sudo herd trigger remote-ftp-job
 @end example
 
+The @code{restic-backup-service-type} installs as well @code{restic-guix}
+to the system profile, a @code{restic} utility wrapper that allows for easier
+interaction with the Guix configured backup jobs.  For example the following
+could be used to list all the shapshots available on a given job's repository:
+
+@example
+restic-guix snapshots remote-ftp
+@end example
+
+All arguments passed after the job name will be passed to the underlying
+@code{restic} command, together with the @code{extra-flags} field from the
+@code{restic-backup-job} record:
+
+@example
+restic-guix restore remote-ftp -t `pwd`/restored -i .config/guix/channels.scm latest
+@end example
+
 @c %start of fragment
 
 @deftp {Data Type} restic-backup-configuration
@@ -42071,8 +42088,7 @@ Miscellaneous Services
 
 @item @code{extra-flags} (default: @code{'()}) (type: list-of-lowerables)
 A list of values that are lowered to strings.  These will be passed as
-command-line arguments to the current job @command{restic backup}
-invokation.
+command-line arguments to the current @command{restic} invokation.
 
 @end table
 
diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm
index fc8934873b..8d1959f9bf 100644
--- a/gnu/services/backup.scm
+++ b/gnu/services/backup.scm
@@ -52,7 +52,7 @@ (define-module (gnu services backup)
             restic-backup-configuration-fields
             restic-backup-configuration-jobs
 
-            restic-backup-job-program
+            restic-action-program
             restic-backup-job->mcron-job
             restic-guix
             restic-guix-wrapper-package
@@ -128,7 +128,7 @@ (define-configuration/no-serialization restic-backup-job
   (extra-flags
    (list-of-lowerables '())
    "A list of values that are lowered to strings.  These will be passed as
-command-line arguments to the current job @command{restic backup} invokation."))
+command-line arguments to the current @command{restic} invokation."))
 
 (define list-of-restic-backup-jobs?
   (list-of restic-backup-job?))
@@ -138,15 +138,27 @@ (define-configuration/no-serialization restic-backup-configuration
    (list-of-restic-backup-jobs '())
    "The list of backup jobs for the current system."))
 
-(define (restic-backup-job-program config)
+(define %restic-guix-supported-actions
+  '("backup" "mount" "prune" "restore" "run" "snapshots" "unlock"))
+
+(define* (restic-action-program config action)
+  (define (format name)
+    ;; Remove from NAME characters that cannot be used in the store.
+    (string-map (lambda (chr)
+                  (if (and (char-set-contains? char-set:ascii chr)
+                           (char-set-contains? char-set:graphic chr)
+                           (not (memv chr '(#\. #\/ #\space))))
+                      chr
+                      #\-))
+                name))
   (let ((restic
          (file-append (restic-backup-job-restic config) "/bin/restic"))
+        (name
+         (restic-backup-job-name config))
         (repository
          (restic-backup-job-repository config))
         (password-file
          (restic-backup-job-password-file config))
-        (files
-         (restic-backup-job-files config))
         (extra-flags
          (restic-backup-job-extra-flags config))
         (verbose
@@ -154,55 +166,104 @@ (define (restic-backup-job-program config)
              '("--verbose")
              '())))
     (program-file
-     "restic-backup-job.scm"
+     (string-append "restic-" action "-" (format name) "-program.scm")
      #~(begin
          (use-modules (ice-9 popen)
-                      (ice-9 rdelim))
+                      (ice-9 rdelim)
+                      (srfi srfi-1))
+
+         (define cli-arguments
+           (let* ((cl (command-line))
+                  (argc (length cl)))
+             (if (> argc 1)
+                 (take-right cl (- argc 1))
+                 '())))
+
          (setenv "RESTIC_PASSWORD"
                  (with-input-from-file #$password-file read-line))
 
-         (execlp #$restic #$restic #$@verbose
-                 "-r" #$repository
-                 #$@extra-flags
-                 "backup" #$@files)))))
+         (apply execlp `(#$restic #$restic #$@verbose
+                         "-r" #$repository
+                         #$@extra-flags
+                         #$action ,@cli-arguments))))))
+
+(define* (restic-guix jobs #:key (supported-actions
+                                  %restic-guix-supported-actions))
+  (define action-table
+    (map
+     (lambda (action)
+       (list action
+             (map (lambda (job)
+                    (list (restic-backup-job-name job)
+                          (restic-action-program job action)))
+                  jobs)))
+     ;; run is an alias for backup
+     (filter (lambda (a) (not (string=? a "run"))) supported-actions)))
 
-(define (restic-guix jobs)
   (program-file
    "restic-guix"
    #~(begin
        (use-modules (ice-9 match)
                     (srfi srfi-1))
 
+       (define action-table '#$action-table)
+       (define (assoc-table key table)
+         (first
+          (filter-map
+           (match-lambda
+             ((k v)
+              (and (string=? key k) v)))
+           table)))
        (define names '#$(map restic-backup-job-name jobs))
-       (define programs '#$(map restic-backup-job-program jobs))
+       (define backup-files
+         '#$(map restic-backup-job-files jobs))
 
-       (define (get-program name)
+       (define (get-program action name)
+         (assoc-table name (assoc-table action action-table)))
+
+       (define (get-backup-files name)
          (define idx
            (list-index (lambda (n) (string=? n name)) names))
-         (unless idx
-           (error (string-append "Unknown job name " name "\n\n"
-                                 "Possible job names are: "
-                                 (string-join names " "))))
-         (list-ref programs idx))
-
-       (define (backup args)
-         (define name (third args))
-         (define program (get-program name))
-         (execlp program program))
+         (list-ref backup-files idx))
 
        (define (validate-args args)
-         (when (not (>= (length args) 3))
-           (error (string-append "Usage: " (basename (car args))
-                                 " backup NAME"))))
+         (unless (>= (length args) 2)
+           (error (string-append "Usage: " (basename (first args))
+                                 " ACTION [ARGS]\n\nSupported actions are: "
+                                 #$(string-join supported-actions ", ") ".")))
+         (unless (member (second args) '#$supported-actions)
+           (error (string-append "Unknown action: " (second args) ". Supported"
+                                 "actions are: "
+                                 #$(string-join supported-actions ", ") "."))))
+
+       (define (validate-action-args action args)
+         (define argc (length args))
+         (when (not (>= argc 3))
+           (error (string-append "Usage: " (basename (first args))
+                                 " " action " JOB_NAME [ARGS]\n\nPossible job "
+                                 "names are: " (string-join names ", ") ".")))
+         (define job-name (third args))
+         (unless (member job-name names)
+           (error (string-append "Unknown job name: " job-name ". Possible job "
+                                 "names are: " (string-join names ", ") ".")))
+         (let ((program
+                (get-program
+                 ;; run is just backup called with restic-backup-job-files
+                 (if (string=? action "run") "backup" action)
+                 job-name))
+               (rest (if (> argc 3)
+                         (take-right args (- argc 3))
+                         '())))
+           (values program
+                   (if (string=? action "run")
+                       (append rest (get-backup-files job-name))
+                       rest))))
 
        (define (main args)
          (validate-args args)
          (define action (second args))
-         (match action
-           ("backup"
-            (backup args))
-           (_
-            (error (string-append "Unknown action: " action)))))
+         (define-values (program action-args) (validate-action-args action args))
+         (apply execlp (append (list program program) action-args)))
 
        (main (command-line)))))
 

base-commit: f52cde358b609d18f43bf62f1dfe63835c1a57b9
-- 
2.46.0





Message received at control <at> debbugs.gnu.org:


Received: (at control) by debbugs.gnu.org; 23 Dec 2024 11:26:30 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Dec 23 06:26:30 2024
Received: from localhost ([127.0.0.1]:53550 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tPgZy-00089J-HE
	for submit <at> debbugs.gnu.org; Mon, 23 Dec 2024 06:26:30 -0500
Received: from confino.investici.org ([93.190.126.19]:27483)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <goodoldpaul@HIDDEN>) id 1tPgZx-00089C-8M
 for control <at> debbugs.gnu.org; Mon, 23 Dec 2024 06:26:29 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1734953188;
 bh=kcYPzq10ZS7hPgfmaCaLRTsSuizGr65MwpArJHalXrw=;
 h=Date:To:From:Subject:From;
 b=C/uIGDgTg+I6qtanXBhRXrvSXXSFNXYpKNvCNSPjrEql55elogWd/Id5Mcn76xsZW
 VSL2ygaOFYG9yukpniDHWfAapvh80GVp9EsDDxtJTDsqGwAbRI2R/vYHyjJ3kzqwO5
 byYjjEyjATaTnIL4F7n6PCkG9qV39xG+FgWQdkgo=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4YGwhN5k4Rz10w5
 for <control <at> debbugs.gnu.org>; Mon, 23 Dec 2024 11:26:28 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4YGwhN5Czbz10vx
 for <control <at> debbugs.gnu.org>; Mon, 23 Dec 2024 11:26:28 +0000 (UTC)
Message-ID: <581fb166-b3b6-4eab-a349-ff7a75798873@HIDDEN>
Date: Mon, 23 Dec 2024 12:26:28 +0100
MIME-Version: 1.0
User-Agent: Icedove Daily
Content-Language: en-US
To: control <at> debbugs.gnu.org
From: paul <goodoldpaul@HIDDEN>
Subject: block 72803 by 75045
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: control
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

block 72803 by 75045





Message sent to guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] Add restic commands to the restic-guix package
Resent-From: paul <goodoldpaul@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: guix-patches@HIDDEN
Resent-Date: Mon, 23 Dec 2024 11:33:02 +0000
Resent-Message-ID: <handler.72803.B72803.173495357032529 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: 72803 <at> debbugs.gnu.org
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.173495357032529
          (code B ref 72803); Mon, 23 Dec 2024 11:33:02 +0000
Received: (at 72803) by debbugs.gnu.org; 23 Dec 2024 11:32:50 +0000
Received: from localhost ([127.0.0.1]:53569 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tPgg2-0008SY-EM
	for submit <at> debbugs.gnu.org; Mon, 23 Dec 2024 06:32:50 -0500
Received: from confino.investici.org ([93.190.126.19]:31521)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <goodoldpaul@HIDDEN>) id 1tPgg0-0008SP-4E
 for 72803 <at> debbugs.gnu.org; Mon, 23 Dec 2024 06:32:44 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1734953563;
 bh=n0ETKCzKhbZqkwo3HnRizwofUI+AHdKe8NhVn7ujIRU=;
 h=Date:Subject:From:To:References:In-Reply-To:From;
 b=S8tyKDG2xigGfVhpUgZExKmJpBJFHSpKrubTqhwyZBhyQvFsnzwZU3ClGiNyINc0o
 sb0eD9uMALcyJ9viOe5+W18C6PR9htH8C6LI7k/bdIE71WjJHSYhQjVBXi1LVNsdnz
 wBfefq6EVMNSIrqk6qU99x37VFGMxJtX/jFvi/2s=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4YGwqb43qVz10wH
 for <72803 <at> debbugs.gnu.org>; Mon, 23 Dec 2024 11:32:43 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4YGwqb3YsKz10wG
 for <72803 <at> debbugs.gnu.org>; Mon, 23 Dec 2024 11:32:43 +0000 (UTC)
Message-ID: <08b873f4-26da-478a-bd61-91a03da51fb5@HIDDEN>
Date: Mon, 23 Dec 2024 12:32:43 +0100
MIME-Version: 1.0
User-Agent: Icedove Daily
From: paul <goodoldpaul@HIDDEN>
References: <dd908cb9-d4b7-4c5e-84f8-d9a7d6e625c9@HIDDEN>
 <c5977a15-dedd-4396-8327-fa9a52710f80@HIDDEN>
Content-Language: en-US
In-Reply-To: <c5977a15-dedd-4396-8327-fa9a52710f80@HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

Actually I'm sending a v4 dropping the "run" subcommand from 
restic-guix, since now we can use


sudo herd trigger job-name


Apologies for the noise,

giacomo





Message sent to ludo@HIDDEN, maxim.cournoyer@HIDDEN, guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] [PATCH v4] services: restic-backup: Add more restic commands to the restic-guix package.
References: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
In-Reply-To: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
Resent-From: Giacomo Leidi <goodoldpaul@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: ludo@HIDDEN, maxim.cournoyer@HIDDEN, guix-patches@HIDDEN
Resent-Date: Mon, 23 Dec 2024 14:18:01 +0000
Resent-Message-ID: <handler.72803.B72803.173496346029637 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: 72803 <at> debbugs.gnu.org
Cc: Giacomo Leidi <goodoldpaul@HIDDEN>, Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>
X-Debbugs-Original-Xcc: Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.173496346029637
          (code B ref 72803); Mon, 23 Dec 2024 14:18:01 +0000
Received: (at 72803) by debbugs.gnu.org; 23 Dec 2024 14:17:40 +0000
Received: from localhost ([127.0.0.1]:53808 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tPjFb-0007hw-MQ
	for submit <at> debbugs.gnu.org; Mon, 23 Dec 2024 09:17:40 -0500
Received: from confino.investici.org ([93.190.126.19]:20769)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <goodoldpaul@HIDDEN>) id 1tPjFY-0007hi-Nl
 for 72803 <at> debbugs.gnu.org; Mon, 23 Dec 2024 09:17:38 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1734963446;
 bh=34HVHqduCm+/2K5JxrJLwyP9CveFW3NN119T1uXcqLQ=;
 h=From:To:Cc:Subject:Date:From;
 b=XUNG0jtbQZr2i7tA+J14slY3QpDCG7h37VXgnJoDXgLUCvKb07w9cbcBYMkizblon
 5d0fY0TIl2xbkua8jgavEzWo+0rV4N1bezSDMaTiSqCvDXZE3aPZYwepB8gAHDC0ax
 AJKMknTK848L3G99QbeqpIsumCtcsbrehFm9xfqk=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4YH0Tf5rYfz10xL;
 Mon, 23 Dec 2024 14:17:26 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4YH0Tf4TQxz10wM; Mon, 23 Dec 2024 14:17:26 +0000 (UTC)
From: Giacomo Leidi <goodoldpaul@HIDDEN>
Date: Mon, 23 Dec 2024 15:17:18 +0100
Message-ID: <e78157d5ce65108ac29f44f612ca68664b0eab6d.1734963438.git.goodoldpaul@HIDDEN>
X-Mailer: git-send-email 2.46.0
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

This patch refactors the way restic commands can be added to the
restic-guix package with a more general approach.  This way new
subcommands for restic-guix can be added more easily.

* gnu/services/backup.scm (restic-backup-job-program): Generalize to
restic-action-program;
(restic-guix): allow for multiple actions.

* doc/guix.texi: Document it.

Change-Id: Ib2b5d74bebc51e35f1ae6e1aa32cedee0da59697
---
 doc/guix.texi           |  20 ++++++-
 gnu/services/backup.scm | 129 ++++++++++++++++++++++++++++------------
 2 files changed, 109 insertions(+), 40 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index f77b765933..aca87c7274 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -41999,6 +41999,23 @@ Miscellaneous Services
 sudo herd trigger remote-ftp-job
 @end example
 
+The @code{restic-backup-service-type} installs as well @code{restic-guix}
+to the system profile, a @code{restic} utility wrapper that allows for easier
+interaction with the Guix configured backup jobs.  For example the following
+could be used to list all the shapshots available on a given job's repository:
+
+@example
+restic-guix snapshots remote-ftp
+@end example
+
+All arguments passed after the job name will be passed to the underlying
+@code{restic} command, together with the @code{extra-flags} field from the
+@code{restic-backup-job} record:
+
+@example
+restic-guix restore remote-ftp -t `pwd`/restored -i .config/guix/channels.scm latest
+@end example
+
 @c %start of fragment
 
 @deftp {Data Type} restic-backup-configuration
@@ -42071,8 +42088,7 @@ Miscellaneous Services
 
 @item @code{extra-flags} (default: @code{'()}) (type: list-of-lowerables)
 A list of values that are lowered to strings.  These will be passed as
-command-line arguments to the current job @command{restic backup}
-invokation.
+command-line arguments to the current @command{restic} invokation.
 
 @end table
 
diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm
index fc8934873b..5c693660e3 100644
--- a/gnu/services/backup.scm
+++ b/gnu/services/backup.scm
@@ -52,11 +52,12 @@ (define-module (gnu services backup)
             restic-backup-configuration-fields
             restic-backup-configuration-jobs
 
-            restic-backup-job-program
-            restic-backup-job->mcron-job
+            restic-action-program
+            restic-backup-job->shepherd-service
             restic-guix
             restic-guix-wrapper-package
             restic-backup-service-profile
+            restic-backup-service-activation
             restic-backup-service-type))
 
 (define (gexp-or-string? value)
@@ -128,7 +129,7 @@ (define-configuration/no-serialization restic-backup-job
   (extra-flags
    (list-of-lowerables '())
    "A list of values that are lowered to strings.  These will be passed as
-command-line arguments to the current job @command{restic backup} invokation."))
+command-line arguments to the current @command{restic} invokation."))
 
 (define list-of-restic-backup-jobs?
   (list-of restic-backup-job?))
@@ -138,15 +139,27 @@ (define-configuration/no-serialization restic-backup-configuration
    (list-of-restic-backup-jobs '())
    "The list of backup jobs for the current system."))
 
-(define (restic-backup-job-program config)
+(define %restic-guix-supported-actions
+  '("backup" "mount" "prune" "restore" "snapshots" "unlock"))
+
+(define* (restic-action-program config action)
+  (define (format name)
+    ;; Remove from NAME characters that cannot be used in the store.
+    (string-map (lambda (chr)
+                  (if (and (char-set-contains? char-set:ascii chr)
+                           (char-set-contains? char-set:graphic chr)
+                           (not (memv chr '(#\. #\/ #\space))))
+                      chr
+                      #\-))
+                name))
   (let ((restic
          (file-append (restic-backup-job-restic config) "/bin/restic"))
+        (name
+         (restic-backup-job-name config))
         (repository
          (restic-backup-job-repository config))
         (password-file
          (restic-backup-job-password-file config))
-        (files
-         (restic-backup-job-files config))
         (extra-flags
          (restic-backup-job-extra-flags config))
         (verbose
@@ -154,55 +167,90 @@ (define (restic-backup-job-program config)
              '("--verbose")
              '())))
     (program-file
-     "restic-backup-job.scm"
+     (string-append "restic-" action "-" (format name) "-program.scm")
      #~(begin
          (use-modules (ice-9 popen)
-                      (ice-9 rdelim))
+                      (ice-9 rdelim)
+                      (srfi srfi-1))
+
+         (define cli-arguments
+           (let* ((cl (command-line))
+                  (argc (length cl)))
+             (if (> argc 1)
+                 (take-right cl (- argc 1))
+                 '())))
+
          (setenv "RESTIC_PASSWORD"
                  (with-input-from-file #$password-file read-line))
 
-         (execlp #$restic #$restic #$@verbose
-                 "-r" #$repository
-                 #$@extra-flags
-                 "backup" #$@files)))))
+         (apply execlp `(#$restic #$restic #$@verbose
+                         "-r" #$repository
+                         #$@extra-flags
+                         #$action ,@cli-arguments))))))
+
+(define* (restic-guix jobs #:key (supported-actions
+                                  %restic-guix-supported-actions))
+  (define action-table
+    (map
+     (lambda (action)
+       (list action
+             (map (lambda (job)
+                    (list (restic-backup-job-name job)
+                          (restic-action-program job action)))
+                  jobs)))
+     supported-actions))
 
-(define (restic-guix jobs)
   (program-file
    "restic-guix"
    #~(begin
        (use-modules (ice-9 match)
                     (srfi srfi-1))
 
+       (define action-table '#$action-table)
+       (define (assoc-table key table)
+         (first
+          (filter-map
+           (match-lambda
+             ((k v)
+              (and (string=? key k) v)))
+           table)))
        (define names '#$(map restic-backup-job-name jobs))
-       (define programs '#$(map restic-backup-job-program jobs))
 
-       (define (get-program name)
-         (define idx
-           (list-index (lambda (n) (string=? n name)) names))
-         (unless idx
-           (error (string-append "Unknown job name " name "\n\n"
-                                 "Possible job names are: "
-                                 (string-join names " "))))
-         (list-ref programs idx))
-
-       (define (backup args)
-         (define name (third args))
-         (define program (get-program name))
-         (execlp program program))
+       (define (get-program action name)
+         (assoc-table name (assoc-table action action-table)))
 
        (define (validate-args args)
-         (when (not (>= (length args) 3))
-           (error (string-append "Usage: " (basename (car args))
-                                 " backup NAME"))))
+         (unless (>= (length args) 2)
+           (error (string-append "Usage: " (basename (first args))
+                                 " ACTION [ARGS]\n\nSupported actions are: "
+                                 #$(string-join supported-actions ", ") ".")))
+         (unless (member (second args) '#$supported-actions)
+           (error (string-append "Unknown action: " (second args) ". Supported"
+                                 "actions are: "
+                                 #$(string-join supported-actions ", ") "."))))
+
+       (define (validate-action-args action args)
+         (define argc (length args))
+         (when (not (>= argc 3))
+           (error (string-append "Usage: " (basename (first args))
+                                 " " action " JOB_NAME [ARGS]\n\nPossible job "
+                                 "names are: " (string-join names ", ") ".")))
+         (define job-name (third args))
+         (unless (member job-name names)
+           (error (string-append "Unknown job name: " job-name ". Possible job "
+                                 "names are: " (string-join names ", ") ".")))
+         (let ((program
+                (get-program action job-name))
+               (rest (if (> argc 3)
+                         (take-right args (- argc 3))
+                         '())))
+           (values program rest)))
 
        (define (main args)
          (validate-args args)
          (define action (second args))
-         (match action
-           ("backup"
-            (backup args))
-           (_
-            (error (string-append "Unknown action: " action)))))
+         (define-values (program action-args) (validate-action-args action args))
+         (apply execlp (append (list program program) action-args)))
 
        (main (command-line)))))
 
@@ -216,6 +264,10 @@ (define (restic-job-log-file job)
 (define (restic-backup-job->shepherd-service config)
   (let ((schedule (restic-backup-job-schedule config))
         (name (restic-backup-job-name config))
+        (files (string-join
+                (map (lambda (f) (string-append "'" f "'"))
+                     (restic-backup-job-files config))
+                " "))
         (user (restic-backup-job-user config))
         (group (restic-backup-job-group config))
         (max-duration (restic-backup-job-max-duration config))
@@ -238,7 +290,8 @@ (define (restic-backup-job->shepherd-service config)
                            (list
                             (string-append #+bash-minimal "/bin/bash")
                             "-l" "-c"
-                            (string-append "restic-guix backup " #$name))
+                            (string-append
+                             "restic-guix backup " #$name " " #$files))
                            #:user #$user
                            #:group #$group
                            #:environment-variables
@@ -283,7 +336,7 @@ (define restic-backup-service-profile
          (restic-guix-wrapper-package jobs))
         '())))
 
-(define (restic-backup-activation config)
+(define (restic-backup-service-activation config)
   #~(for-each
      (lambda (log-file)
        (mkdir-p (dirname log-file)))
@@ -295,7 +348,7 @@ (define restic-backup-service-type
                 (extensions
                  (list
                   (service-extension activation-service-type
-                                     restic-backup-activation)
+                                     restic-backup-service-activation)
                   (service-extension profile-service-type
                                      restic-backup-service-profile)
                   (service-extension shepherd-root-service-type

base-commit: f52cde358b609d18f43bf62f1dfe63835c1a57b9
-- 
2.46.0





Message sent to guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] Add restic commands to the restic-guix package
Resent-From: paul <goodoldpaul@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: guix-patches@HIDDEN
Resent-Date: Fri, 24 Jan 2025 23:48:01 +0000
Resent-Message-ID: <handler.72803.B72803.173776245710900 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: 72803 <at> debbugs.gnu.org
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.173776245710900
          (code B ref 72803); Fri, 24 Jan 2025 23:48:01 +0000
Received: (at 72803) by debbugs.gnu.org; 24 Jan 2025 23:47:37 +0000
Received: from localhost ([127.0.0.1]:47652 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tbTOj-0002pj-2M
	for submit <at> debbugs.gnu.org; Fri, 24 Jan 2025 18:47:37 -0500
Received: from confino.investici.org ([93.190.126.19]:53587)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>)
 id 1tbTOg-0002pY-JP
 for 72803 <at> debbugs.gnu.org; Fri, 24 Jan 2025 18:47:35 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1737762452;
 bh=WJ7KblwsFOpZrAtNm9mMEZ+rCEmXhC1XE5jRQDUprBw=;
 h=Date:Subject:From:To:References:In-Reply-To:From;
 b=mxFAJdx88ZWvd/LysQuFCvkNy9XW3KUnzT1/8iMhVsASSIO+jRSfq5JVjC6pGrEXS
 Um1Fj1lxsHyYCNLFUNh4TINq4avgYm4oTKotsDY65xrVtltrVee15ZQsD5e6lOAQnv
 bphBD41SYMg+LBSv76GE0HVwRNpu2I2Y9HL9uohA=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4Yfvch5rSpz11LD
 for <72803 <at> debbugs.gnu.org>; Fri, 24 Jan 2025 23:47:32 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4Yfvch57t4z11JZ
 for <72803 <at> debbugs.gnu.org>; Fri, 24 Jan 2025 23:47:32 +0000 (UTC)
Message-ID: <b6841b0b-2715-48e2-8928-837764e5df96@HIDDEN>
Date: Sat, 25 Jan 2025 00:47:30 +0100
MIME-Version: 1.0
User-Agent: Icedove Daily
From: paul <goodoldpaul@HIDDEN>
References: <dd908cb9-d4b7-4c5e-84f8-d9a7d6e625c9@HIDDEN>
 <c5977a15-dedd-4396-8327-fa9a52710f80@HIDDEN>
 <08b873f4-26da-478a-bd61-91a03da51fb5@HIDDEN>
Content-Language: en-US
In-Reply-To: <08b873f4-26da-478a-bd61-91a03da51fb5@HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

Hi Guix, I'm sending a v5 rebased on current master, thank you for your 
time!




Message sent to ludo@HIDDEN, maxim.cournoyer@HIDDEN, guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] [PATCH v5] services: restic-backup: Add more restic commands to the restic-guix package.
References: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
In-Reply-To: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
Resent-From: Giacomo Leidi <goodoldpaul@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: ludo@HIDDEN, maxim.cournoyer@HIDDEN, guix-patches@HIDDEN
Resent-Date: Fri, 24 Jan 2025 23:49:02 +0000
Resent-Message-ID: <handler.72803.B72803.173776250611023 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: 72803 <at> debbugs.gnu.org
Cc: Giacomo Leidi <goodoldpaul@HIDDEN>, Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>
X-Debbugs-Original-Xcc: Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.173776250611023
          (code B ref 72803); Fri, 24 Jan 2025 23:49:02 +0000
Received: (at 72803) by debbugs.gnu.org; 24 Jan 2025 23:48:26 +0000
Received: from localhost ([127.0.0.1]:47656 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tbTPV-0002ri-Hb
	for submit <at> debbugs.gnu.org; Fri, 24 Jan 2025 18:48:26 -0500
Received: from confino.investici.org ([93.190.126.19]:23803)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>)
 id 1tbTPS-0002rU-Cr
 for 72803 <at> debbugs.gnu.org; Fri, 24 Jan 2025 18:48:23 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1737762501;
 bh=IIHJ3kZNhXTNhnyagkg1KFUD7TdeqqV/BOYtO6/rMzw=;
 h=From:To:Cc:Subject:Date:From;
 b=gnKyl3yUX10xtt2feUB4lTHMZZycisvtDHqVnBne8DptpMe6oKP3WrEvi1QCDTqzP
 VTgAzphpV2okGpByvuM9VXyLx71FJxo/hDpTvOljwt6QK8si1XOV80Tio7do4MOEKu
 jQfEGtVt4hmgiXYWmfWy5W6qT9d2yFYum8b92fH4=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4Yfvdd3SZSz11Qc;
 Fri, 24 Jan 2025 23:48:21 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4Yfvdd2571z11LD; Fri, 24 Jan 2025 23:48:21 +0000 (UTC)
From: Giacomo Leidi <goodoldpaul@HIDDEN>
Date: Sat, 25 Jan 2025 00:47:54 +0100
Message-ID: <757f3b471a0b994c34fd6c8371aa19072ed04431.1737762473.git.goodoldpaul@HIDDEN>
X-Mailer: git-send-email 2.47.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

This patch refactors the way restic commands can be added to the
restic-guix package with a more general approach.  This way new
subcommands for restic-guix can be added more easily.

* gnu/services/backup.scm (restic-backup-job-program): Generalize to
restic-action-program;
(restic-guix): allow for multiple actions.

* doc/guix.texi: Document it.

Change-Id: Ib2b5d74bebc51e35f1ae6e1aa32cedee0da59697
---
 doc/guix.texi           |  20 ++++++-
 gnu/services/backup.scm | 129 ++++++++++++++++++++++++++++------------
 2 files changed, 109 insertions(+), 40 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 9a53bdcd374..716dd312cd2 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -42722,6 +42722,23 @@ Miscellaneous Services
 sudo herd trigger remote-ftp
 @end example
 
+The @code{restic-backup-service-type} installs as well @code{restic-guix}
+to the system profile, a @code{restic} utility wrapper that allows for easier
+interaction with the Guix configured backup jobs.  For example the following
+could be used to list all the shapshots available on a given job's repository:
+
+@example
+restic-guix snapshots remote-ftp
+@end example
+
+All arguments passed after the job name will be passed to the underlying
+@code{restic} command, together with the @code{extra-flags} field from the
+@code{restic-backup-job} record:
+
+@example
+restic-guix restore remote-ftp -t `pwd`/restored -i .config/guix/channels.scm latest
+@end example
+
 @c %start of fragment
 
 @deftp {Data Type} restic-backup-configuration
@@ -42795,8 +42812,7 @@ Miscellaneous Services
 
 @item @code{extra-flags} (default: @code{'()}) (type: list-of-lowerables)
 A list of values that are lowered to strings.  These will be passed as
-command-line arguments to the current job @command{restic backup}
-invokation.
+command-line arguments to the current @command{restic} invokation.
 
 @end table
 
diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm
index 99a79ff5fbe..49655d1d930 100644
--- a/gnu/services/backup.scm
+++ b/gnu/services/backup.scm
@@ -52,11 +52,12 @@ (define-module (gnu services backup)
             restic-backup-configuration-fields
             restic-backup-configuration-jobs
 
-            restic-backup-job-program
-            restic-backup-job->mcron-job
+            restic-action-program
+            restic-backup-job->shepherd-service
             restic-guix
             restic-guix-wrapper-package
             restic-backup-service-profile
+            restic-backup-service-activation
             restic-backup-service-type))
 
 (define (gexp-or-string? value)
@@ -129,7 +130,7 @@ (define-configuration/no-serialization restic-backup-job
   (extra-flags
    (list-of-lowerables '())
    "A list of values that are lowered to strings.  These will be passed as
-command-line arguments to the current job @command{restic backup} invokation."))
+command-line arguments to the current @command{restic} invokation."))
 
 (define list-of-restic-backup-jobs?
   (list-of restic-backup-job?))
@@ -139,15 +140,27 @@ (define-configuration/no-serialization restic-backup-configuration
    (list-of-restic-backup-jobs '())
    "The list of backup jobs for the current system."))
 
-(define (restic-backup-job-program config)
+(define %restic-guix-supported-actions
+  '("backup" "mount" "prune" "restore" "snapshots" "unlock"))
+
+(define* (restic-action-program config action)
+  (define (format name)
+    ;; Remove from NAME characters that cannot be used in the store.
+    (string-map (lambda (chr)
+                  (if (and (char-set-contains? char-set:ascii chr)
+                           (char-set-contains? char-set:graphic chr)
+                           (not (memv chr '(#\. #\/ #\space))))
+                      chr
+                      #\-))
+                name))
   (let ((restic
          (file-append (restic-backup-job-restic config) "/bin/restic"))
+        (name
+         (restic-backup-job-name config))
         (repository
          (restic-backup-job-repository config))
         (password-file
          (restic-backup-job-password-file config))
-        (files
-         (restic-backup-job-files config))
         (extra-flags
          (restic-backup-job-extra-flags config))
         (verbose
@@ -155,55 +168,90 @@ (define (restic-backup-job-program config)
              '("--verbose")
              '())))
     (program-file
-     "restic-backup-job.scm"
+     (string-append "restic-" action "-" (format name) "-program.scm")
      #~(begin
          (use-modules (ice-9 popen)
-                      (ice-9 rdelim))
+                      (ice-9 rdelim)
+                      (srfi srfi-1))
+
+         (define cli-arguments
+           (let* ((cl (command-line))
+                  (argc (length cl)))
+             (if (> argc 1)
+                 (take-right cl (- argc 1))
+                 '())))
+
          (setenv "RESTIC_PASSWORD"
                  (with-input-from-file #$password-file read-line))
 
-         (execlp #$restic #$restic #$@verbose
-                 "-r" #$repository
-                 #$@extra-flags
-                 "backup" #$@files)))))
+         (apply execlp `(#$restic #$restic #$@verbose
+                         "-r" #$repository
+                         #$@extra-flags
+                         #$action ,@cli-arguments))))))
+
+(define* (restic-guix jobs #:key (supported-actions
+                                  %restic-guix-supported-actions))
+  (define action-table
+    (map
+     (lambda (action)
+       (list action
+             (map (lambda (job)
+                    (list (restic-backup-job-name job)
+                          (restic-action-program job action)))
+                  jobs)))
+     supported-actions))
 
-(define (restic-guix jobs)
   (program-file
    "restic-guix"
    #~(begin
        (use-modules (ice-9 match)
                     (srfi srfi-1))
 
+       (define action-table '#$action-table)
+       (define (assoc-table key table)
+         (first
+          (filter-map
+           (match-lambda
+             ((k v)
+              (and (string=? key k) v)))
+           table)))
        (define names '#$(map restic-backup-job-name jobs))
-       (define programs '#$(map restic-backup-job-program jobs))
 
-       (define (get-program name)
-         (define idx
-           (list-index (lambda (n) (string=? n name)) names))
-         (unless idx
-           (error (string-append "Unknown job name " name "\n\n"
-                                 "Possible job names are: "
-                                 (string-join names " "))))
-         (list-ref programs idx))
-
-       (define (backup args)
-         (define name (third args))
-         (define program (get-program name))
-         (execlp program program))
+       (define (get-program action name)
+         (assoc-table name (assoc-table action action-table)))
 
        (define (validate-args args)
-         (when (not (>= (length args) 3))
-           (error (string-append "Usage: " (basename (car args))
-                                 " backup NAME"))))
+         (unless (>= (length args) 2)
+           (error (string-append "Usage: " (basename (first args))
+                                 " ACTION [ARGS]\n\nSupported actions are: "
+                                 #$(string-join supported-actions ", ") ".")))
+         (unless (member (second args) '#$supported-actions)
+           (error (string-append "Unknown action: " (second args) ". Supported"
+                                 "actions are: "
+                                 #$(string-join supported-actions ", ") "."))))
+
+       (define (validate-action-args action args)
+         (define argc (length args))
+         (when (not (>= argc 3))
+           (error (string-append "Usage: " (basename (first args))
+                                 " " action " JOB_NAME [ARGS]\n\nPossible job "
+                                 "names are: " (string-join names ", ") ".")))
+         (define job-name (third args))
+         (unless (member job-name names)
+           (error (string-append "Unknown job name: " job-name ". Possible job "
+                                 "names are: " (string-join names ", ") ".")))
+         (let ((program
+                (get-program action job-name))
+               (rest (if (> argc 3)
+                         (take-right args (- argc 3))
+                         '())))
+           (values program rest)))
 
        (define (main args)
          (validate-args args)
          (define action (second args))
-         (match action
-           ("backup"
-            (backup args))
-           (_
-            (error (string-append "Unknown action: " action)))))
+         (define-values (program action-args) (validate-action-args action args))
+         (apply execlp (append (list program program) action-args)))
 
        (main (command-line)))))
 
@@ -217,6 +265,10 @@ (define (restic-job-log-file job)
 (define (restic-backup-job->shepherd-service config)
   (let ((schedule (restic-backup-job-schedule config))
         (name (restic-backup-job-name config))
+        (files (string-join
+                (map (lambda (f) (string-append "'" f "'"))
+                     (restic-backup-job-files config))
+                " "))
         (user (restic-backup-job-user config))
         (group (restic-backup-job-group config))
         (max-duration (restic-backup-job-max-duration config))
@@ -242,7 +294,8 @@ (define (restic-backup-job->shepherd-service config)
                             ;; backends require, such as rclone.
                             (string-append #+bash-minimal "/bin/bash")
                             "-l" "-c"
-                            (string-append "restic-guix backup " #$name))
+                            (string-append
+                             "restic-guix backup " #$name " " #$files))
                            #:user #$user
                            #:group #$group
                            #:environment-variables
@@ -287,7 +340,7 @@ (define restic-backup-service-profile
          (restic-guix-wrapper-package jobs))
         '())))
 
-(define (restic-backup-activation config)
+(define (restic-backup-service-activation config)
   #~(for-each
      (lambda (log-file)
        (mkdir-p (dirname log-file)))
@@ -299,7 +352,7 @@ (define restic-backup-service-type
                 (extensions
                  (list
                   (service-extension activation-service-type
-                                     restic-backup-activation)
+                                     restic-backup-service-activation)
                   (service-extension profile-service-type
                                      restic-backup-service-profile)
                   (service-extension shepherd-root-service-type

base-commit: 646202bf73f90de4f9b7cc66248b8f8e6e381014
-- 
2.47.1





Message sent to guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] Add restic commands to the restic-guix package
Resent-From: paul <goodoldpaul@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: guix-patches@HIDDEN
Resent-Date: Sun, 09 Feb 2025 23:01:01 +0000
Resent-Message-ID: <handler.72803.B72803.173914204919877 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: 72803 <at> debbugs.gnu.org
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.173914204919877
          (code B ref 72803); Sun, 09 Feb 2025 23:01:01 +0000
Received: (at 72803) by debbugs.gnu.org; 9 Feb 2025 23:00:49 +0000
Received: from localhost ([127.0.0.1]:46820 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1thGID-0005AX-20
	for submit <at> debbugs.gnu.org; Sun, 09 Feb 2025 18:00:49 -0500
Received: from confino.investici.org ([2a11:7980:1::2:0]:33677)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>)
 id 1thGIA-0005AL-0x
 for 72803 <at> debbugs.gnu.org; Sun, 09 Feb 2025 18:00:47 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1739142042;
 bh=5Wj6aEAfU9hM5OLDrktbSIqqKHBWxzEM0bYpzuOh02k=;
 h=Date:Subject:From:To:References:In-Reply-To:From;
 b=nWiQdbYG3xT2VEDOgCHnSTHY13xUjzlT5bX9mM6c3VdCkQY3LPIVDZAdmxMFM98T2
 RfwtP91LNhLBc60Ct0JcfYbkixpb4K6Un0SNC/IEi+UluA7SKlMDlaCLWi6KZ67Ku9
 SKFkIXsKLYKbWtfQ84/MusPzGG4jT3vS/ZmqQ0HM=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4YrjqG5X61z1118
 for <72803 <at> debbugs.gnu.org>; Sun,  9 Feb 2025 23:00:42 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4YrjqG51yHz110n
 for <72803 <at> debbugs.gnu.org>; Sun,  9 Feb 2025 23:00:42 +0000 (UTC)
Message-ID: <de6259a5-5c42-4158-a407-8c12d24036bd@HIDDEN>
Date: Mon, 10 Feb 2025 00:00:41 +0100
MIME-Version: 1.0
User-Agent: Icedove Daily
From: paul <goodoldpaul@HIDDEN>
References: <dd908cb9-d4b7-4c5e-84f8-d9a7d6e625c9@HIDDEN>
 <c5977a15-dedd-4396-8327-fa9a52710f80@HIDDEN>
 <08b873f4-26da-478a-bd61-91a03da51fb5@HIDDEN>
 <b6841b0b-2715-48e2-8928-837764e5df96@HIDDEN>
Content-Language: en-US
In-Reply-To: <b6841b0b-2715-48e2-8928-837764e5df96@HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Spam-Score: -0.0 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hi Guix,

I'm sending a v6. Compared to v5 it has the nice property of greatly 
simplifying the restic-guix script. Now there are no more multiple guile 
entrypoints (it used to be number of jobs * number of supported actions, 
so quite bad), there is only a single script which has embedded the 
information of all jobs, implements multiple actions and should be 
easily extendible to include more actions (like the init one proposed in 
https://issues.guix.gnu.org/71639 ).


Please let me know your thoughts on this!


Thank you all for your work,

giacomo





Message sent to ludo@HIDDEN, maxim.cournoyer@HIDDEN, guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] [PATCH v6] services: restic-backup: Add more restic commands to the restic-guix package.
References: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
In-Reply-To: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
Resent-From: Giacomo Leidi <goodoldpaul@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: ludo@HIDDEN, maxim.cournoyer@HIDDEN, guix-patches@HIDDEN
Resent-Date: Sun, 09 Feb 2025 23:02:02 +0000
Resent-Message-ID: <handler.72803.B72803.173914208919977 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: 72803 <at> debbugs.gnu.org
Cc: Giacomo Leidi <goodoldpaul@HIDDEN>, Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>
X-Debbugs-Original-Xcc: Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.173914208919977
          (code B ref 72803); Sun, 09 Feb 2025 23:02:02 +0000
Received: (at 72803) by debbugs.gnu.org; 9 Feb 2025 23:01:29 +0000
Received: from localhost ([127.0.0.1]:46824 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1thGIq-0005C8-Hz
	for submit <at> debbugs.gnu.org; Sun, 09 Feb 2025 18:01:29 -0500
Received: from confino.investici.org ([2a11:7980:1::2:0]:40487)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>)
 id 1thGIo-0005Bz-Tx
 for 72803 <at> debbugs.gnu.org; Sun, 09 Feb 2025 18:01:27 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1739142086;
 bh=2Afa+ZXsna+5ZmA8KFAoW2aZBS17iX0GfYB449wcRfg=;
 h=From:To:Cc:Subject:Date:From;
 b=U5oWgdOsu0acidZjdcSQWfWIFRFL+qG1+q+Sh81gulNeLG4eN5Xtq5RBbUCPVE45H
 pIbJ6tLhwwlj5KzQdna2bvi8Ca8mKuWP30uJJZTJrMwEgSL+bYbuyL/Gqza8W4/GQ8
 JzYYB+C2iX+qwQPPwyCIp031kSXblSWm0QeOuDhE=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4Yrjr60tGNz1118;
 Sun,  9 Feb 2025 23:01:26 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4Yrjr56z9jz110n; Sun,  9 Feb 2025 23:01:25 +0000 (UTC)
From: Giacomo Leidi <goodoldpaul@HIDDEN>
Date: Mon, 10 Feb 2025 00:01:19 +0100
Message-ID: <a1fac696c4ef5e20d0412ec22ae6a0d77ea26682.1739142079.git.goodoldpaul@HIDDEN>
X-Mailer: git-send-email 2.48.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.0 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

This patch refactors the way restic commands can be added to the
restic-guix package with a more general approach.  This way new
subcommands for restic-guix can be added more easily.

* gnu/services/backup.scm (restic-backup-job-program): Generalize to
restic-program;
(restic-guix): allow for multiple actions.

* doc/guix.texi: Document it.

Change-Id: Ib2b5d74bebc51e35f1ae6e1aa32cedee0da59697
---
 doc/guix.texi           |  20 +++++-
 gnu/services/backup.scm | 138 ++++++++++++++++++++++++++--------------
 2 files changed, 108 insertions(+), 50 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index ce780682ed0..86582fb4785 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -42837,6 +42837,23 @@ Miscellaneous Services
 sudo herd trigger remote-ftp
 @end example
 
+The @code{restic-backup-service-type} installs as well @code{restic-guix}
+to the system profile, a @code{restic} utility wrapper that allows for easier
+interaction with the Guix configured backup jobs.  For example the following
+could be used to list all the shapshots available on a given job's repository:
+
+@example
+restic-guix snapshots remote-ftp
+@end example
+
+All arguments passed after the job name will be passed to the underlying
+@code{restic} command, together with the @code{extra-flags} field from the
+@code{restic-backup-job} record:
+
+@example
+restic-guix restore remote-ftp -t `pwd`/restored -i .config/guix/channels.scm latest
+@end example
+
 @c %start of fragment
 
 @deftp {Data Type} restic-backup-configuration
@@ -42910,8 +42927,7 @@ Miscellaneous Services
 
 @item @code{extra-flags} (default: @code{'()}) (type: list-of-lowerables)
 A list of values that are lowered to strings.  These will be passed as
-command-line arguments to the current job @command{restic backup}
-invokation.
+command-line arguments to the current @command{restic} invokation.
 
 @end table
 
diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm
index 99a79ff5fbe..dcbed890e13 100644
--- a/gnu/services/backup.scm
+++ b/gnu/services/backup.scm
@@ -52,11 +52,12 @@ (define-module (gnu services backup)
             restic-backup-configuration-fields
             restic-backup-configuration-jobs
 
-            restic-backup-job-program
-            restic-backup-job->mcron-job
+            restic-program
+            restic-backup-job->shepherd-service
             restic-guix
             restic-guix-wrapper-package
             restic-backup-service-profile
+            restic-backup-service-activation
             restic-backup-service-type))
 
 (define (gexp-or-string? value)
@@ -129,7 +130,7 @@ (define-configuration/no-serialization restic-backup-job
   (extra-flags
    (list-of-lowerables '())
    "A list of values that are lowered to strings.  These will be passed as
-command-line arguments to the current job @command{restic backup} invokation."))
+command-line arguments to the current @command{restic} invokation."))
 
 (define list-of-restic-backup-jobs?
   (list-of restic-backup-job?))
@@ -139,71 +140,107 @@ (define-configuration/no-serialization restic-backup-configuration
    (list-of-restic-backup-jobs '())
    "The list of backup jobs for the current system."))
 
-(define (restic-backup-job-program config)
+(define %restic-guix-supported-actions
+  '("backup" "mount" "prune" "restore" "snapshots" "unlock"))
+
+(define (restic-backup-job->kv config)
   (let ((restic
          (file-append (restic-backup-job-restic config) "/bin/restic"))
+        (name
+         (restic-backup-job-name config))
         (repository
          (restic-backup-job-repository config))
         (password-file
          (restic-backup-job-password-file config))
-        (files
-         (restic-backup-job-files config))
         (extra-flags
          (restic-backup-job-extra-flags config))
-        (verbose
+        (verbose?
          (if (restic-backup-job-verbose? config)
              '("--verbose")
              '())))
-    (program-file
-     "restic-backup-job.scm"
-     #~(begin
-         (use-modules (ice-9 popen)
-                      (ice-9 rdelim))
-         (setenv "RESTIC_PASSWORD"
-                 (with-input-from-file #$password-file read-line))
+    #~(list #$name (list #$restic #$repository #$password-file
+                         (list #$@verbose?) (list #$@extra-flags)))))
+
+(define (restic-program config)
+  #~(lambda* (action action-args job-restic repository password-file verbose? extra-flags)
+      (use-modules (ice-9 format)
+                   (ice-9 popen)
+                   (ice-9 rdelim))
+      ;; This can be extended later, i.e. to have a
+      ;; centrally defined restic package.
+      ;; See https://issues.guix.gnu.org/71639
+      (define restic job-restic)
+
+      (define command
+        `(,restic ,@verbose?
+          "-r" ,repository
+          ,@extra-flags
+          ,action ,@action-args))
+
+      (setenv "RESTIC_PASSWORD"
+              (with-input-from-file password-file read-line))
 
-         (execlp #$restic #$restic #$@verbose
-                 "-r" #$repository
-                 #$@extra-flags
-                 "backup" #$@files)))))
+      (when (> (length verbose?) 0)
+        (format #t "Running~{ ~a~}~%" command))
 
-(define (restic-guix jobs)
+      (apply execlp `(,restic ,@command))))
+
+(define* (restic-guix config #:key (supported-actions
+                                    %restic-guix-supported-actions))
   (program-file
    "restic-guix"
    #~(begin
        (use-modules (ice-9 match)
                     (srfi srfi-1))
 
-       (define names '#$(map restic-backup-job-name jobs))
-       (define programs '#$(map restic-backup-job-program jobs))
-
-       (define (get-program name)
-         (define idx
-           (list-index (lambda (n) (string=? n name)) names))
-         (unless idx
-           (error (string-append "Unknown job name " name "\n\n"
-                                 "Possible job names are: "
-                                 (string-join names " "))))
-         (list-ref programs idx))
+       (define jobs
+         (list
+          #$@(map restic-backup-job->kv
+                  (restic-backup-configuration-jobs config))))
+       (define names (map first jobs))
+       (define (get-job key)
+         (first
+          (filter-map
+           (match-lambda
+             ((k v)
+              (and (string=? key k) v)))
+           jobs)))
 
-       (define (backup args)
-         (define name (third args))
-         (define program (get-program name))
-         (execlp program program))
+       (define restic-exec
+         #$(restic-program config))
 
        (define (validate-args args)
-         (when (not (>= (length args) 3))
-           (error (string-append "Usage: " (basename (car args))
-                                 " backup NAME"))))
+         (unless (>= (length args) 2)
+           (error (string-append "Usage: " (basename (first args))
+                                 " ACTION [ARGS]\n\nSupported actions are: "
+                                 #$(string-join supported-actions ", ") ".")))
+         (unless (member (second args) '#$supported-actions)
+           (error (string-append "Unknown action: " (second args) ". Supported"
+                                 "actions are: "
+                                 #$(string-join supported-actions ", ") "."))))
+
+       (define (validate-action-args action args)
+         (define argc (length args))
+         (when (not (>= argc 3))
+           (error (string-append "Usage: " (basename (first args))
+                                 " " action " JOB_NAME [ARGS]\n\nPossible job "
+                                 "names are: " (string-join names ", ") ".")))
+         (define job-name (third args))
+         (unless (member job-name names)
+           (error (string-append "Unknown job name: " job-name ". Possible job "
+                                 "names are: " (string-join names ", ") ".")))
+         (let ((job (get-job job-name))
+               (action-args
+                (if (> argc 3)
+                    (take-right args (- argc 3))
+                    '())))
+           (values job action-args)))
 
        (define (main args)
          (validate-args args)
          (define action (second args))
-         (match action
-           ("backup"
-            (backup args))
-           (_
-            (error (string-append "Unknown action: " action)))))
+         (define-values (job action-args) (validate-action-args action args))
+         (apply restic-exec `(,action ,action-args ,@job)))
 
        (main (command-line)))))
 
@@ -217,6 +254,10 @@ (define (restic-job-log-file job)
 (define (restic-backup-job->shepherd-service config)
   (let ((schedule (restic-backup-job-schedule config))
         (name (restic-backup-job-name config))
+        (files (string-join
+                (map (lambda (f) (string-append "'" f "'"))
+                     (restic-backup-job-files config))
+                " "))
         (user (restic-backup-job-user config))
         (group (restic-backup-job-group config))
         (max-duration (restic-backup-job-max-duration config))
@@ -242,7 +283,8 @@ (define (restic-backup-job->shepherd-service config)
                             ;; backends require, such as rclone.
                             (string-append #+bash-minimal "/bin/bash")
                             "-l" "-c"
-                            (string-append "restic-guix backup " #$name))
+                            (string-append
+                             "restic-guix backup " #$name " " #$files))
                            #:user #$user
                            #:group #$group
                            #:environment-variables
@@ -261,11 +303,11 @@ (define (restic-backup-job->shepherd-service config)
 without waiting for the scheduled time.")
                                       (procedure #~trigger-timer)))))))
 
-(define (restic-guix-wrapper-package jobs)
+(define (restic-guix-wrapper-package config)
   (package
     (name "restic-backup-service-wrapper")
     (version "0.0.0")
-    (source (restic-guix jobs))
+    (source (restic-guix config))
     (build-system copy-build-system)
     (arguments
      (list #:install-plan #~'(("./" "/bin"))))
@@ -284,10 +326,10 @@ (define restic-backup-service-profile
     (define jobs (restic-backup-configuration-jobs config))
     (if (> (length jobs) 0)
         (list
-         (restic-guix-wrapper-package jobs))
+         (restic-guix-wrapper-package config))
         '())))
 
-(define (restic-backup-activation config)
+(define (restic-backup-service-activation config)
   #~(for-each
      (lambda (log-file)
        (mkdir-p (dirname log-file)))
@@ -299,7 +341,7 @@ (define restic-backup-service-type
                 (extensions
                  (list
                   (service-extension activation-service-type
-                                     restic-backup-activation)
+                                     restic-backup-service-activation)
                   (service-extension profile-service-type
                                      restic-backup-service-profile)
                   (service-extension shepherd-root-service-type

base-commit: e27e63e6fe72d3a6cb6a8755f290ec710d339a9a
-- 
2.48.1





Message received at control <at> debbugs.gnu.org:


Received: (at control) by debbugs.gnu.org; 10 Feb 2025 00:10:45 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Feb 09 19:10:45 2025
Received: from localhost ([127.0.0.1]:46949 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1thHNt-0008TF-40
	for submit <at> debbugs.gnu.org; Sun, 09 Feb 2025 19:10:45 -0500
Received: from confino.investici.org ([93.190.126.19]:40609)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>)
 id 1thHNr-0008T5-7q
 for control <at> debbugs.gnu.org; Sun, 09 Feb 2025 19:10:43 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1739146242;
 bh=N7zQoB/lm3ZJ1eCx9NKt3zuz5zkYvGIRA/GUFVQXAwc=;
 h=Date:To:From:Subject:From;
 b=EWiAKsE4BRtEg7CMf0V0URHKtKfWXPTyxYCZobBp2c8k9EPPJC8g8p6RK3dV+Zt23
 wCnaEuiLPpoNwa8UsvJV9xYMAb4Nu5ohn84obilknP84yDoRqcRAW12hqM129jddTV
 9DCu0jnbf++WHhYlVlf8Qa7x2uFOgeZtUI1OxMX0=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4YrlN22Pdqz110V
 for <control <at> debbugs.gnu.org>; Mon, 10 Feb 2025 00:10:42 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4YrlN21tyRz110G
 for <control <at> debbugs.gnu.org>; Mon, 10 Feb 2025 00:10:42 +0000 (UTC)
Message-ID: <ed23b5b6-b369-4c19-84a5-502c3d566742@HIDDEN>
Date: Mon, 10 Feb 2025 01:10:41 +0100
MIME-Version: 1.0
User-Agent: Icedove Daily
To: control <at> debbugs.gnu.org
Content-Language: en-US
From: paul <goodoldpaul@HIDDEN>
Subject: block 76169 by 72803
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: control
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

block 76169 by 72803





Message sent to guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] Add restic commands to the restic-guix package
Resent-From: paul <goodoldpaul@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: guix-patches@HIDDEN
Resent-Date: Sun, 23 Feb 2025 16:42:01 +0000
Resent-Message-ID: <handler.72803.B72803.174032887710165 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: 72803 <at> debbugs.gnu.org
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.174032887710165
          (code B ref 72803); Sun, 23 Feb 2025 16:42:01 +0000
Received: (at 72803) by debbugs.gnu.org; 23 Feb 2025 16:41:17 +0000
Received: from localhost ([127.0.0.1]:35709 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tmF2a-0002dt-Pf
	for submit <at> debbugs.gnu.org; Sun, 23 Feb 2025 11:41:17 -0500
Received: from confino.investici.org ([93.190.126.19]:54873)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>)
 id 1tmF2X-0002dh-2K
 for 72803 <at> debbugs.gnu.org; Sun, 23 Feb 2025 11:41:15 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1740328870;
 bh=04QQYhrtckqcpxCwCb072MMgrmY9kBQtpbO1Iyi4slU=;
 h=Date:Subject:From:To:References:In-Reply-To:From;
 b=cC2nfdO9iHFNYZ2VVlg1D048KxVHjdAseInVpEir1TVHsV49XJG/Twy02HumNX6Ps
 igZKoaCxP1cAGKx2YOhoc196MvLMxXj3gVk0YbDNB4GKkS0F3QAUh8uoH8WGd1hKTO
 17RIohcPWgLDn7Nr8mj93IPr1PDRDDnf0K9VaFbE=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4Z18kt1CJZz10xK
 for <72803 <at> debbugs.gnu.org>; Sun, 23 Feb 2025 16:41:10 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4Z18kt0fMfz10x3
 for <72803 <at> debbugs.gnu.org>; Sun, 23 Feb 2025 16:41:10 +0000 (UTC)
Message-ID: <cc6cdfdc-d6e0-42f3-9526-307a39f96d39@HIDDEN>
Date: Sun, 23 Feb 2025 17:41:09 +0100
MIME-Version: 1.0
User-Agent: Icedove Daily
From: paul <goodoldpaul@HIDDEN>
References: <dd908cb9-d4b7-4c5e-84f8-d9a7d6e625c9@HIDDEN>
 <c5977a15-dedd-4396-8327-fa9a52710f80@HIDDEN>
 <08b873f4-26da-478a-bd61-91a03da51fb5@HIDDEN>
 <b6841b0b-2715-48e2-8928-837764e5df96@HIDDEN>
 <de6259a5-5c42-4158-a407-8c12d24036bd@HIDDEN>
Content-Language: en-US
In-Reply-To: <de6259a5-5c42-4158-a407-8c12d24036bd@HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

Hi,

I'm sending a v6 rebased on current master. Compared to v5 it adds 
support for the restic ls an restic list commands.

cheers,


giacomo





Message sent to guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] Add restic commands to the restic-guix package
Resent-From: paul <goodoldpaul@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: guix-patches@HIDDEN
Resent-Date: Sun, 23 Feb 2025 16:44:01 +0000
Resent-Message-ID: <handler.72803.B72803.174032900010364 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: 72803 <at> debbugs.gnu.org
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.174032900010364
          (code B ref 72803); Sun, 23 Feb 2025 16:44:01 +0000
Received: (at 72803) by debbugs.gnu.org; 23 Feb 2025 16:43:20 +0000
Received: from localhost ([127.0.0.1]:35713 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tmF4a-0002h6-Gd
	for submit <at> debbugs.gnu.org; Sun, 23 Feb 2025 11:43:20 -0500
Received: from confino.investici.org ([2a11:7980:1::2:0]:56977)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>)
 id 1tmF4Y-0002gw-RQ
 for 72803 <at> debbugs.gnu.org; Sun, 23 Feb 2025 11:43:19 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1740328995;
 bh=qyjyioe+aa6Q9cdNqYsIsvXaAEQjXV9eLsZXd5IdSBw=;
 h=Date:Subject:From:To:References:In-Reply-To:From;
 b=SQAw4ykBV9i00+jf8bH00ByksUBUcD0VJc1RKiMvdtuUA6i3dfIWjSezgETVM+S+0
 NTLK25Trs1eSgMa8B51enqk4sYCnUbD9fV/vPdYxh3TTpz2yDNWZVtxlouXMYrjylF
 RHInexMyPiMblPivKMofAOeSNAeqlVcJqFUT1WD4=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4Z18nH73bpz10xL
 for <72803 <at> debbugs.gnu.org>; Sun, 23 Feb 2025 16:43:15 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4Z18nH6YzDz10xK
 for <72803 <at> debbugs.gnu.org>; Sun, 23 Feb 2025 16:43:15 +0000 (UTC)
Message-ID: <3b9b96ec-5f67-4ca0-b10c-67518d18d642@HIDDEN>
Date: Sun, 23 Feb 2025 17:43:15 +0100
MIME-Version: 1.0
User-Agent: Icedove Daily
From: paul <goodoldpaul@HIDDEN>
References: <dd908cb9-d4b7-4c5e-84f8-d9a7d6e625c9@HIDDEN>
 <c5977a15-dedd-4396-8327-fa9a52710f80@HIDDEN>
 <08b873f4-26da-478a-bd61-91a03da51fb5@HIDDEN>
 <b6841b0b-2715-48e2-8928-837764e5df96@HIDDEN>
 <de6259a5-5c42-4158-a407-8c12d24036bd@HIDDEN>
 <cc6cdfdc-d6e0-42f3-9526-307a39f96d39@HIDDEN>
Content-Language: en-US
In-Reply-To: <cc6cdfdc-d6e0-42f3-9526-307a39f96d39@HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Spam-Score: -0.0 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hi again, sorry for the noise, I meant v7 :)

Thank you for your work!

giacomo




Message sent to ludo@HIDDEN, maxim.cournoyer@HIDDEN, guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] [PATCH v7] services: restic-backup: Add more restic commands to the restic-guix package.
References: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
In-Reply-To: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
Resent-From: Giacomo Leidi <goodoldpaul@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: ludo@HIDDEN, maxim.cournoyer@HIDDEN, guix-patches@HIDDEN
Resent-Date: Sun, 23 Feb 2025 16:45:02 +0000
Resent-Message-ID: <handler.72803.B72803.174032906610483 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: 72803 <at> debbugs.gnu.org
Cc: Giacomo Leidi <goodoldpaul@HIDDEN>, Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>
X-Debbugs-Original-Xcc: Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.174032906610483
          (code B ref 72803); Sun, 23 Feb 2025 16:45:02 +0000
Received: (at 72803) by debbugs.gnu.org; 23 Feb 2025 16:44:26 +0000
Received: from localhost ([127.0.0.1]:35717 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tmF5d-0002iz-3D
	for submit <at> debbugs.gnu.org; Sun, 23 Feb 2025 11:44:25 -0500
Received: from confino.investici.org ([93.190.126.19]:40425)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>)
 id 1tmF5a-0002iq-JA
 for 72803 <at> debbugs.gnu.org; Sun, 23 Feb 2025 11:44:23 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1740329061;
 bh=+zEcortRAg2sFaHkhqZTAtvlPXYjdrD/OFims268Eag=;
 h=From:To:Cc:Subject:Date:From;
 b=nl5d3vEnOGwMdEHKzR3N+lfFvtj4kzpUP4M/vy14rgVQrJDL6lMnnsjv3MZZpIe6a
 AlcNXU5lwDeGTkWy3yOikOhypiKvQ5MkskrhixKsmX8XA9Ov1D5yygqlvp4fs0ezHv
 81hsjFKoPSj0ipqLg0DSO4ByYtivGybydJ+QallA=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4Z18pY4SJNz10xK;
 Sun, 23 Feb 2025 16:44:21 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4Z18pY3RFmz10x1; Sun, 23 Feb 2025 16:44:21 +0000 (UTC)
From: Giacomo Leidi <goodoldpaul@HIDDEN>
Date: Sun, 23 Feb 2025 17:43:24 +0100
Message-ID: <f87b0019e7a43e5f74d338278fc807aac68a3a01.1740329004.git.goodoldpaul@HIDDEN>
X-Mailer: git-send-email 2.48.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

This patch refactors the way restic commands can be added to the
restic-guix package with a more general approach.  This way new
subcommands for restic-guix can be added more easily.

* gnu/services/backup.scm (restic-backup-job-program): Generalize to
restic-program;
(restic-guix): allow for multiple actions.

* doc/guix.texi: Document it.

Change-Id: Ib2b5d74bebc51e35f1ae6e1aa32cedee0da59697
---
 doc/guix.texi           |  20 +++++-
 gnu/services/backup.scm | 138 ++++++++++++++++++++++++++--------------
 2 files changed, 108 insertions(+), 50 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 83ba0f32923..5c99521f8e6 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -43271,6 +43271,23 @@ Miscellaneous Services
 sudo herd trigger remote-ftp
 @end example
 
+The @code{restic-backup-service-type} installs as well @code{restic-guix}
+to the system profile, a @code{restic} utility wrapper that allows for easier
+interaction with the Guix configured backup jobs.  For example the following
+could be used to list all the shapshots available on a given job's repository:
+
+@example
+restic-guix snapshots remote-ftp
+@end example
+
+All arguments passed after the job name will be passed to the underlying
+@code{restic} command, together with the @code{extra-flags} field from the
+@code{restic-backup-job} record:
+
+@example
+restic-guix restore remote-ftp -t `pwd`/restored -i .config/guix/channels.scm latest
+@end example
+
 @c %start of fragment
 
 @deftp {Data Type} restic-backup-configuration
@@ -43344,8 +43361,7 @@ Miscellaneous Services
 
 @item @code{extra-flags} (default: @code{'()}) (type: list-of-lowerables)
 A list of values that are lowered to strings.  These will be passed as
-command-line arguments to the current job @command{restic backup}
-invocation.
+command-line arguments to the current @command{restic} invocation.
 
 @end table
 
diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm
index 4d8cf167f04..dc095593432 100644
--- a/gnu/services/backup.scm
+++ b/gnu/services/backup.scm
@@ -52,11 +52,12 @@ (define-module (gnu services backup)
             restic-backup-configuration-fields
             restic-backup-configuration-jobs
 
-            restic-backup-job-program
-            restic-backup-job->mcron-job
+            restic-program
+            restic-backup-job->shepherd-service
             restic-guix
             restic-guix-wrapper-package
             restic-backup-service-profile
+            restic-backup-service-activation
             restic-backup-service-type))
 
 (define (gexp-or-string? value)
@@ -129,7 +130,7 @@ (define-configuration/no-serialization restic-backup-job
   (extra-flags
    (list-of-lowerables '())
    "A list of values that are lowered to strings.  These will be passed as
-command-line arguments to the current job @command{restic backup} invocation."))
+command-line arguments to the current @command{restic} invocation."))
 
 (define list-of-restic-backup-jobs?
   (list-of restic-backup-job?))
@@ -139,71 +140,107 @@ (define-configuration/no-serialization restic-backup-configuration
    (list-of-restic-backup-jobs '())
    "The list of backup jobs for the current system."))
 
-(define (restic-backup-job-program config)
+(define %restic-guix-supported-actions
+  '("backup" "list" "ls" "mount" "prune" "restore" "snapshots" "unlock"))
+
+(define (restic-backup-job->kv config)
   (let ((restic
          (file-append (restic-backup-job-restic config) "/bin/restic"))
+        (name
+         (restic-backup-job-name config))
         (repository
          (restic-backup-job-repository config))
         (password-file
          (restic-backup-job-password-file config))
-        (files
-         (restic-backup-job-files config))
         (extra-flags
          (restic-backup-job-extra-flags config))
-        (verbose
+        (verbose?
          (if (restic-backup-job-verbose? config)
              '("--verbose")
              '())))
-    (program-file
-     "restic-backup-job.scm"
-     #~(begin
-         (use-modules (ice-9 popen)
-                      (ice-9 rdelim))
-         (setenv "RESTIC_PASSWORD"
-                 (with-input-from-file #$password-file read-line))
+    #~(list #$name (list #$restic #$repository #$password-file
+                         (list #$@verbose?) (list #$@extra-flags)))))
+
+(define (restic-program config)
+  #~(lambda* (action action-args job-restic repository password-file verbose? extra-flags)
+      (use-modules (ice-9 format)
+                   (ice-9 popen)
+                   (ice-9 rdelim))
+      ;; This can be extended later, i.e. to have a
+      ;; centrally defined restic package.
+      ;; See https://issues.guix.gnu.org/71639
+      (define restic job-restic)
+
+      (define command
+        `(,restic ,@verbose?
+          "-r" ,repository
+          ,@extra-flags
+          ,action ,@action-args))
+
+      (setenv "RESTIC_PASSWORD"
+              (with-input-from-file password-file read-line))
 
-         (execlp #$restic #$restic #$@verbose
-                 "-r" #$repository
-                 #$@extra-flags
-                 "backup" #$@files)))))
+      (when (> (length verbose?) 0)
+        (format #t "Running~{ ~a~}~%" command))
 
-(define (restic-guix jobs)
+      (apply execlp `(,restic ,@command))))
+
+(define* (restic-guix config #:key (supported-actions
+                                    %restic-guix-supported-actions))
   (program-file
    "restic-guix"
    #~(begin
        (use-modules (ice-9 match)
                     (srfi srfi-1))
 
-       (define names '#$(map restic-backup-job-name jobs))
-       (define programs '#$(map restic-backup-job-program jobs))
-
-       (define (get-program name)
-         (define idx
-           (list-index (lambda (n) (string=? n name)) names))
-         (unless idx
-           (error (string-append "Unknown job name " name "\n\n"
-                                 "Possible job names are: "
-                                 (string-join names " "))))
-         (list-ref programs idx))
+       (define jobs
+         (list
+          #$@(map restic-backup-job->kv
+                  (restic-backup-configuration-jobs config))))
+       (define names (map first jobs))
+       (define (get-job key)
+         (first
+          (filter-map
+           (match-lambda
+             ((k v)
+              (and (string=? key k) v)))
+           jobs)))
 
-       (define (backup args)
-         (define name (third args))
-         (define program (get-program name))
-         (execlp program program))
+       (define restic-exec
+         #$(restic-program config))
 
        (define (validate-args args)
-         (when (not (>= (length args) 3))
-           (error (string-append "Usage: " (basename (car args))
-                                 " backup NAME"))))
+         (unless (>= (length args) 2)
+           (error (string-append "Usage: " (basename (first args))
+                                 " ACTION [ARGS]\n\nSupported actions are: "
+                                 #$(string-join supported-actions ", ") ".")))
+         (unless (member (second args) '#$supported-actions)
+           (error (string-append "Unknown action: " (second args) ". Supported"
+                                 "actions are: "
+                                 #$(string-join supported-actions ", ") "."))))
+
+       (define (validate-action-args action args)
+         (define argc (length args))
+         (when (not (>= argc 3))
+           (error (string-append "Usage: " (basename (first args))
+                                 " " action " JOB_NAME [ARGS]\n\nPossible job "
+                                 "names are: " (string-join names ", ") ".")))
+         (define job-name (third args))
+         (unless (member job-name names)
+           (error (string-append "Unknown job name: " job-name ". Possible job "
+                                 "names are: " (string-join names ", ") ".")))
+         (let ((job (get-job job-name))
+               (action-args
+                (if (> argc 3)
+                    (take-right args (- argc 3))
+                    '())))
+           (values job action-args)))
 
        (define (main args)
          (validate-args args)
          (define action (second args))
-         (match action
-           ("backup"
-            (backup args))
-           (_
-            (error (string-append "Unknown action: " action)))))
+         (define-values (job action-args) (validate-action-args action args))
+         (apply restic-exec `(,action ,action-args ,@job)))
 
        (main (command-line)))))
 
@@ -217,6 +254,10 @@ (define (restic-job-log-file job)
 (define (restic-backup-job->shepherd-service config)
   (let ((schedule (restic-backup-job-schedule config))
         (name (restic-backup-job-name config))
+        (files (string-join
+                (map (lambda (f) (string-append "'" f "'"))
+                     (restic-backup-job-files config))
+                " "))
         (user (restic-backup-job-user config))
         (group (restic-backup-job-group config))
         (max-duration (restic-backup-job-max-duration config))
@@ -242,7 +283,8 @@ (define (restic-backup-job->shepherd-service config)
                             ;; backends require, such as rclone.
                             (string-append #+bash-minimal "/bin/bash")
                             "-l" "-c"
-                            (string-append "restic-guix backup " #$name))
+                            (string-append
+                             "restic-guix backup " #$name " " #$files))
                            #:user #$user
                            #:group #$group
                            #:environment-variables
@@ -261,11 +303,11 @@ (define (restic-backup-job->shepherd-service config)
 without waiting for the scheduled time.")
                                       (procedure #~trigger-timer)))))))
 
-(define (restic-guix-wrapper-package jobs)
+(define (restic-guix-wrapper-package config)
   (package
     (name "restic-backup-service-wrapper")
     (version "0.0.0")
-    (source (restic-guix jobs))
+    (source (restic-guix config))
     (build-system copy-build-system)
     (arguments
      (list #:install-plan #~'(("./" "/bin"))))
@@ -284,10 +326,10 @@ (define restic-backup-service-profile
     (define jobs (restic-backup-configuration-jobs config))
     (if (> (length jobs) 0)
         (list
-         (restic-guix-wrapper-package jobs))
+         (restic-guix-wrapper-package config))
         '())))
 
-(define (restic-backup-activation config)
+(define (restic-backup-service-activation config)
   #~(for-each
      (lambda (log-file)
        (mkdir-p (dirname log-file)))
@@ -299,7 +341,7 @@ (define restic-backup-service-type
                 (extensions
                  (list
                   (service-extension activation-service-type
-                                     restic-backup-activation)
+                                     restic-backup-service-activation)
                   (service-extension profile-service-type
                                      restic-backup-service-profile)
                   (service-extension shepherd-root-service-type

base-commit: 23b068c036223e70bdea9d7d579850a1cffc02a7
-- 
2.48.1





Message sent to guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] Add restic commands to the restic-guix package
Resent-From: paul <goodoldpaul@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: guix-patches@HIDDEN
Resent-Date: Wed, 05 Mar 2025 22:45:01 +0000
Resent-Message-ID: <handler.72803.B72803.174121465930208 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: 72803 <at> debbugs.gnu.org
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.174121465930208
          (code B ref 72803); Wed, 05 Mar 2025 22:45:01 +0000
Received: (at 72803) by debbugs.gnu.org; 5 Mar 2025 22:44:19 +0000
Received: from localhost ([127.0.0.1]:40195 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tpxTP-0007r9-0o
	for submit <at> debbugs.gnu.org; Wed, 05 Mar 2025 17:44:19 -0500
Received: from confino.investici.org ([93.190.126.19]:45277)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>)
 id 1tpxTL-0007qz-VK
 for 72803 <at> debbugs.gnu.org; Wed, 05 Mar 2025 17:44:17 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1741214654;
 bh=X52PgQuUGy1hfKMlvghe2Qsk2wrNfTPfOjn35vrde28=;
 h=Date:Subject:From:To:References:In-Reply-To:From;
 b=rCMP/yPZdjbKgOGjclvU14yFvo9t/YgM9kAbfVyG/AUevpRTTJJIVmKP21iCTc0LR
 cGglRmOzcQmrpPBQqNcB2VlX+xqi4Ufv5qa2x/4UN6Vt9FhJSUsrAonNQmhyuSR6ek
 pL71MqrtYkcUb/Aodc4OUa7mNAmMpa4NfonW9p5M=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4Z7SKB0gPBz11JG
 for <72803 <at> debbugs.gnu.org>; Wed,  5 Mar 2025 22:44:14 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4Z7SKB03zzz11J6
 for <72803 <at> debbugs.gnu.org>; Wed,  5 Mar 2025 22:44:13 +0000 (UTC)
Message-ID: <d87fdaba-b639-4bd5-9352-52a96e4f08ce@HIDDEN>
Date: Wed, 5 Mar 2025 23:44:13 +0100
MIME-Version: 1.0
User-Agent: Icedove Daily
From: paul <goodoldpaul@HIDDEN>
References: <dd908cb9-d4b7-4c5e-84f8-d9a7d6e625c9@HIDDEN>
 <c5977a15-dedd-4396-8327-fa9a52710f80@HIDDEN>
 <08b873f4-26da-478a-bd61-91a03da51fb5@HIDDEN>
 <b6841b0b-2715-48e2-8928-837764e5df96@HIDDEN>
 <de6259a5-5c42-4158-a407-8c12d24036bd@HIDDEN>
 <cc6cdfdc-d6e0-42f3-9526-307a39f96d39@HIDDEN>
 <3b9b96ec-5f67-4ca0-b10c-67518d18d642@HIDDEN>
Content-Language: en-US
In-Reply-To: <3b9b96ec-5f67-4ca0-b10c-67518d18d642@HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

Hi, I'm sending a v8 rebased on current master.


thank you for your work





Message sent to ludo@HIDDEN, maxim.cournoyer@HIDDEN, guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] [PATCH v8] services: restic-backup: Add more restic commands to the restic-guix package.
References: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
In-Reply-To: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
Resent-From: Giacomo Leidi <goodoldpaul@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: ludo@HIDDEN, maxim.cournoyer@HIDDEN, guix-patches@HIDDEN
Resent-Date: Wed, 05 Mar 2025 22:46:02 +0000
Resent-Message-ID: <handler.72803.B72803.174121474430735 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: 72803 <at> debbugs.gnu.org
Cc: Giacomo Leidi <goodoldpaul@HIDDEN>, Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>
X-Debbugs-Original-Xcc: Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.174121474430735
          (code B ref 72803); Wed, 05 Mar 2025 22:46:02 +0000
Received: (at 72803) by debbugs.gnu.org; 5 Mar 2025 22:45:44 +0000
Received: from localhost ([127.0.0.1]:40202 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tpxUl-0007ze-Gi
	for submit <at> debbugs.gnu.org; Wed, 05 Mar 2025 17:45:44 -0500
Received: from confino.investici.org ([93.190.126.19]:32111)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>)
 id 1tpxUg-0007zR-Jf
 for 72803 <at> debbugs.gnu.org; Wed, 05 Mar 2025 17:45:41 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org;
 s=stigmate; t=1741214737;
 bh=phXq/HY1/60ZFkfuR0hEEcKZ0Z09Y+G2/qJ9zuagVbk=;
 h=From:To:Cc:Subject:Date:From;
 b=ETqGE73KNppdhAIjFGK3/Mx0QVU9hk7nHg9/hjwGCeYB/FiLDsr2DCGG1UXiCC0Jn
 pqqbpWTXkm2FoPiF5bvMhSDLUdUYuSPpDa0A6o3BAGBgdD+nmcKx6YVGQt+DXP6ghk
 oR+O62ZMe7lDIHwAUfeYgGdGP9BvXabTkh5s3Wno=
Received: from mx1.investici.org (unknown [127.0.0.1])
 by confino.investici.org (Postfix) with ESMTP id 4Z7SLn4PZ4z11JF;
 Wed,  5 Mar 2025 22:45:37 +0000 (UTC)
Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19])
 (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with
 ESMTPSA id 4Z7SLn3Nqrz11J6; Wed,  5 Mar 2025 22:45:37 +0000 (UTC)
From: Giacomo Leidi <goodoldpaul@HIDDEN>
Date: Wed,  5 Mar 2025 23:44:47 +0100
Message-ID: <eacc927e82941220e5d4bd1f8737e7edbe5b712f.1741214687.git.goodoldpaul@HIDDEN>
X-Mailer: git-send-email 2.48.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

This patch refactors the way restic commands can be added to the
restic-guix package with a more general approach.  This way new
subcommands for restic-guix can be added more easily.

* gnu/services/backup.scm (restic-backup-job-program): Generalize to
restic-program;
(restic-guix): allow for multiple actions.

* doc/guix.texi: Document it.

Change-Id: Ib2b5d74bebc51e35f1ae6e1aa32cedee0da59697
---
 doc/guix.texi           |  20 +++++-
 gnu/services/backup.scm | 138 ++++++++++++++++++++++++++--------------
 2 files changed, 108 insertions(+), 50 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 6844470ce2f..e4c5c86e91f 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -43709,6 +43709,23 @@ Miscellaneous Services
 sudo herd trigger remote-ftp
 @end example
 
+The @code{restic-backup-service-type} installs as well @code{restic-guix}
+to the system profile, a @code{restic} utility wrapper that allows for easier
+interaction with the Guix configured backup jobs.  For example the following
+could be used to list all the shapshots available on a given job's repository:
+
+@example
+restic-guix snapshots remote-ftp
+@end example
+
+All arguments passed after the job name will be passed to the underlying
+@code{restic} command, together with the @code{extra-flags} field from the
+@code{restic-backup-job} record:
+
+@example
+restic-guix restore remote-ftp -t `pwd`/restored -i .config/guix/channels.scm latest
+@end example
+
 @c %start of fragment
 
 @deftp {Data Type} restic-backup-configuration
@@ -43782,8 +43799,7 @@ Miscellaneous Services
 
 @item @code{extra-flags} (default: @code{'()}) (type: list-of-lowerables)
 A list of values that are lowered to strings.  These will be passed as
-command-line arguments to the current job @command{restic backup}
-invocation.
+command-line arguments to the current @command{restic} invocation.
 
 @end table
 
diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm
index 4d8cf167f04..dc095593432 100644
--- a/gnu/services/backup.scm
+++ b/gnu/services/backup.scm
@@ -52,11 +52,12 @@ (define-module (gnu services backup)
             restic-backup-configuration-fields
             restic-backup-configuration-jobs
 
-            restic-backup-job-program
-            restic-backup-job->mcron-job
+            restic-program
+            restic-backup-job->shepherd-service
             restic-guix
             restic-guix-wrapper-package
             restic-backup-service-profile
+            restic-backup-service-activation
             restic-backup-service-type))
 
 (define (gexp-or-string? value)
@@ -129,7 +130,7 @@ (define-configuration/no-serialization restic-backup-job
   (extra-flags
    (list-of-lowerables '())
    "A list of values that are lowered to strings.  These will be passed as
-command-line arguments to the current job @command{restic backup} invocation."))
+command-line arguments to the current @command{restic} invocation."))
 
 (define list-of-restic-backup-jobs?
   (list-of restic-backup-job?))
@@ -139,71 +140,107 @@ (define-configuration/no-serialization restic-backup-configuration
    (list-of-restic-backup-jobs '())
    "The list of backup jobs for the current system."))
 
-(define (restic-backup-job-program config)
+(define %restic-guix-supported-actions
+  '("backup" "list" "ls" "mount" "prune" "restore" "snapshots" "unlock"))
+
+(define (restic-backup-job->kv config)
   (let ((restic
          (file-append (restic-backup-job-restic config) "/bin/restic"))
+        (name
+         (restic-backup-job-name config))
         (repository
          (restic-backup-job-repository config))
         (password-file
          (restic-backup-job-password-file config))
-        (files
-         (restic-backup-job-files config))
         (extra-flags
          (restic-backup-job-extra-flags config))
-        (verbose
+        (verbose?
          (if (restic-backup-job-verbose? config)
              '("--verbose")
              '())))
-    (program-file
-     "restic-backup-job.scm"
-     #~(begin
-         (use-modules (ice-9 popen)
-                      (ice-9 rdelim))
-         (setenv "RESTIC_PASSWORD"
-                 (with-input-from-file #$password-file read-line))
+    #~(list #$name (list #$restic #$repository #$password-file
+                         (list #$@verbose?) (list #$@extra-flags)))))
+
+(define (restic-program config)
+  #~(lambda* (action action-args job-restic repository password-file verbose? extra-flags)
+      (use-modules (ice-9 format)
+                   (ice-9 popen)
+                   (ice-9 rdelim))
+      ;; This can be extended later, i.e. to have a
+      ;; centrally defined restic package.
+      ;; See https://issues.guix.gnu.org/71639
+      (define restic job-restic)
+
+      (define command
+        `(,restic ,@verbose?
+          "-r" ,repository
+          ,@extra-flags
+          ,action ,@action-args))
+
+      (setenv "RESTIC_PASSWORD"
+              (with-input-from-file password-file read-line))
 
-         (execlp #$restic #$restic #$@verbose
-                 "-r" #$repository
-                 #$@extra-flags
-                 "backup" #$@files)))))
+      (when (> (length verbose?) 0)
+        (format #t "Running~{ ~a~}~%" command))
 
-(define (restic-guix jobs)
+      (apply execlp `(,restic ,@command))))
+
+(define* (restic-guix config #:key (supported-actions
+                                    %restic-guix-supported-actions))
   (program-file
    "restic-guix"
    #~(begin
        (use-modules (ice-9 match)
                     (srfi srfi-1))
 
-       (define names '#$(map restic-backup-job-name jobs))
-       (define programs '#$(map restic-backup-job-program jobs))
-
-       (define (get-program name)
-         (define idx
-           (list-index (lambda (n) (string=? n name)) names))
-         (unless idx
-           (error (string-append "Unknown job name " name "\n\n"
-                                 "Possible job names are: "
-                                 (string-join names " "))))
-         (list-ref programs idx))
+       (define jobs
+         (list
+          #$@(map restic-backup-job->kv
+                  (restic-backup-configuration-jobs config))))
+       (define names (map first jobs))
+       (define (get-job key)
+         (first
+          (filter-map
+           (match-lambda
+             ((k v)
+              (and (string=? key k) v)))
+           jobs)))
 
-       (define (backup args)
-         (define name (third args))
-         (define program (get-program name))
-         (execlp program program))
+       (define restic-exec
+         #$(restic-program config))
 
        (define (validate-args args)
-         (when (not (>= (length args) 3))
-           (error (string-append "Usage: " (basename (car args))
-                                 " backup NAME"))))
+         (unless (>= (length args) 2)
+           (error (string-append "Usage: " (basename (first args))
+                                 " ACTION [ARGS]\n\nSupported actions are: "
+                                 #$(string-join supported-actions ", ") ".")))
+         (unless (member (second args) '#$supported-actions)
+           (error (string-append "Unknown action: " (second args) ". Supported"
+                                 "actions are: "
+                                 #$(string-join supported-actions ", ") "."))))
+
+       (define (validate-action-args action args)
+         (define argc (length args))
+         (when (not (>= argc 3))
+           (error (string-append "Usage: " (basename (first args))
+                                 " " action " JOB_NAME [ARGS]\n\nPossible job "
+                                 "names are: " (string-join names ", ") ".")))
+         (define job-name (third args))
+         (unless (member job-name names)
+           (error (string-append "Unknown job name: " job-name ". Possible job "
+                                 "names are: " (string-join names ", ") ".")))
+         (let ((job (get-job job-name))
+               (action-args
+                (if (> argc 3)
+                    (take-right args (- argc 3))
+                    '())))
+           (values job action-args)))
 
        (define (main args)
          (validate-args args)
          (define action (second args))
-         (match action
-           ("backup"
-            (backup args))
-           (_
-            (error (string-append "Unknown action: " action)))))
+         (define-values (job action-args) (validate-action-args action args))
+         (apply restic-exec `(,action ,action-args ,@job)))
 
        (main (command-line)))))
 
@@ -217,6 +254,10 @@ (define (restic-job-log-file job)
 (define (restic-backup-job->shepherd-service config)
   (let ((schedule (restic-backup-job-schedule config))
         (name (restic-backup-job-name config))
+        (files (string-join
+                (map (lambda (f) (string-append "'" f "'"))
+                     (restic-backup-job-files config))
+                " "))
         (user (restic-backup-job-user config))
         (group (restic-backup-job-group config))
         (max-duration (restic-backup-job-max-duration config))
@@ -242,7 +283,8 @@ (define (restic-backup-job->shepherd-service config)
                             ;; backends require, such as rclone.
                             (string-append #+bash-minimal "/bin/bash")
                             "-l" "-c"
-                            (string-append "restic-guix backup " #$name))
+                            (string-append
+                             "restic-guix backup " #$name " " #$files))
                            #:user #$user
                            #:group #$group
                            #:environment-variables
@@ -261,11 +303,11 @@ (define (restic-backup-job->shepherd-service config)
 without waiting for the scheduled time.")
                                       (procedure #~trigger-timer)))))))
 
-(define (restic-guix-wrapper-package jobs)
+(define (restic-guix-wrapper-package config)
   (package
     (name "restic-backup-service-wrapper")
     (version "0.0.0")
-    (source (restic-guix jobs))
+    (source (restic-guix config))
     (build-system copy-build-system)
     (arguments
      (list #:install-plan #~'(("./" "/bin"))))
@@ -284,10 +326,10 @@ (define restic-backup-service-profile
     (define jobs (restic-backup-configuration-jobs config))
     (if (> (length jobs) 0)
         (list
-         (restic-guix-wrapper-package jobs))
+         (restic-guix-wrapper-package config))
         '())))
 
-(define (restic-backup-activation config)
+(define (restic-backup-service-activation config)
   #~(for-each
      (lambda (log-file)
        (mkdir-p (dirname log-file)))
@@ -299,7 +341,7 @@ (define restic-backup-service-type
                 (extensions
                  (list
                   (service-extension activation-service-type
-                                     restic-backup-activation)
+                                     restic-backup-service-activation)
                   (service-extension profile-service-type
                                      restic-backup-service-profile)
                   (service-extension shepherd-root-service-type

base-commit: 310adf4ce70cbb864859274fcc7842bd519bbddc
-- 
2.48.1





Message sent to guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#72803] Add restic commands to the restic-guix package
Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: guix-patches@HIDDEN
Resent-Date: Mon, 10 Mar 2025 13:53:02 +0000
Resent-Message-ID: <handler.72803.B72803.17416147723768 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 72803
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: 
To: Giacomo Leidi <goodoldpaul@HIDDEN>
Cc: 72803 <at> debbugs.gnu.org, Maxim Cournoyer <maxim.cournoyer@HIDDEN>
Received: via spool by 72803-submit <at> debbugs.gnu.org id=B72803.17416147723768
          (code B ref 72803); Mon, 10 Mar 2025 13:53:02 +0000
Received: (at 72803) by debbugs.gnu.org; 10 Mar 2025 13:52:52 +0000
Received: from localhost ([127.0.0.1]:36788 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1trdYp-0000yg-RL
	for submit <at> debbugs.gnu.org; Mon, 10 Mar 2025 09:52:52 -0400
Received: from hera.aquilenet.fr ([185.233.100.1]:46626)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <ludo@HIDDEN>) id 1trdYl-0000y9-8Y
 for 72803 <at> debbugs.gnu.org; Mon, 10 Mar 2025 09:52:49 -0400
Received: from localhost (localhost [127.0.0.1])
 by hera.aquilenet.fr (Postfix) with ESMTP id 5A75B1C2;
 Mon, 10 Mar 2025 14:52:37 +0100 (CET)
Authentication-Results: hera.aquilenet.fr;
	none
X-Virus-Scanned: Debian amavis at hera.aquilenet.fr
Received: from hera.aquilenet.fr ([127.0.0.1])
 by localhost (hera.aquilenet.fr [127.0.0.1]) (amavis, port 10024) with ESMTP
 id mVoqTgS4_aVC; Mon, 10 Mar 2025 14:52:36 +0100 (CET)
Received: from ribbon (unknown [193.50.110.159])
 by hera.aquilenet.fr (Postfix) with ESMTPSA id 43DB364;
 Mon, 10 Mar 2025 14:52:34 +0100 (CET)
From: Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>
In-Reply-To: <eacc927e82941220e5d4bd1f8737e7edbe5b712f.1741214687.git.goodoldpaul@HIDDEN>
 (Giacomo Leidi's message of "Wed, 5 Mar 2025 23:44:47 +0100")
References: <db336bf4-14d8-e969-b998-dd5f98108066@HIDDEN>
 <eacc927e82941220e5d4bd1f8737e7edbe5b712f.1741214687.git.goodoldpaul@HIDDEN>
Date: Mon, 10 Mar 2025 14:52:32 +0100
Message-ID: <87msdtq9gf.fsf_-_@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Rspamd-Server: hera
X-Rspamd-Queue-Id: 5A75B1C2
X-Spamd-Result: default: False [4.86 / 15.00]; SPAM_FLAG(5.00)[];
 BAYES_HAM(-3.00)[100.00%]; NEURAL_SPAM(2.96)[0.987];
 MIME_GOOD(-0.10)[text/plain]; TO_DN_SOME(0.00)[];
 FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2];
 RCVD_TLS_ALL(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[];
 TAGGED_RCPT(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[];
 RCVD_VIA_SMTP_AUTH(0.00)[]; MID_RHS_MATCH_FROM(0.00)[];
 FROM_HAS_DN(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com];
 RCPT_COUNT_THREE(0.00)[3];
 FREEMAIL_CC(0.00)[debbugs.gnu.org,gmail.com]
X-Spamd-Bar: ++++
X-Rspamd-Action: no action
X-Spam-Level: ****
X-Spam-Score: 1.0 (+)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.0 (/)

Hi,

Giacomo Leidi <goodoldpaul@HIDDEN> skribis:

> This patch refactors the way restic commands can be added to the
> restic-guix package with a more general approach.  This way new
> subcommands for restic-guix can be added more easily.
>
> * gnu/services/backup.scm (restic-backup-job-program): Generalize to
> restic-program;
> (restic-guix): allow for multiple actions.
>
> * doc/guix.texi: Document it.
>
> Change-Id: Ib2b5d74bebc51e35f1ae6e1aa32cedee0da59697
> +(define (restic-program config)
> +  #~(lambda* (action action-args job-restic repository password-file ver=
bose? extra-flags)
> +      (use-modules (ice-9 format)
> +                   (ice-9 popen)
> +                   (ice-9 rdelim))

Please move =E2=80=98use-modules=E2=80=99 to the top-level; that=E2=80=99s =
the only guaranteed
way to use it.

> +(define* (restic-guix config #:key (supported-actions
> +                                    %restic-guix-supported-actions))
>    (program-file
>     "restic-guix"
>     #~(begin
>         (use-modules (ice-9 match)
>                      (srfi srfi-1))
>=20=20
> -       (define names '#$(map restic-backup-job-name jobs))
> -       (define programs '#$(map restic-backup-job-program jobs))
> -
> -       (define (get-program name)
> -         (define idx
> -           (list-index (lambda (n) (string=3D? n name)) names))
> -         (unless idx
> -           (error (string-append "Unknown job name " name "\n\n"
> -                                 "Possible job names are: "
> -                                 (string-join names " "))))
> -         (list-ref programs idx))
> +       (define jobs
> +         (list
> +          #$@(map restic-backup-job->kv
> +                  (restic-backup-configuration-jobs config))))
> +       (define names (map first jobs))
> +       (define (get-job key)
> +         (first
> +          (filter-map
> +           (match-lambda
> +             ((k v)
> +              (and (string=3D? key k) v)))
> +           jobs)))
>=20=20
> -       (define (backup args)
> -         (define name (third args))
> -         (define program (get-program name))
> -         (execlp program program))
> +       (define restic-exec
> +         #$(restic-program config))
>=20=20
>         (define (validate-args args)
> -         (when (not (>=3D (length args) 3))
> -           (error (string-append "Usage: " (basename (car args))
> -                                 " backup NAME"))))
> +         (unless (>=3D (length args) 2)
> +           (error (string-append "Usage: " (basename (first args))
> +                                 " ACTION [ARGS]\n\nSupported actions ar=
e: "
> +                                 #$(string-join supported-actions ", ") =
".")))
> +         (unless (member (second args) '#$supported-actions)
> +           (error (string-append "Unknown action: " (second args) ". Sup=
ported"
> +                                 "actions are: "
> +                                 #$(string-join supported-actions ", ") =
"."))))
> +
> +       (define (validate-action-args action args)
> +         (define argc (length args))
> +         (when (not (>=3D argc 3))
> +           (error (string-append "Usage: " (basename (first args))
> +                                 " " action " JOB_NAME [ARGS]\n\nPossibl=
e job "
> +                                 "names are: " (string-join names ", ") =
".")))
> +         (define job-name (third args))
> +         (unless (member job-name names)
> +           (error (string-append "Unknown job name: " job-name ". Possib=
le job "
> +                                 "names are: " (string-join names ", ") =
".")))
> +         (let ((job (get-job job-name))
> +               (action-args
> +                (if (> argc 3)
> +                    (take-right args (- argc 3))
> +                    '())))
> +           (values job action-args)))
>=20=20
>         (define (main args)
>           (validate-args args)
>           (define action (second args))
> -         (match action
> -           ("backup"
> -            (backup args))
> -           (_
> -            (error (string-append "Unknown action: " action)))))
> +         (define-values (job action-args) (validate-action-args action a=
rgs))
> +         (apply restic-exec `(,action ,action-args ,@job)))

I see two issues here:

  1. This is stepping on the toes of upstream: why are we providing a
     non-trivial program like this downstream?

  2. There are stylistic issues: use of =E2=80=98first=E2=80=99 & co. (info=
 "(guix) Data
     Types and Pattern Matching"), use of =E2=80=98error=E2=80=99 (it is to=
o generic and
     user-unfriendly), custom argument parsing procedure.

Thanks,
Ludo=E2=80=99.





Last modified: Mon, 10 Mar 2025 14:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.