From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] Add restic commands to the restic-guix package Resent-From: paul Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 25 Aug 2024 13:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@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 ) id 1siDiy-00071A-KH for submit@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 ) id 1siDiv-000710-Lg for submit@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 ) id 1siDi7-0008Iw-FW for guix-patches@gnu.org; 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 ) id 1siDi3-0006Ja-GH for guix-patches@gnu.org; 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 ; 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@autistici.org) by localhost (Postfix) with ESMTPSA id 4WsFg33xvzz112c for ; Sun, 25 Aug 2024 13:54:55 +0000 (UTC) Content-Type: multipart/alternative; boundary="------------9Llavbym5vDHYS1kfkBlgJnK" Message-ID: 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 Received-SPF: pass client-ip=2a11:7980:1::2:0; envelope-from=goodoldpaul@autistici.org; 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@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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

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-- From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] [PATCH] services: restic-backup: Add more restic commands to the restic-guix package. References: In-Reply-To: Resent-From: Giacomo Leidi Original-Sender: "Debbugs-submit" Resent-CC: pelzflorian@pelzflorian.de, ludo@gnu.org, matt@excalamus.com, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Sun, 25 Aug 2024 13:58:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org Cc: Giacomo Leidi , Florian Pelz , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Matthew Trzcinski , Maxim Cournoyer X-Debbugs-Original-Xcc: Florian Pelz , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Matthew Trzcinski , Maxim Cournoyer Received: via spool by 72803-submit@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 ) id 1siDkb-00077M-6v for submit@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 ) id 1siDkZ-00077C-61 for 72803@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@autistici.org) by localhost (Postfix) with ESMTPSA id 4WsFjN0Ry3z112c; Sun, 25 Aug 2024 13:56:56 +0000 (UTC) From: Giacomo Leidi Date: Sun, 25 Aug 2024 15:56:41 +0200 Message-ID: <1084765da10bf285803cbb7457997f73f785983d.1724594201.git.goodoldpaul@autistici.org> 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@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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 From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] Add restic commands to the restic-guix package References: Resent-From: Fabio Natali Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 02 Sep 2024 22:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org Cc: Giacomo Leidi Received: via spool by 72803-submit@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 ) id 1slFtS-0001EJ-JQ for submit@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 ) id 1slFtP-0001Dy-5E for 72803@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 In-Reply-To: <1084765da10bf285803cbb7457997f73f785983d.1724594201.git.goodoldpaul@autistici.org> Date: Mon, 02 Sep 2024 23:50:17 +0100 Message-ID: <8734mhfz6e.fsf@fabionatali.com> MIME-Version: 1.0 Content-Type: text/plain X-GND-Sasl: me@fabionatali.com X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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. From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] Add restic commands to the restic-guix package References: Resent-From: Fabio Natali Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 02 Sep 2024 23:04:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org Cc: Giacomo Leidi , Fabio Natali Received: via spool by 72803-submit@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 ) id 1slG4f-0001fV-0W for submit@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 ) id 1slG4b-0001el-N1 for 72803@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 In-Reply-To: <8734mhfz6e.fsf@fabionatali.com> Date: Tue, 03 Sep 2024 00:01:53 +0100 Message-ID: <87zfopek2m.fsf@fabionatali.com> MIME-Version: 1.0 Content-Type: text/plain X-GND-Sasl: me@fabionatali.com X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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. From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] Add restic commands to the restic-guix package Resent-From: paul Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 04 Sep 2024 22:29:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: Fabio Natali , 72803@debbugs.gnu.org Received: via spool by 72803-submit@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 ) id 1slyUJ-0003Xv-Qv for submit@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 ) id 1slyUH-0003Xm-Gi for 72803@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@autistici.org) by localhost (Postfix) with ESMTPSA id 4WzcNf4mcGz112X; Wed, 4 Sep 2024 22:19:30 +0000 (UTC) Message-ID: <2d83c75b-b750-b80d-5d7c-b4a6c89b4434@autistici.org> 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@fabionatali.com> Content-Language: en-US From: paul In-Reply-To: <8734mhfz6e.fsf@fabionatali.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -1.9 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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 From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] [PATCH v2] services: restic-backup: Add more restic commands to the restic-guix package. References: In-Reply-To: Resent-From: Giacomo Leidi Original-Sender: "Debbugs-submit" Resent-CC: pelzflorian@pelzflorian.de, ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Wed, 04 Sep 2024 22:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org Cc: Giacomo Leidi , Florian Pelz , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Florian Pelz , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 72803-submit@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 ) id 1slyWF-0003dP-If for submit@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 ) id 1slyWE-0003dI-Dr for 72803@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@autistici.org) by localhost (Postfix) with ESMTPSA id 4Wzcby2wR3z114S; Wed, 4 Sep 2024 22:29:18 +0000 (UTC) From: Giacomo Leidi Date: Thu, 5 Sep 2024 00:29:04 +0200 Message-ID: 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@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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 From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] Add restic commands to the restic-guix package References: In-Reply-To: Resent-From: paul Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 20 Oct 2024 22:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org Received: via spool by 72803-submit@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 ) id 1t2et3-0002IO-Cg for submit@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 ) id 1t2et2-0002IH-5l for 72803@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@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@autistici.org) by localhost (Postfix) with ESMTPSA id 4XWv4L4GzLz10xr for <72803@debbugs.gnu.org>; Sun, 20 Oct 2024 22:58:26 +0000 (UTC) Content-Type: multipart/alternative; boundary="------------2pT8kZ5kP4Ob0Y3A60w5rWFC" Message-ID: Date: Mon, 21 Oct 2024 00:58:26 +0200 MIME-Version: 1.0 User-Agent: Icedove Daily Content-Language: en-US From: paul X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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

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

Thank you for your work,

giacomo

--------------2pT8kZ5kP4Ob0Y3A60w5rWFC-- From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] [PATCH v2] services: restic-backup: Add more restic commands to the restic-guix package. References: In-Reply-To: Resent-From: Giacomo Leidi Original-Sender: "Debbugs-submit" Resent-CC: ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Sun, 20 Oct 2024 23:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org Cc: Giacomo Leidi , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 72803-submit@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 ) id 1t2etA-0002J8-PA for submit@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 ) id 1t2et8-0002J0-Qh for 72803@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@autistici.org) by localhost (Postfix) with ESMTPSA id 4XWv4b6J04z10xr; Sun, 20 Oct 2024 22:58:39 +0000 (UTC) From: Giacomo Leidi Date: Mon, 21 Oct 2024 00:58:31 +0200 Message-ID: <31413c193ddf6caccb7e23dd75796b6d89d5ceb7.1729465111.git.goodoldpaul@autistici.org> 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@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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 From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] Add restic commands to the restic-guix package Resent-From: paul Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 23 Dec 2024 11:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org Received: via spool by 72803-submit@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 ) id 1tPgXj-0007yr-20 for submit@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 ) id 1tPgXg-0007yi-TO for 72803@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@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@autistici.org) by localhost (Postfix) with ESMTPSA id 4YGwdg3jYcz10w5 for <72803@debbugs.gnu.org>; Mon, 23 Dec 2024 11:24:07 +0000 (UTC) Message-ID: Date: Mon, 23 Dec 2024 12:24:07 +0100 MIME-Version: 1.0 User-Agent: Icedove Daily From: paul References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Hi, I'm sending a v3 based on issue#75045. Thank you for your work, cheers giacomo From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] [PATCH v3] services: restic-backup: Add more restic commands to the restic-guix package. References: In-Reply-To: Resent-From: Giacomo Leidi Original-Sender: "Debbugs-submit" Resent-CC: ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Mon, 23 Dec 2024 11:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org Cc: Giacomo Leidi , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 72803-submit@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 ) id 1tPgYN-00080I-L7 for submit@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 ) id 1tPgYL-000805-JQ for 72803@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@autistici.org) by localhost (Postfix) with ESMTPSA id 4YGwfT04sbz10vv; Mon, 23 Dec 2024 11:24:48 +0000 (UTC) From: Giacomo Leidi Date: Mon, 23 Dec 2024 12:24:35 +0100 Message-ID: <9e1eec4968529a6f8bdcf6b4a14c91ce1595d0ad.1734953075.git.goodoldpaul@autistici.org> 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@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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 From debbugs-submit-bounces@debbugs.gnu.org Mon Dec 23 06:26:30 2024 Received: (at control) by debbugs.gnu.org; 23 Dec 2024 11:26:30 +0000 Received: from localhost ([127.0.0.1]:53550 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tPgZy-00089J-HE for submit@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 ) id 1tPgZx-00089C-8M for control@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 ; 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@autistici.org) by localhost (Postfix) with ESMTPSA id 4YGwhN5Czbz10vx for ; Mon, 23 Dec 2024 11:26:28 +0000 (UTC) Message-ID: <581fb166-b3b6-4eab-a349-ff7a75798873@autistici.org> Date: Mon, 23 Dec 2024 12:26:28 +0100 MIME-Version: 1.0 User-Agent: Icedove Daily Content-Language: en-US To: control@debbugs.gnu.org From: paul 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@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) block 72803 by 75045 From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] Add restic commands to the restic-guix package Resent-From: paul Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 23 Dec 2024 11:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org Received: via spool by 72803-submit@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 ) id 1tPgg2-0008SY-EM for submit@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 ) id 1tPgg0-0008SP-4E for 72803@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@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@autistici.org) by localhost (Postfix) with ESMTPSA id 4YGwqb3YsKz10wG for <72803@debbugs.gnu.org>; Mon, 23 Dec 2024 11:32:43 +0000 (UTC) Message-ID: <08b873f4-26da-478a-bd61-91a03da51fb5@autistici.org> Date: Mon, 23 Dec 2024 12:32:43 +0100 MIME-Version: 1.0 User-Agent: Icedove Daily From: paul References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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 From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] [PATCH v4] services: restic-backup: Add more restic commands to the restic-guix package. References: In-Reply-To: Resent-From: Giacomo Leidi Original-Sender: "Debbugs-submit" Resent-CC: ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Mon, 23 Dec 2024 14:18:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org Cc: Giacomo Leidi , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 72803-submit@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 ) id 1tPjFb-0007hw-MQ for submit@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 ) id 1tPjFY-0007hi-Nl for 72803@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@autistici.org) by localhost (Postfix) with ESMTPSA id 4YH0Tf4TQxz10wM; Mon, 23 Dec 2024 14:17:26 +0000 (UTC) From: Giacomo Leidi Date: Mon, 23 Dec 2024 15:17:18 +0100 Message-ID: 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@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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 From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] Add restic commands to the restic-guix package Resent-From: paul Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 24 Jan 2025 23:48:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org Received: via spool by 72803-submit@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 ) id 1tbTOj-0002pj-2M for submit@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 ) id 1tbTOg-0002pY-JP for 72803@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@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@autistici.org) by localhost (Postfix) with ESMTPSA id 4Yfvch57t4z11JZ for <72803@debbugs.gnu.org>; Fri, 24 Jan 2025 23:47:32 +0000 (UTC) Message-ID: Date: Sat, 25 Jan 2025 00:47:30 +0100 MIME-Version: 1.0 User-Agent: Icedove Daily From: paul References: <08b873f4-26da-478a-bd61-91a03da51fb5@autistici.org> Content-Language: en-US In-Reply-To: <08b873f4-26da-478a-bd61-91a03da51fb5@autistici.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Hi Guix, I'm sending a v5 rebased on current master, thank you for your time! From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] [PATCH v5] services: restic-backup: Add more restic commands to the restic-guix package. References: In-Reply-To: Resent-From: Giacomo Leidi Original-Sender: "Debbugs-submit" Resent-CC: ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Fri, 24 Jan 2025 23:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org Cc: Giacomo Leidi , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 72803-submit@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 ) id 1tbTPV-0002ri-Hb for submit@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 ) id 1tbTPS-0002rU-Cr for 72803@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@autistici.org) by localhost (Postfix) with ESMTPSA id 4Yfvdd2571z11LD; Fri, 24 Jan 2025 23:48:21 +0000 (UTC) From: Giacomo Leidi Date: Sat, 25 Jan 2025 00:47:54 +0100 Message-ID: <757f3b471a0b994c34fd6c8371aa19072ed04431.1737762473.git.goodoldpaul@autistici.org> 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@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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 From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] Add restic commands to the restic-guix package Resent-From: paul Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 09 Feb 2025 23:01:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org Received: via spool by 72803-submit@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 ) id 1thGID-0005AX-20 for submit@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 ) id 1thGIA-0005AL-0x for 72803@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@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@autistici.org) by localhost (Postfix) with ESMTPSA id 4YrjqG51yHz110n for <72803@debbugs.gnu.org>; Sun, 9 Feb 2025 23:00:42 +0000 (UTC) Message-ID: Date: Mon, 10 Feb 2025 00:00:41 +0100 MIME-Version: 1.0 User-Agent: Icedove Daily From: paul References: <08b873f4-26da-478a-bd61-91a03da51fb5@autistici.org> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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 From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] [PATCH v6] services: restic-backup: Add more restic commands to the restic-guix package. References: In-Reply-To: Resent-From: Giacomo Leidi Original-Sender: "Debbugs-submit" Resent-CC: ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Sun, 09 Feb 2025 23:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org Cc: Giacomo Leidi , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 72803-submit@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 ) id 1thGIq-0005C8-Hz for submit@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 ) id 1thGIo-0005Bz-Tx for 72803@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@autistici.org) by localhost (Postfix) with ESMTPSA id 4Yrjr56z9jz110n; Sun, 9 Feb 2025 23:01:25 +0000 (UTC) From: Giacomo Leidi Date: Mon, 10 Feb 2025 00:01:19 +0100 Message-ID: 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@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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 From debbugs-submit-bounces@debbugs.gnu.org Sun Feb 09 19:10:45 2025 Received: (at control) by debbugs.gnu.org; 10 Feb 2025 00:10:45 +0000 Received: from localhost ([127.0.0.1]:46949 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1thHNt-0008TF-40 for submit@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 ) id 1thHNr-0008T5-7q for control@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 ; 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@autistici.org) by localhost (Postfix) with ESMTPSA id 4YrlN21tyRz110G for ; Mon, 10 Feb 2025 00:10:42 +0000 (UTC) Message-ID: Date: Mon, 10 Feb 2025 01:10:41 +0100 MIME-Version: 1.0 User-Agent: Icedove Daily To: control@debbugs.gnu.org Content-Language: en-US From: paul 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@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) block 76169 by 72803 From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] Add restic commands to the restic-guix package Resent-From: paul Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 23 Feb 2025 16:42:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org Received: via spool by 72803-submit@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 ) id 1tmF2a-0002dt-Pf for submit@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 ) id 1tmF2X-0002dh-2K for 72803@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@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@autistici.org) by localhost (Postfix) with ESMTPSA id 4Z18kt0fMfz10x3 for <72803@debbugs.gnu.org>; Sun, 23 Feb 2025 16:41:10 +0000 (UTC) Message-ID: Date: Sun, 23 Feb 2025 17:41:09 +0100 MIME-Version: 1.0 User-Agent: Icedove Daily From: paul References: <08b873f4-26da-478a-bd61-91a03da51fb5@autistici.org> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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 From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] Add restic commands to the restic-guix package Resent-From: paul Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 23 Feb 2025 16:44:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org Received: via spool by 72803-submit@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 ) id 1tmF4a-0002h6-Gd for submit@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 ) id 1tmF4Y-0002gw-RQ for 72803@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@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@autistici.org) by localhost (Postfix) with ESMTPSA id 4Z18nH6YzDz10xK for <72803@debbugs.gnu.org>; Sun, 23 Feb 2025 16:43:15 +0000 (UTC) Message-ID: <3b9b96ec-5f67-4ca0-b10c-67518d18d642@autistici.org> Date: Sun, 23 Feb 2025 17:43:15 +0100 MIME-Version: 1.0 User-Agent: Icedove Daily From: paul References: <08b873f4-26da-478a-bd61-91a03da51fb5@autistici.org> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hi again, sorry for the noise, I meant v7 :) Thank you for your work! giacomo From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] [PATCH v7] services: restic-backup: Add more restic commands to the restic-guix package. References: In-Reply-To: Resent-From: Giacomo Leidi Original-Sender: "Debbugs-submit" Resent-CC: ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Sun, 23 Feb 2025 16:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org Cc: Giacomo Leidi , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 72803-submit@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 ) id 1tmF5d-0002iz-3D for submit@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 ) id 1tmF5a-0002iq-JA for 72803@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@autistici.org) by localhost (Postfix) with ESMTPSA id 4Z18pY3RFmz10x1; Sun, 23 Feb 2025 16:44:21 +0000 (UTC) From: Giacomo Leidi Date: Sun, 23 Feb 2025 17:43:24 +0100 Message-ID: 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@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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 From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] Add restic commands to the restic-guix package Resent-From: paul Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 05 Mar 2025 22:45:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org Received: via spool by 72803-submit@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 ) id 1tpxTP-0007r9-0o for submit@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 ) id 1tpxTL-0007qz-VK for 72803@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@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@autistici.org) by localhost (Postfix) with ESMTPSA id 4Z7SKB03zzz11J6 for <72803@debbugs.gnu.org>; Wed, 5 Mar 2025 22:44:13 +0000 (UTC) Message-ID: Date: Wed, 5 Mar 2025 23:44:13 +0100 MIME-Version: 1.0 User-Agent: Icedove Daily From: paul References: <08b873f4-26da-478a-bd61-91a03da51fb5@autistici.org> <3b9b96ec-5f67-4ca0-b10c-67518d18d642@autistici.org> Content-Language: en-US In-Reply-To: <3b9b96ec-5f67-4ca0-b10c-67518d18d642@autistici.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Hi, I'm sending a v8 rebased on current master. thank you for your work From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] [PATCH v8] services: restic-backup: Add more restic commands to the restic-guix package. References: In-Reply-To: Resent-From: Giacomo Leidi Original-Sender: "Debbugs-submit" Resent-CC: ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Wed, 05 Mar 2025 22:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org Cc: Giacomo Leidi , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 72803-submit@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 ) id 1tpxUl-0007ze-Gi for submit@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 ) id 1tpxUg-0007zR-Jf for 72803@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@autistici.org) by localhost (Postfix) with ESMTPSA id 4Z7SLn3Nqrz11J6; Wed, 5 Mar 2025 22:45:37 +0000 (UTC) From: Giacomo Leidi Date: Wed, 5 Mar 2025 23:44:47 +0100 Message-ID: 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@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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 From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] Add restic commands to the restic-guix package Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 10 Mar 2025 13:53:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: Giacomo Leidi Cc: 72803@debbugs.gnu.org, Maxim Cournoyer Received: via spool by 72803-submit@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 ) id 1trdYp-0000yg-RL for submit@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 ) id 1trdYl-0000y9-8Y for 72803@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?= In-Reply-To: (Giacomo Leidi's message of "Wed, 5 Mar 2025 23:44:47 +0100") References: Date: Mon, 10 Mar 2025 14:52:32 +0100 Message-ID: <87msdtq9gf.fsf_-_@gnu.org> 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@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Hi, Giacomo Leidi 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. From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] Add restic commands to the restic-guix package Resent-From: paul Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 10 Mar 2025 15:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 72803@debbugs.gnu.org, Maxim Cournoyer Received: via spool by 72803-submit@debbugs.gnu.org id=B72803.174162186830512 (code B ref 72803); Mon, 10 Mar 2025 15:52:02 +0000 Received: (at 72803) by debbugs.gnu.org; 10 Mar 2025 15:51:08 +0000 Received: from localhost ([127.0.0.1]:39387 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1trfPH-0007w4-W8 for submit@debbugs.gnu.org; Mon, 10 Mar 2025 11:51:08 -0400 Received: from confino.investici.org ([2a11:7980:1::2:0]:53079) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1trfPB-0007vU-VY for 72803@debbugs.gnu.org; Mon, 10 Mar 2025 11:51:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1741621858; bh=nxUiVp3ylJXrvPMr4y6MgutCaOKUip/0HuIqyM6M5jE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=R4r11Rvai1Mn5i/rTnlHjoIMeha8ROJu0z4h1bRu99UeRAzHAKCZ6NYxaiTK7wVdW 5INtJ0vWawqFRO+77VNJ7vQh6qEOL2Lmrp/bHaorlF98TYA10c6xOOAHWTGq48LSg2 i3g0z1rlAoP/+zmNj2sOLIyQr0yyR53/3ZUO4l5s= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4ZBLw25RCDz11FK; Mon, 10 Mar 2025 15:50:58 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@autistici.org) by localhost (Postfix) with ESMTPSA id 4ZBLw24PyKz11F7; Mon, 10 Mar 2025 15:50:58 +0000 (UTC) Content-Type: multipart/alternative; boundary="------------CLKTpCWzTLXCDiHNQFKIAUzW" Message-ID: <783760a3-1fc0-4803-8ea6-009e49cf760a@autistici.org> Date: Mon, 10 Mar 2025 16:50:57 +0100 MIME-Version: 1.0 User-Agent: Icedove Daily References: <87msdtq9gf.fsf_-_@gnu.org> Content-Language: en-US From: paul In-Reply-To: <87msdtq9gf.fsf_-_@gnu.org> X-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) This is a multi-part message in MIME format. --------------CLKTpCWzTLXCDiHNQFKIAUzW Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi Ludo’ , first thanks a lot for your review, On 3/10/25 14:52, Ludovic Courtès wrote: > 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? In my understanding this is the fundamental issue, which could be a shipstopper. Please correct me if I'm wrong. We kind of are obviously even if restic-guix is already in the master branch ( ) . In my opinion the way forward should be: a. In this scenario we merge the current 72803 (after addressing your other comments) and we take this risk b. In this scenario we remove completely the current incomplete restic-guix command implementation from master, as it makes not much sense to have it incomplete as it is right now. I view scenario a and scenario b as mutually exclusive but I may be missing some implication, what is your opinion on this? > 2. There are stylistic issues: use of ‘first’ & co. (info "(guix) Data > Types and Pattern Matching"), use of ‘error’ (it is too generic and > user-unfriendly), custom argument parsing procedure. I will address these comments only if we decide to go forward with scenario a. Thank you so much for your work, cheers giacomo --------------CLKTpCWzTLXCDiHNQFKIAUzW Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Hi Ludo’ ,

first thanks a lot for your review,

On 3/10/25 14:52, Ludovic Courtès wrote:
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?

In my understanding this is the fundamental issue, which could be a shipstopper. Please correct me if I'm wrong. We kind of are obviously even if restic-guix is already in the master branch ( ) . In my opinion the way forward should be: a. In this scenario we merge the current 72803 (after addressing your other comments) and we take this risk

b. In this scenario we remove completely the current incomplete restic-guix command implementation from master, as it makes not much sense to have it incomplete as it is right now.

I view scenario a and scenario b as mutually exclusive but I may be missing some implication, what is your opinion on this?

  2. There are stylistic issues: use of ‘first’ & co. (info "(guix) Data
     Types and Pattern Matching"), use of ‘error’ (it is too generic and
     user-unfriendly), custom argument parsing procedure.

I will address these comments only if we decide to go forward with scenario a.


Thank you so much for your work,


cheers

giacomo

--------------CLKTpCWzTLXCDiHNQFKIAUzW-- From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] Add restic commands to the restic-guix package Resent-From: paul Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 10 Mar 2025 15:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 72803@debbugs.gnu.org, Maxim Cournoyer Received: via spool by 72803-submit@debbugs.gnu.org id=B72803.174162206930907 (code B ref 72803); Mon, 10 Mar 2025 15:55:02 +0000 Received: (at 72803) by debbugs.gnu.org; 10 Mar 2025 15:54:29 +0000 Received: from localhost ([127.0.0.1]:39399 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1trfSX-00082Q-3j for submit@debbugs.gnu.org; Mon, 10 Mar 2025 11:54:29 -0400 Received: from confino.investici.org ([2a11:7980:1::2:0]:25583) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1trfSQ-00082D-OX for 72803@debbugs.gnu.org; Mon, 10 Mar 2025 11:54:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1741622061; bh=FihFzSyBRkySUeCO6gQQyZHS1ccWUeDuTEmdzqi5JRc=; h=Date:Subject:From:To:Cc:References:In-Reply-To:From; b=fTZ6Xx3eC6iBQqtwIQ7qNYLySv0Sz5Avv38RiXz3LsCRkDwrSGh8GtQSnhlVDzVbG 7Ert2phciWAhrpspi6nFcG69YKQSeR7Rq6ZkkAJu67dbNvJLWCMqTuxIrQ4W8JwwQP zvFzQ2hjwANxn96GZM+FGS84rGPXfCSwGIT3CWsg= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4ZBLzx4xF6z117J; Mon, 10 Mar 2025 15:54:21 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@autistici.org) by localhost (Postfix) with ESMTPSA id 4ZBLzx3ngpz1179; Mon, 10 Mar 2025 15:54:21 +0000 (UTC) Content-Type: multipart/alternative; boundary="------------206JivTiQK2ce5wqq20rSNH0" Message-ID: Date: Mon, 10 Mar 2025 16:54:21 +0100 MIME-Version: 1.0 User-Agent: Icedove Daily From: paul References: <87msdtq9gf.fsf_-_@gnu.org> <783760a3-1fc0-4803-8ea6-009e49cf760a@autistici.org> Content-Language: en-US In-Reply-To: <783760a3-1fc0-4803-8ea6-009e49cf760a@autistici.org> X-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) This is a multi-part message in MIME format. --------------206JivTiQK2ce5wqq20rSNH0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Ah I hit return too soon :/ Apologies for the noise. This is what I wanted to add to my previous message: ... We kind of are obviously even if restic-guix is already in the master branch ( https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/services/backup.scm#n170 ), which suffers from many of the shortcomings you noticed in your review, such as: use of ‘first & co., use of ‘error’, custom argument parsing procedure. In my opinion ... thank you again for your review, giacomo --------------206JivTiQK2ce5wqq20rSNH0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit Ah I hit return too soon :/ Apologies for the noise. This is what I wanted to add to my previous message:


... We kind of are obviously even if restic-guix is already in the master branch ( https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/services/backup.scm#n170 ), which suffers from many of the shortcomings you noticed in your review, such as: use of first & co., use of ‘error’, custom argument parsing procedure. In my opinion ...

thank you again for your review,

giacomo

--------------206JivTiQK2ce5wqq20rSNH0-- From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] Add restic commands to the restic-guix package Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 10 Mar 2025 21:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: paul Cc: 72803@debbugs.gnu.org, Maxim Cournoyer Received: via spool by 72803-submit@debbugs.gnu.org id=B72803.174164288912445 (code B ref 72803); Mon, 10 Mar 2025 21:42:02 +0000 Received: (at 72803) by debbugs.gnu.org; 10 Mar 2025 21:41:29 +0000 Received: from localhost ([127.0.0.1]:40205 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1trksK-0003Ee-Tk for submit@debbugs.gnu.org; Mon, 10 Mar 2025 17:41:29 -0400 Received: from hera.aquilenet.fr ([185.233.100.1]:33084) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1trksI-0003EL-II for 72803@debbugs.gnu.org; Mon, 10 Mar 2025 17:41:27 -0400 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id EAE1851E; Mon, 10 Mar 2025 22:41:17 +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 ctgCQnyH826H; Mon, 10 Mar 2025 22:41:16 +0100 (CET) Received: from ribbon (91-160-117-201.subs.proxad.net [91.160.117.201]) by hera.aquilenet.fr (Postfix) with ESMTPSA id CC2081C2; Mon, 10 Mar 2025 22:41:13 +0100 (CET) From: Ludovic =?UTF-8?Q?Court=C3=A8s?= In-Reply-To: <783760a3-1fc0-4803-8ea6-009e49cf760a@autistici.org> (paul's message of "Mon, 10 Mar 2025 16:50:57 +0100") References: <87msdtq9gf.fsf_-_@gnu.org> <783760a3-1fc0-4803-8ea6-009e49cf760a@autistici.org> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: =?UTF-8?Q?D=C3=A9cadi?= 20 =?UTF-8?Q?Vent=C3=B4se?= an 233 de la =?UTF-8?Q?R=C3=A9volution,?= jour du Cordeau X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Mon, 10 Mar 2025 22:41:12 +0100 Message-ID: <87wmcwmumf.fsf@gnu.org> 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: EAE1851E X-Spamd-Result: default: False [-6.10 / 15.00]; BAYES_HAM(-3.00)[99.99%]; NEURAL_HAM(-3.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; MID_RHS_MATCH_FROM(0.00)[]; ARC_NA(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; TAGGED_RCPT(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-Score: 1.0 (+) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Hi, paul skribis: > On 3/10/25 14:52, Ludovic Court=C3=A8s wrote: >> 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? > > In my understanding this is the fundamental issue, which could be a > shipstopper. Please correct me if I'm wrong. We kind of are obviously > even if restic-guix is already in the master branch ( ) . In my > opinion the way forward should be: a. In this scenario we merge the > current 72803 (after addressing your other comments) and we take this > risk > > b. In this scenario we remove completely the current incomplete > restic-guix command implementation from master, as it makes not much > sense to have it incomplete as it is right now. > > I view scenario a and scenario b as mutually exclusive but I may be > missing some implication, what is your opinion on this? I=E2=80=99m not a restic user so I=E2=80=99m not super qualified, but I thi= nk the general direction should be to stick to our role of downstream users; if we go too far in terms of tooling around the software, then that suggests something=E2=80=99s missing from what upstream provides, and perha= ps more importantly that=E2=80=99s a maintenance burden on us. >From that perspective, I lean towards scenario b, but I trust you can find the right middle ground. WDYT? Ludo=E2=80=99. From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] Add restic commands to the restic-guix package Resent-From: paul Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 29 Apr 2025 00:00:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 72803@debbugs.gnu.org, Maxim Cournoyer Received: via spool by 72803-submit@debbugs.gnu.org id=B72803.17458847995856 (code B ref 72803); Tue, 29 Apr 2025 00:00:03 +0000 Received: (at 72803) by debbugs.gnu.org; 28 Apr 2025 23:59:59 +0000 Received: from localhost ([127.0.0.1]:39650 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1u9YOE-0001WO-PH for submit@debbugs.gnu.org; Mon, 28 Apr 2025 19:59:59 -0400 Received: from confino.investici.org ([2a11:7980:1::2:0]:34655) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1u9YO4-0001Uh-QU for 72803@debbugs.gnu.org; Mon, 28 Apr 2025 19:59:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1745884785; bh=CIJ3gJBNfUhQ2ityk4nBcwf1vh8UIUCTGtYos10phHs=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=bItsuMndN0xnHyu0tGjmArPg0bk3/GLNoJ2uzeAmP9hqjAMyx2nyFcXrgZ3LihoHv V25V38xraWv8I6aZfNtWXJHghWwtLHMVOI4L9FSNNYFE4AL+ebXxk20Bv0ijCn0CMu X2bUuhCZB9+Tg45+3wCK/5qz6S/lqkxo8iWCgmac= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4ZmgRP1T82z114L; Mon, 28 Apr 2025 23:59:45 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@autistici.org) by localhost (Postfix) with ESMTPSA id 4ZmgRP0B3Cz114C; Mon, 28 Apr 2025 23:59:44 +0000 (UTC) Content-Type: multipart/alternative; boundary="------------98EHfwrw52yZUrr0K0yS00AB" Message-ID: <6a8923ea-1ef6-4631-8625-172c7815fa3b@autistici.org> Date: Tue, 29 Apr 2025 01:59:44 +0200 MIME-Version: 1.0 User-Agent: Icedove Daily References: <87msdtq9gf.fsf_-_@gnu.org> <783760a3-1fc0-4803-8ea6-009e49cf760a@autistici.org> <87wmcwmumf.fsf@gnu.org> Content-Language: en-US From: paul In-Reply-To: <87wmcwmumf.fsf@gnu.org> X-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) This is a multi-part message in MIME format. --------------98EHfwrw52yZUrr0K0yS00AB Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi Ludo', On 3/10/25 22:41, Ludovic Courtès wrote: > I’m not a restic user so I’m not super qualified, but I think the > general direction should be to stick to our role of downstream users; if > we go too far in terms of tooling around the software, then that > suggests something’s missing from what upstream provides, and perhaps > more importantly that’s a maintenance burden on us. You were definitely right, I found out this has been known upstream for at least 10 years :( .  I found https://github.com/restic/restic/issues/16 which proves this is a missing feature upstream.  To avoid the maintenance cost I'll drop the restic-guix package.  Its functionality can be implemented in a separate Guix based project or by using one of the different FOSS projects implementing a configuration file for restic. > From that perspective, I lean towards scenario b, but I trust you can > find the right middle ground. Thank you for your help, I'm sending a v9 which can hopefully be the final revision. cheers, giacomo --------------98EHfwrw52yZUrr0K0yS00AB Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Hi Ludo',

On 3/10/25 22:41, Ludovic Courtès wrote:
I’m not a restic user so I’m not super qualified, but I think the
general direction should be to stick to our role of downstream users; if
we go too far in terms of tooling around the software, then that
suggests something’s missing from what upstream provides, and perhaps
more importantly that’s a maintenance burden on us.
You were definitely right, I found out this has been known upstream for at least 10 years :( .  I found https://github.com/restic/restic/issues/16 which proves this is a missing feature upstream.  To avoid the maintenance
cost I'll drop the restic-guix package.  Its functionality can be implemented in a separate Guix based project or by using one of the different FOSS projects implementing a configuration file for restic.
From that perspective, I lean towards scenario b, but I trust you can
find the right middle ground.

Thank you for your help, I'm sending a v9 which can hopefully be the final revision.


cheers,
giacomo

--------------98EHfwrw52yZUrr0K0yS00AB-- From unknown Tue Jun 17 22:30:02 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#72803] [PATCH v9] services: restic-backup: Drop restic-guix command. References: In-Reply-To: Resent-From: Giacomo Leidi Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 29 Apr 2025 00:02:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72803 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72803@debbugs.gnu.org Cc: Giacomo Leidi Received: via spool by 72803-submit@debbugs.gnu.org id=B72803.17458849017023 (code B ref 72803); Tue, 29 Apr 2025 00:02:05 +0000 Received: (at 72803) by debbugs.gnu.org; 29 Apr 2025 00:01:41 +0000 Received: from localhost ([127.0.0.1]:39677 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1u9YPs-0001pC-QY for submit@debbugs.gnu.org; Mon, 28 Apr 2025 20:01:41 -0400 Received: from confino.investici.org ([2a11:7980:1::2:0]:53535) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1u9YPo-0001oy-K9 for 72803@debbugs.gnu.org; Mon, 28 Apr 2025 20:01:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1745884895; bh=cZttipHo8eolwetZpdPWmMPiiNeADiCbLXjjCch4bCg=; h=From:To:Cc:Subject:Date:From; b=khvxUjNgADP+jKpJrzQqK99Fcqn42h4TYA2TBW+j5mu47BZeQqPoE5yFz/+MOI7P2 UGkTkLBA0sgAmiN+ZWq8AANENViiycNjpt1lOO8rzWif5uuj0Ystap4Fc95QPhQ2qg Pe8JOBVRTtIDDLtqrfI9hqQeIPy2ET6rmZ1cgDvc= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4ZmgTW57Rqz114L; Tue, 29 Apr 2025 00:01:35 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@autistici.org) by localhost (Postfix) with ESMTPSA id 4ZmgTW3yzLz114C; Tue, 29 Apr 2025 00:01:35 +0000 (UTC) From: Giacomo Leidi Date: Tue, 29 Apr 2025 02:00:16 +0200 Message-ID: <25dac960ce99c32cf53cdf010351b7355f072fa1.1745884816.git.goodoldpaul@autistici.org> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) restic-guix has always been close to a reimplementation of a restic command line. https://github.com/restic/restic/issues/16 was then found out, indicating a missing feature upstream. To avoid the maintenance cost we drop the restic-guix package. Its functionality can be implemented in a separate project or by using one of the different FOSS projects implementing a configuration file for restic. * gnu/services/backup.scm: Drop mcron obsolete export. (restic-backup-job-program): Generalize to restic-program. (lower-restic-backup-job): New procedure implementing a standard way to lower restic-backup-job records into lists. (restic-guix): Drop procedure; (restic-program): Implement general way to run restic commands, for example to initialize repositories. (restic-backup): New procedure returning a gexp for the entrypoint of the backup job. (restic-job-logfile): Rename to restic-backup-log-file. (restic-backup-job-command): New procedure returning the restic command file for the Shepherd timer as a gexped list. (restic-backup-job-requirement): New procedure returning the Shepherd timer Shepherd dependencies. (restic-backup-job-modules): New procedure returning the Guile modules that will be loaded in the Shepherd timer. (restic-backup-job->shepherd-service): Use the new procedures and use the trigger action from (shepherd service timer). (restic-guix-wrapper-package): Drop procedure. (restic-backup-service-profile): Drop procedure. (restic-backup-service-activation): Drop procedure as now the Shepherd takes care of creating timers log file directories. (restic-backup-service-type): Drop profile and activation services extensions. Change-Id: Ib2b5d74bebc51e35f1ae6e1aa32cedee0da59697 --- gnu/services/backup.scm | 178 ++++++++++++++++------------------------ 1 file changed, 71 insertions(+), 107 deletions(-) diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm index 6e066bd3d66..4fff815e168 100644 --- a/gnu/services/backup.scm +++ b/gnu/services/backup.scm @@ -47,16 +47,19 @@ (define-module (gnu services backup) restic-backup-job-verbose? restic-backup-job-extra-flags + lower-restic-backup-job + restic-backup-configuration restic-backup-configuration? restic-backup-configuration-fields restic-backup-configuration-jobs - restic-backup-job-program - restic-backup-job->mcron-job - restic-guix - restic-guix-wrapper-package - restic-backup-service-profile + restic-program + restic-backup-job-log-file + restic-backup-job-command + restic-backup-job-requirement + restic-backup-job-modules + restic-backup-job->shepherd-service restic-backup-service-type)) (define (gexp-or-string? value) @@ -139,110 +142,104 @@ (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 (lower-restic-backup-job config) (let ((restic (file-append (restic-backup-job-restic config) "/bin/restic")) + (name + (restic-backup-job-name config)) + (files + (restic-backup-job-files 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 (list #$@files) #$restic #$repository #$password-file + (list #$@verbose?) (list #$@extra-flags)))) - (execlp #$restic #$restic #$@verbose - "-r" #$repository - #$@extra-flags - "backup" #$@files))))) - -(define (restic-guix jobs) - (program-file - "restic-guix" - #~(begin - (use-modules (ice-9 match) - (srfi srfi-1)) +(define restic-program + #~(lambda (action action-args job-restic repository password-file verbose? extra-flags) + (use-modules (ice-9 format)) + ;; 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 names '#$(map restic-backup-job-name jobs)) - (define programs '#$(map restic-backup-job-program jobs)) + (define command + `(,restic ,@verbose? + "-r" ,repository + ,@extra-flags + ,action ,@action-args)) - (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)) + (setenv "RESTIC_PASSWORD_FILE" password-file) - (define (backup args) - (define name (third args)) - (define program (get-program name)) - (execlp program program)) + (when (> (length verbose?) 0) + (format #t "Running~{ ~a~}~%" command)) - (define (validate-args args) - (when (not (>= (length args) 3)) - (error (string-append "Usage: " (basename (car args)) - " backup NAME")))) + (apply execlp `(,restic ,@command)))) - (define (main args) - (validate-args args) - (define action (second args)) - (match action - ("backup" - (backup args)) - (_ - (error (string-append "Unknown action: " action))))) +(define (restic-backup config) + (program-file + "restic-backup" + #~(let ((restic-exec + #$restic-program) + (job #$(lower-restic-backup-job config))) - (main (command-line))))) + (apply restic-exec `("backup" ,@job))))) -(define (restic-job-log-file job) +(define (restic-backup-job-log-file job) (let ((name (restic-backup-job-name job)) (log-file (restic-backup-job-log-file job))) (if (maybe-value-set? log-file) log-file (string-append "/var/log/restic-backup/" name ".log")))) +(define (restic-backup-job-command config) + ;; We go through bash, instead of executing + ;; restic-guix directly, because the login shell + ;; gives us the correct user environment that some + ;; backends require, such as rclone. + #~(list + (string-append #$bash-minimal "/bin/bash") + "-l" "-c" + (string-join (list #$(restic-backup config)) + " "))) + +(define (restic-backup-job-requirement requirement) + (append '(user-processes file-systems) requirement)) + +(define (restic-backup-job-modules) + `((shepherd service timer))) + (define (restic-backup-job->shepherd-service config) (let ((schedule (restic-backup-job-schedule config)) (name (restic-backup-job-name config)) + (files (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)) (wait-for-termination? (restic-backup-job-wait-for-termination? config)) - (log-file (restic-job-log-file config)) - (requirement (restic-backup-job-requirement config))) + (log-file (restic-backup-job-log-file config)) + (requirement + (restic-backup-job-requirement + (restic-backup-job-requirement config)))) (shepherd-service (provision `(,(string->symbol name))) - (requirement - `(user-processes file-systems ,@requirement)) + (requirement requirement) (documentation - "Run @code{restic} backed backups on a regular basis.") - (modules '((shepherd service timer))) + "Run restic backed backups on a regular basis.") + (modules (restic-backup-job-modules)) (start #~(make-timer-constructor (if (string? #$schedule) (cron-string->calendar-event #$schedule) #$schedule) (command - (list - ;; We go through bash, instead of executing - ;; restic-guix directly, because the login shell - ;; gives us the correct user environment that some - ;; backends require, such as rclone. - (string-append #+bash-minimal "/bin/bash") - "-l" "-c" - (string-append "restic-guix backup " #$name)) + #$(restic-backup-job-command config) #:user #$user #:group #$group #:environment-variables @@ -255,49 +252,16 @@ (define (restic-backup-job->shepherd-service config) max-duration))) (stop #~(make-timer-destructor)) - (actions (list shepherd-trigger-action))))) - -(define (restic-guix-wrapper-package jobs) - (package - (name "restic-backup-service-wrapper") - (version "0.0.0") - (source (restic-guix jobs)) - (build-system copy-build-system) - (arguments - (list #:install-plan #~'(("./" "/bin")))) - (home-page "https://restic.net") - (synopsis - "Easily interact from the CLI with Guix configured backups") - (description - "This package provides a simple wrapper around @code{restic}, handled -by the @code{restic-backup-service-type}. It allows for easily interacting -with Guix configured backup jobs, for example for manually triggering a backup -without waiting for the scheduled job to run.") - (license license:gpl3+))) - -(define restic-backup-service-profile - (lambda (config) - (define jobs (restic-backup-configuration-jobs config)) - (if (> (length jobs) 0) - (list - (restic-guix-wrapper-package jobs)) - '()))) - -(define (restic-backup-activation config) - #~(for-each - (lambda (log-file) - (mkdir-p (dirname log-file))) - (list #$@(map restic-job-log-file - (restic-backup-configuration-jobs config))))) + (actions (list (shepherd-action + (name 'trigger) + (documentation "Manually trigger a backup, +without waiting for the scheduled time.") + (procedure #~trigger-timer))))))) (define restic-backup-service-type (service-type (name 'restic-backup) (extensions (list - (service-extension activation-service-type - restic-backup-activation) - (service-extension profile-service-type - restic-backup-service-profile) (service-extension shepherd-root-service-type (lambda (config) (map restic-backup-job->shepherd-service base-commit: 1710c0941db517453ac2b88c0e854e8348172603 -- 2.49.0 From unknown Tue Jun 17 22:30:02 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: paul Subject: bug#72803: closed () Message-ID: References: <5A6C7B2A-2078-4375-9AB8-B458FF6DD3FE@autistici.org> X-Gnu-PR-Message: they-closed 72803 X-Gnu-PR-Package: guix-patches Reply-To: 72803@debbugs.gnu.org Date: Mon, 19 May 2025 16:56:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1747673762-8397-1" This is a multi-part message in MIME format... ------------=_1747673762-8397-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #72803: Add restic commands to the restic-guix package which was filed against the guix-patches package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 72803@debbugs.gnu.org. --=20 72803: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D72803 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1747673762-8397-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 72803-done) by debbugs.gnu.org; 19 May 2025 16:55:46 +0000 Received: from localhost ([127.0.0.1]:43453 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uH3mE-0002AP-4S for submit@debbugs.gnu.org; Mon, 19 May 2025 12:55:46 -0400 Received: from latitanza.investici.org ([2001:888:2000:56::19]:36609) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uH3mA-00029x-1D for 72803-done@debbugs.gnu.org; Mon, 19 May 2025 12:55:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1747673740; bh=LeZWX1Yeg2iR9p4MPfhdZpomA2SPd3B+9WonCzaOuag=; h=Date:From:To:Subject:From; b=qpEfv9pKF5Fy99vd05F/qs3Nsd+lFtBlJJHw51u+otnne49DvtsyDdf33o1D+zIDK YM5DLf1MbTytMovQlar+w7hvf9QHBVBqoGUmZWVx+qm+m5GQz6Qumu8vueJEXJQoTG R71kcfQEU1KVv8LtxGQyXuEQe9PKRJMDKlnuFPag= Received: from mx3.investici.org (unknown [127.0.0.1]) by latitanza.investici.org (Postfix) with ESMTP id 4b1P2N031kzGpr7 for <72803-done@debbugs.gnu.org>; Mon, 19 May 2025 16:55:40 +0000 (UTC) Received: from [82.94.249.234] (mx3.investici.org [82.94.249.234]) (Authenticated sender: goodoldpaul@autistici.org) by localhost (Postfix) with ESMTPSA id 4b1P2M5RhCzGpr6 for <72803-done@debbugs.gnu.org>; Mon, 19 May 2025 16:55:39 +0000 (UTC) Date: Mon, 19 May 2025 18:55:38 +0200 From: paul To: 72803-done@debbugs.gnu.org Subject: User-Agent: Thunderbird for Android Message-ID: <5A6C7B2A-2078-4375-9AB8-B458FF6DD3FE@autistici.org> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary=----6EI4LYIV9G2ATIFETTRX29NCXXE1V7 Content-Transfer-Encoding: 7bit X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Closing this as there seems to be no consensus on how to proceed. I guess we can figure it out in a later patch. Thank you for your help, cheers giacomo Content analysis details: (1.3 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.0 HTML_MESSAGE BODY: HTML included in message -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [2001:888:2000:56:0:0:0:19 listed in] [list.dnswl.org] 2.0 BLANK_SUBJECT Subject is present but empty X-Debbugs-Envelope-To: 72803-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.3 (/) ------6EI4LYIV9G2ATIFETTRX29NCXXE1V7 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Closing this as there seems to be no consensus on how to proceed=2E I guess= we can figure it out in a later patch=2E Thank you for your help, cheers giacomo ------6EI4LYIV9G2ATIFETTRX29NCXXE1V7 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Closing this as there seems to= be no consensus on how to proceed=2E I guess we can figure it out in a lat= er patch=2E

Thank you for your help,

cheers
giacomo
<= /body> ------6EI4LYIV9G2ATIFETTRX29NCXXE1V7-- ------------=_1747673762-8397-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit 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 ) id 1siDiy-00071A-KH for submit@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 ) id 1siDiv-000710-Lg for submit@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 ) id 1siDi7-0008Iw-FW for guix-patches@gnu.org; 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 ) id 1siDi3-0006Ja-GH for guix-patches@gnu.org; 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 ; 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@autistici.org) by localhost (Postfix) with ESMTPSA id 4WsFg33xvzz112c for ; Sun, 25 Aug 2024 13:54:55 +0000 (UTC) Content-Type: multipart/alternative; boundary="------------9Llavbym5vDHYS1kfkBlgJnK" Message-ID: 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 To: guix-patches@gnu.org Content-Language: en-US From: paul Subject: Add restic commands to the restic-guix package Received-SPF: pass client-ip=2a11:7980:1::2:0; envelope-from=goodoldpaul@autistici.org; 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-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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

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-- ------------=_1747673762-8397-1--