summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Girol <symphorien@users.noreply.github.com>2024-05-13 23:53:18 +0200
committerGitHub <noreply@github.com>2024-05-13 23:53:18 +0200
commit673f00ad7b85eae7fdf6f089684c57dcfb013048 (patch)
tree77565d7d867d0f458dce9da7c53a8bd8ac6a5947
parentdcdbcb67ae1b69f700c22b98b85583a68f773587 (diff)
parent00346bff2ba3d9952727fa029890ee649436482d (diff)
Merge pull request #310199 from symphorien/borg_ignore_warnings_master
nixos/borgbackup: add an option to ignore warnings
-rw-r--r--nixos/modules/services/backup/borgbackup.nix32
1 files changed, 26 insertions, 6 deletions
diff --git a/nixos/modules/services/backup/borgbackup.nix b/nixos/modules/services/backup/borgbackup.nix
index 570f8931bd9e..04f971008073 100644
--- a/nixos/modules/services/backup/borgbackup.nix
+++ b/nixos/modules/services/backup/borgbackup.nix
@@ -33,13 +33,24 @@ let
}
trap on_exit EXIT
+ borgWrapper () {
+ local result
+ borg "$@" && result=$? || result=$?
+ if [[ -z "${toString cfg.failOnWarnings}" ]] && [[ "$result" == 1 ]]; then
+ echo "ignoring warning return value 1"
+ return 0
+ else
+ return "$result"
+ fi
+ }
+
archiveName="${optionalString (cfg.archiveBaseName != null) (cfg.archiveBaseName + "-")}$(date ${cfg.dateFormat})"
archiveSuffix="${optionalString cfg.appendFailedSuffix ".failed"}"
${cfg.preHook}
'' + optionalString cfg.doInit ''
# Run borg init if the repo doesn't exist yet
- if ! borg list $extraArgs > /dev/null; then
- borg init $extraArgs \
+ if ! borgWrapper list $extraArgs > /dev/null; then
+ borgWrapper init $extraArgs \
--encryption ${cfg.encryption.mode} \
$extraInitArgs
${cfg.postInit}
@@ -48,7 +59,7 @@ let
(
set -o pipefail
${optionalString (cfg.dumpCommand != null) ''${escapeShellArg cfg.dumpCommand} | \''}
- borg create $extraArgs \
+ borgWrapper create $extraArgs \
--compression ${cfg.compression} \
--exclude-from ${mkExcludeFile cfg} \
--patterns-from ${mkPatternsFile cfg} \
@@ -57,16 +68,16 @@ let
${if cfg.paths == null then "-" else escapeShellArgs cfg.paths}
)
'' + optionalString cfg.appendFailedSuffix ''
- borg rename $extraArgs \
+ borgWrapper rename $extraArgs \
"::$archiveName$archiveSuffix" "$archiveName"
'' + ''
${cfg.postCreate}
'' + optionalString (cfg.prune.keep != { }) ''
- borg prune $extraArgs \
+ borgWrapper prune $extraArgs \
${mkKeepArgs cfg} \
${optionalString (cfg.prune.prefix != null) "--glob-archives ${escapeShellArg "${cfg.prune.prefix}*"}"} \
$extraPruneArgs
- borg compact $extraArgs $extraCompactArgs
+ borgWrapper compact $extraArgs $extraCompactArgs
${cfg.postPrune}
'');
@@ -488,6 +499,15 @@ in {
default = true;
};
+ failOnWarnings = mkOption {
+ type = types.bool;
+ description = ''
+ Fail the whole backup job if any borg command returns a warning
+ (exit code 1), for example because a file changed during backup.
+ '';
+ default = true;
+ };
+
doInit = mkOption {
type = types.bool;
description = ''