unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Richard Sent <richard@freakingpenguin.com>
To: 71639@debbugs.gnu.org
Cc: ludo@gnu.org, "Richard Sent" <richard@freakingpenguin.com>,
	goodoldpaul@autistici.org,
	"Florian Pelz" <pelzflorian@pelzflorian.de>,
	"Ludovic Courtès" <ludo@gnu.org>,
	"Matthew Trzcinski" <matt@excalamus.com>,
	"Maxim Cournoyer" <maxim.cournoyer@gmail.com>
Subject: [bug#71639] [PATCH WIP 1/5] services: backup: Support bootstrapping an initial restic backup
Date: Tue, 18 Jun 2024 18:08:48 -0400	[thread overview]
Message-ID: <88ce7267a59dfb3d80bd790e99b00a731e56835f.1718747513.git.richard@freakingpenguin.com> (raw)
In-Reply-To: <cover.1718747513.git.richard@freakingpenguin.com>

* gnu/services/backup.scm: (restic-backup-job): Add init? field.
(restic-backup-job-program): Initialize repository if init? is set and
repository does not already exist.
* doc/guix.texi (Miscellaneous Services): Document it.

Change-Id: I71d0cbaac646b9d160e662b69286f229b9a9f64d
---
 doc/guix.texi           |  4 ++++
 gnu/services/backup.scm | 20 ++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/doc/guix.texi b/doc/guix.texi
index 0102fd0fad..63c9cbd1a7 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -41353,6 +41353,10 @@ Miscellaneous Services
 The list of files or directories to be backed up.  It must be a list of
 values that can be lowered to strings.
 
+@item @code{init?} (default: @code{#f}) (type: boolean)
+Whether restic-backup-service should check and (if it does not exist)
+initialize the repository before running the backup.
+
 @item @code{verbose?} (default: @code{#f}) (type: boolean)
 Whether to enable verbose output for the current backup job.
 
diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm
index 555e9fc959..eeef11eae7 100644
--- a/gnu/services/backup.scm
+++ b/gnu/services/backup.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2024 Giacomo Leidi <goodoldpaul@autistici.org>
+;;; Copyright © 2024 Richard Sent <richard@freakingpenguin.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -38,6 +39,7 @@ (define-module (gnu services backup)
             restic-backup-job-password-file
             restic-backup-job-schedule
             restic-backup-job-files
+            restic-backup-job-init?
             restic-backup-job-verbose?
             restic-backup-job-extra-flags
 
@@ -94,6 +96,9 @@ (define-configuration/no-serialization restic-backup-job
   (verbose?
    (boolean #f)
    "Whether to enable verbose output for the current backup job.")
+  (init?
+   (boolean #f)
+   "Whether to attempt to initialize a new repository for automated bootstrap purposes.")
   (extra-flags
    (list-of-lowerables '())
    "A list of values that are lowered to strings.  These will be passed as
@@ -118,6 +123,8 @@ (define (restic-backup-job-program config)
          (restic-backup-job-files config))
         (extra-flags
          (restic-backup-job-extra-flags config))
+        (init?
+         (restic-backup-job-init? config))
         (verbose
          (if (restic-backup-job-verbose? config)
              '("--verbose")
@@ -130,6 +137,19 @@ (define (restic-backup-job-program config)
          (setenv "RESTIC_PASSWORD"
                  (with-input-from-file #$password-file read-line))
 
+         (when #$init?
+           ;; Check if the repository exists. See
+           ;; https://github.com/restic/restic/issues/1690 and
+           ;; https://github.com/NixOS/nixpkgs/pull/307962.
+           ;;
+           ;; XXX: restic returns values other than 1 on failure. Use
+           ;; unless EXIT_SUCCESS instead of when EXIT_FAILURE.
+           (unless (equal? EXIT_SUCCESS (system* #$restic "cat" "config"
+                                               "-r" #$repository))
+             ;; Initialize it.
+             (unless (equal? EXIT_SUCCESS (system* #$restic "init"
+                                                 "-r" #$repository))
+               (error "Failed to initialize restic repository: " #$repository))))
          (execlp #$restic #$restic #$@verbose
                  "-r" #$repository
                  #$@extra-flags
-- 
2.45.1





  reply	other threads:[~2024-06-18 22:10 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-18 22:06 [bug#71639] [PATCH WIP 0/5] Improve on restic-backup-service Richard Sent
2024-06-18 22:08 ` Richard Sent [this message]
2024-06-18 22:08 ` [bug#71639] [PATCH WIP 2/5] services: backup: Add password-command support to restic-service Richard Sent
2024-06-18 22:08 ` [bug#71639] [PATCH WIP 3/5] services: backup: Add extra-packages field to restic-backup-job Richard Sent
2024-06-18 22:08 ` [bug#71639] [PATCH WIP 4/5] services: backup: Move restic package to restic-configuration Richard Sent
2024-06-18 22:08 ` [bug#71639] [PATCH WIP 5/5] tests: Add restic system test Richard Sent
  -- strict thread matches above, loose matches on Subject: below --
2024-06-20  3:44 [bug#71660] [PATCH v2 0/5] Improve on restic-backup-service Richard Sent
2024-06-20  3:44 ` [bug#71661] [PATCH v2 1/5] services: backup: Support bootstrapping an initial restic backup Richard Sent
2024-06-20  3:44 ` [bug#71662] [PATCH v2 2/5] services: backup: Add password-command support to restic-service Richard Sent
2024-06-20  3:44 ` [bug#71663] [PATCH v2 3/5] services: backup: Add extra-packages field to restic-backup-job Richard Sent
2024-06-20  3:44 ` [bug#71639] [PATCH v2 4/5] services: backup: Move restic package to restic-configuration Richard Sent
2024-06-20  3:44 ` [bug#71665] [PATCH v2 5/5] tests: Add restic system test Richard Sent
2024-06-24 22:49   ` [bug#71639] [PATCHv2 0/5] Improve on restic-backup-service paul via Guix-patches via
2024-06-27  3:56     ` Richard Sent

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=88ce7267a59dfb3d80bd790e99b00a731e56835f.1718747513.git.richard@freakingpenguin.com \
    --to=richard@freakingpenguin.com \
    --cc=71639@debbugs.gnu.org \
    --cc=goodoldpaul@autistici.org \
    --cc=ludo@gnu.org \
    --cc=matt@excalamus.com \
    --cc=maxim.cournoyer@gmail.com \
    --cc=pelzflorian@pelzflorian.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).