From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id YCoHGdkFcmatbQAAqHPOHw:P1 (envelope-from ) for ; Tue, 18 Jun 2024 22:10:33 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id YCoHGdkFcmatbQAAqHPOHw (envelope-from ) for ; Wed, 19 Jun 2024 00:10:33 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=none ("invalid DKIM record") header.d=freakingpenguin.com header.s=x header.b=eV5Ue2Tn; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1718748633; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=mGC2u6AkPdw2TbKu3XSwToUFXRtmupACwqHDC9DtPuE=; b=CYMIhlIZF5jHJEiuQD8VSgEcHFPr3kkp95ezJn80/GVdRtLr4oxZN7Ckg0wPBDs+qLIzPT zxZV66IUmc13zDXT9nsO4is2MMvmq167GwGoGYoG28p9gRmp2yOe6ZsdlQozmBCudf3c/H KhmucaeOdCAwoimlRLtISEXgpJ+rq4gq2nRX1gz2gaLUE+0BZ+WrSRI/NGhzTsay+J6KpN 11Y/hgjwFccDwAH3I6dGFNvnPyutvlLu3w6CQ/xaXz3o0nEB9QP/r+iLVlKQelzhghBMWt +m/6LPr84XPgMvCDywyxrL3JZN8cMHu2vZh+2WIjlJZ2ECe6E650b3UvmJMsWA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1718748633; a=rsa-sha256; cv=none; b=IzqDt21jncR/ZFBJLy9YGUYTn4YZ/FSodJD9jgMCOCXn133TOguyHQeFOpV4snPCI+Iyva GRB42m8VXtxBAFQzOcD4gx2fxk4bxnIfvmAOWcsz8LFzxooOYnYVYd7dv8Afhy0zC2AaCB a2UfX3ZhGmCVYjT8nDeHmuL3lFGtx+lmXrfJjNuCMfkeFf9ExUsGlSUt45OyfD9PAyOPDs ViFD997ZOPJYlFruXHg8UMQG5UOyT6pxqufdOB3TX+b7bvOXMrMIuVdZZDz69ZKC0MSQ29 YPsh1Hoyk14d3DqP8xXV8XdwS85e2mMSRkZN5f5s2IpoMko030/zgFFknLWjhg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none ("invalid DKIM record") header.d=freakingpenguin.com header.s=x header.b=eV5Ue2Tn; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 06897A06F for ; Wed, 19 Jun 2024 00:10:32 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJh1d-0005h9-Eu; Tue, 18 Jun 2024 18:10:01 -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 1sJh1c-0005gt-7U for guix-patches@gnu.org; Tue, 18 Jun 2024 18:10:00 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sJh1b-0003Bj-V9; Tue, 18 Jun 2024 18:09:59 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sJh1e-00034Q-FU; Tue, 18 Jun 2024 18:10:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#71639] [PATCH WIP 1/5] services: backup: Support bootstrapping an initial restic backup Resent-From: Richard Sent 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: Tue, 18 Jun 2024 22:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71639 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 71639@debbugs.gnu.org Cc: ludo@gnu.org, Richard Sent , goodoldpaul@autistici.org, 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 71639-submit@debbugs.gnu.org id=B71639.171874856711656 (code B ref 71639); Tue, 18 Jun 2024 22:10:02 +0000 Received: (at 71639) by debbugs.gnu.org; 18 Jun 2024 22:09:27 +0000 Received: from localhost ([127.0.0.1]:53627 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sJh14-00031t-IH for submit@debbugs.gnu.org; Tue, 18 Jun 2024 18:09:27 -0400 Received: from mail-108-mta227.mxroute.com ([136.175.108.227]:36689) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sJh12-00031l-0F for 71639@debbugs.gnu.org; Tue, 18 Jun 2024 18:09:24 -0400 Received: from filter006.mxroute.com ([136.175.111.3] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta227.mxroute.com (ZoneMTA) with ESMTPSA id 1902d65b3e000017a3.002 for <71639@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Tue, 18 Jun 2024 22:09:18 +0000 X-Zone-Loop: e7f3684c7a8d6b45121dcd13de1489fab24eddf7d436 X-Originating-IP: [136.175.111.3] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freakingpenguin.com; s=x; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=mGC2u6AkPdw2TbKu3XSwToUFXRtmupACwqHDC9DtPuE=; b=eV5Ue2TnPuO+JHRwbrXr/VQmLF ukS/9YfAVuLqWFpn5Ac29ZGLUjVZv2AoZ5WIpc68esYPNme+Hq0I3dypmC4qSrQasl3+QVgStwUfa mE/hzPE1+tFFhXwGUZ7EAMxfHjaekou0CeytVcyV/Xg7fGkxczFFWwZCJlSSd3k5tVeYwoA8fuUeS g5I/9VxP42F+E5R35uUTtLDjR3B+dKS58ldVg4tzLP0T+OimGLbotKO4s7YSGqcVp/C1F6ySULUzE PWVGgLZDxjz+woKI/5/fouusJ6+Ovo+bgbiDiiiluRAef9fwmBrFgfG1AHiaXcYYLsOUkSAgb1BaC 7WU0YWNg==; From: Richard Sent Date: Tue, 18 Jun 2024 18:08:48 -0400 Message-ID: <88ce7267a59dfb3d80bd790e99b00a731e56835f.1718747513.git.richard@freakingpenguin.com> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Authenticated-Id: richard@freakingpenguin.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -0.86 X-Spam-Score: -0.86 X-Migadu-Queue-Id: 06897A06F X-Migadu-Scanner: mx11.migadu.com X-TUID: OPi8OAcL+MM3 * 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 +;;; Copyright © 2024 Richard Sent ;;; ;;; 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