From 01938a297abdb89c79d7d03247a68e93937d47f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Thu, 24 Oct 2019 00:35:49 +0200 Subject: Rename backup module to duply_backup --- modules/backup/default.nix | 104 ----------------------------------- modules/default.nix | 2 +- modules/duply_backup/default.nix | 104 +++++++++++++++++++++++++++++++++++ modules/webapps/webstats/default.nix | 2 +- 4 files changed, 106 insertions(+), 106 deletions(-) delete mode 100644 modules/backup/default.nix create mode 100644 modules/duply_backup/default.nix (limited to 'modules') diff --git a/modules/backup/default.nix b/modules/backup/default.nix deleted file mode 100644 index be12231e..00000000 --- a/modules/backup/default.nix +++ /dev/null @@ -1,104 +0,0 @@ -{ lib, pkgs, myconfig, config, ... }: - -let - cfg = myconfig.env.backup; - varDir = "/var/lib/duply"; - duplyProfile = profile: prefix: '' - GPG_PW="${cfg.password}" - TARGET="${cfg.remote}${prefix}" - export AWS_ACCESS_KEY_ID="${cfg.accessKeyId}" - export AWS_SECRET_ACCESS_KEY="${cfg.secretAccessKey}" - SOURCE="${profile.rootDir}" - FILENAME=".duplicity-ignore" - DUPL_PARAMS="$DUPL_PARAMS --exclude-if-present '$FILENAME'" - VERBOSITY=4 - ARCH_DIR="${varDir}/caches" - - # Do a full backup after 1 month - MAX_FULLBKP_AGE=1M - DUPL_PARAMS="$DUPL_PARAMS --full-if-older-than $MAX_FULLBKP_AGE " - # Backups older than 2months are deleted - MAX_AGE=2M - # Keep 2 full backups - MAX_FULL_BACKUPS=2 - MAX_FULLS_WITH_INCRS=2 - ''; - action = "bkp_purge_purgeFull_purgeIncr"; -in -{ - options = { - services.backup.enable = lib.mkOption { - type = lib.types.bool; - default = false; - description = '' - Whether to enable remote backups. - ''; - }; - services.backup.profiles = lib.mkOption { - type = lib.types.attrsOf (lib.types.submodule { - options = { - rootDir = lib.mkOption { - type = lib.types.path; - description = '' - Path to backup - ''; - }; - excludeFile = lib.mkOption { - type = lib.types.lines; - default = ""; - description = '' - Content to put in exclude file - ''; - }; - }; - }); - }; - }; - - config = lib.mkIf config.services.backup.enable { - system.activationScripts.backup = '' - install -m 0700 -o root -g root -d ${varDir} ${varDir}/caches - ''; - secrets.keys = lib.flatten (lib.mapAttrsToList (k: v: [ - { - permissions = "0400"; - dest = "backup/${k}/conf"; - text = duplyProfile v "${k}/"; - } - { - permissions = "0400"; - dest = "backup/${k}/exclude"; - text = v.excludeFile; - } - ]) config.services.backup.profiles); - - services.cron = { - enable = true; - systemCronJobs = let - backups = pkgs.writeScript "backups" '' - #!${pkgs.stdenv.shell} - - ${builtins.concatStringsSep "\n" (lib.mapAttrsToList (k: v: - '' - touch ${varDir}/${k}.log - ${pkgs.duply}/bin/duply ${config.secrets.location}/backup/${k}/ ${action} --force >> ${varDir}/${k}.log - '' - ) config.services.backup.profiles)} - ''; - in - [ - "0 2 * * * root ${backups}" - ]; - - }; - - security.pki.certificates = let - cert = pkgs.fetchurl { - url = "http://downloads.e.eriomem.net/eriomemca.pem"; - sha256 = "1ixx4c6j3m26j8dp9a3dkvxc80v1nr5aqgmawwgs06bskasqkvvh"; - }; - in [ - (builtins.readFile cert) - ]; - }; -} diff --git a/modules/default.nix b/modules/default.nix index 05f2bfe0..18bee9af 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -13,7 +13,7 @@ opendmarc = ./opendmarc.nix; openarc = ./openarc.nix; - backup = ./backup; + duplyBackup = ./duply_backup; naemon = ./naemon; php-application = ./websites/php-application.nix; diff --git a/modules/duply_backup/default.nix b/modules/duply_backup/default.nix new file mode 100644 index 00000000..32fa9414 --- /dev/null +++ b/modules/duply_backup/default.nix @@ -0,0 +1,104 @@ +{ lib, pkgs, myconfig, config, ... }: + +let + cfg = myconfig.env.backup; + varDir = "/var/lib/duply"; + duplyProfile = profile: prefix: '' + GPG_PW="${cfg.password}" + TARGET="${cfg.remote}${prefix}" + export AWS_ACCESS_KEY_ID="${cfg.accessKeyId}" + export AWS_SECRET_ACCESS_KEY="${cfg.secretAccessKey}" + SOURCE="${profile.rootDir}" + FILENAME=".duplicity-ignore" + DUPL_PARAMS="$DUPL_PARAMS --exclude-if-present '$FILENAME'" + VERBOSITY=4 + ARCH_DIR="${varDir}/caches" + + # Do a full backup after 1 month + MAX_FULLBKP_AGE=1M + DUPL_PARAMS="$DUPL_PARAMS --full-if-older-than $MAX_FULLBKP_AGE " + # Backups older than 2months are deleted + MAX_AGE=2M + # Keep 2 full backups + MAX_FULL_BACKUPS=2 + MAX_FULLS_WITH_INCRS=2 + ''; + action = "bkp_purge_purgeFull_purgeIncr"; +in +{ + options = { + services.duplyBackup.enable = lib.mkOption { + type = lib.types.bool; + default = false; + description = '' + Whether to enable remote backups. + ''; + }; + services.duplyBackup.profiles = lib.mkOption { + type = lib.types.attrsOf (lib.types.submodule { + options = { + rootDir = lib.mkOption { + type = lib.types.path; + description = '' + Path to backup + ''; + }; + excludeFile = lib.mkOption { + type = lib.types.lines; + default = ""; + description = '' + Content to put in exclude file + ''; + }; + }; + }); + }; + }; + + config = lib.mkIf config.services.duplyBackup.enable { + system.activationScripts.backup = '' + install -m 0700 -o root -g root -d ${varDir} ${varDir}/caches + ''; + secrets.keys = lib.flatten (lib.mapAttrsToList (k: v: [ + { + permissions = "0400"; + dest = "backup/${k}/conf"; + text = duplyProfile v "${k}/"; + } + { + permissions = "0400"; + dest = "backup/${k}/exclude"; + text = v.excludeFile; + } + ]) config.services.duplyBackup.profiles); + + services.cron = { + enable = true; + systemCronJobs = let + backups = pkgs.writeScript "backups" '' + #!${pkgs.stdenv.shell} + + ${builtins.concatStringsSep "\n" (lib.mapAttrsToList (k: v: + '' + touch ${varDir}/${k}.log + ${pkgs.duply}/bin/duply ${config.secrets.location}/backup/${k}/ ${action} --force >> ${varDir}/${k}.log + '' + ) config.services.duplyBackup.profiles)} + ''; + in + [ + "0 2 * * * root ${backups}" + ]; + + }; + + security.pki.certificates = let + cert = pkgs.fetchurl { + url = "http://downloads.e.eriomem.net/eriomemca.pem"; + sha256 = "1ixx4c6j3m26j8dp9a3dkvxc80v1nr5aqgmawwgs06bskasqkvvh"; + }; + in [ + (builtins.readFile cert) + ]; + }; +} diff --git a/modules/webapps/webstats/default.nix b/modules/webapps/webstats/default.nix index 6771f015..e822645c 100644 --- a/modules/webapps/webstats/default.nix +++ b/modules/webapps/webstats/default.nix @@ -37,7 +37,7 @@ in { }; config = lib.mkIf (builtins.length cfg.sites > 0) { - services.backup.profiles.goaccess = { + services.duplyBackup.profiles.goaccess = { rootDir = cfg.dataDir; }; users.users.root.packages = [ -- cgit v1.2.3