From cd98acd3a721e48b82f277af5a00235cb77dc4a0 Mon Sep 17 00:00:00 2001 From: Aristid Breitkreuz Date: Sun, 6 Oct 2013 22:22:25 +0200 Subject: [PATCH 1/4] add simple rsnapshot module --- modules/module-list.nix | 1 + modules/services/backup/rsnapshot.nix | 56 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 modules/services/backup/rsnapshot.nix diff --git a/modules/module-list.nix b/modules/module-list.nix index 76f5e0a46574..c186968f0590 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -75,6 +75,7 @@ ./services/backup/mysql-backup.nix ./services/backup/postgresql-backup.nix ./services/backup/sitecopy-backup.nix + ./services/backup/rsnapshot.nix ./services/databases/4store-endpoint.nix ./services/databases/4store.nix ./services/databases/firebird.nix diff --git a/modules/services/backup/rsnapshot.nix b/modules/services/backup/rsnapshot.nix new file mode 100644 index 000000000000..678296a3e3d2 --- /dev/null +++ b/modules/services/backup/rsnapshot.nix @@ -0,0 +1,56 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +let cfg = config.services.rsnapshot; +in +{ + options = { + services.rsnapshot = { + enable = mkEnableOption "rsnapshot backups"; + + configuration = mkOption { + default = ""; + example = '' + retain hourly 24 + retain daily 365 + backup /home/ localhost/ + ''; + type = types.lines; + description = '' + rsnapshot configuration option in addition to the defaults from rsnapshot and this module. + ''; + }; + + cronIntervals = mkOption { + default = {}; + example = { "hourly" = "0 * * * *"; "daily" = "50 21 * * *"; }; + type = types.attrsOf types.string; + description = '' + Periodicity at which intervals should be run by cron. + Note that the intervals also have to exist in configuration + as retain options. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + environment.systemPackages = [ pkgs.rsnapshot ]; + + services.cron.systemCronJobs = + mapAttrsToList (interval: time: "${time} root ${pkgs.rsnapshot}/bin/rsnapshot ${interval}") cfg.cronIntervals; + + environment.etc."rsnapshot.conf".source = with pkgs; writeText "gen-rsnapshot.conf" ('' + config_version 1.2 + cmd_cp ${coreutils}/bin/cp + cmd_rsync ${rsync}/bin/rsync + cmd_ssh ${openssh}/bin/ssh + cmd_logger ${inetutils}/bin/logger + cmd_du ${coreutils}/bin/du + cmd_rsnapshot_diff ${rsnapshot}/bin/rsnapshot-diff + lockfile /run/rsnapshot.pid + + '' + cfg.configuration); + }; +} From fa1f5e5b7507533476b7cb4e6fc0013c8cecbd23 Mon Sep 17 00:00:00 2001 From: Aristid Breitkreuz Date: Sun, 6 Oct 2013 23:02:41 +0200 Subject: [PATCH 2/4] implement bjornfors comments --- modules/services/backup/rsnapshot.nix | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/modules/services/backup/rsnapshot.nix b/modules/services/backup/rsnapshot.nix index 678296a3e3d2..c4c67ebe35a6 100644 --- a/modules/services/backup/rsnapshot.nix +++ b/modules/services/backup/rsnapshot.nix @@ -9,16 +9,23 @@ in services.rsnapshot = { enable = mkEnableOption "rsnapshot backups"; - configuration = mkOption { + extraConfiguration = mkOption { default = ""; example = '' - retain hourly 24 - retain daily 365 - backup /home/ localhost/ + retains hourly 24 + retain daily 365 + backup /home/ localhost/ ''; type = types.lines; description = '' - rsnapshot configuration option in addition to the defaults from rsnapshot and this module. + rsnapshot configuration option in addition to the defaults from + rsnapshot and this module. + + Note that tabs are required to separate option arguments, and + directory names require trailing slashes. + + The "extra" in the option name might be a little misleading right + now, as it is required to get a functional configuration. ''; }; @@ -27,9 +34,9 @@ in example = { "hourly" = "0 * * * *"; "daily" = "50 21 * * *"; }; type = types.attrsOf types.string; description = '' - Periodicity at which intervals should be run by cron. - Note that the intervals also have to exist in configuration - as retain options. + Periodicity at which intervals should be run by cron. + Note that the intervals also have to exist in configuration + as retain options. ''; }; }; @@ -51,6 +58,6 @@ in cmd_rsnapshot_diff ${rsnapshot}/bin/rsnapshot-diff lockfile /run/rsnapshot.pid - '' + cfg.configuration); + '' + cfg.extraConfiguration); }; } From 2700a13596178dd6af8e4f26afafce78f3b9f2d9 Mon Sep 17 00:00:00 2001 From: Aristid Breitkreuz Date: Sun, 6 Oct 2013 23:05:30 +0200 Subject: [PATCH 3/4] rsnapshot: extraConfiguration -> extraConfig --- modules/services/backup/rsnapshot.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/services/backup/rsnapshot.nix b/modules/services/backup/rsnapshot.nix index c4c67ebe35a6..e0ce97257a50 100644 --- a/modules/services/backup/rsnapshot.nix +++ b/modules/services/backup/rsnapshot.nix @@ -9,7 +9,7 @@ in services.rsnapshot = { enable = mkEnableOption "rsnapshot backups"; - extraConfiguration = mkOption { + extraConfig = mkOption { default = ""; example = '' retains hourly 24 @@ -58,6 +58,6 @@ in cmd_rsnapshot_diff ${rsnapshot}/bin/rsnapshot-diff lockfile /run/rsnapshot.pid - '' + cfg.extraConfiguration); + '' + cfg.extraConfig); }; } From 5e07af062d55dbeb86a29696488dfbb58a8c7344 Mon Sep 17 00:00:00 2001 From: Aristid Breitkreuz Date: Sun, 6 Oct 2013 23:36:07 +0200 Subject: [PATCH 4/4] rsnapshot: do not use /etc/rsnapshot.conf --- modules/services/backup/rsnapshot.nix | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/modules/services/backup/rsnapshot.nix b/modules/services/backup/rsnapshot.nix index e0ce97257a50..178ba3ec7207 100644 --- a/modules/services/backup/rsnapshot.nix +++ b/modules/services/backup/rsnapshot.nix @@ -42,22 +42,24 @@ in }; }; - config = mkIf cfg.enable { - environment.systemPackages = [ pkgs.rsnapshot ]; - - services.cron.systemCronJobs = - mapAttrsToList (interval: time: "${time} root ${pkgs.rsnapshot}/bin/rsnapshot ${interval}") cfg.cronIntervals; - - environment.etc."rsnapshot.conf".source = with pkgs; writeText "gen-rsnapshot.conf" ('' + config = mkIf cfg.enable (let + myRsnapshot = pkgs.rsnapshot.override { configFile = rsnapshotCfg; }; + rsnapshotCfg = with pkgs; writeText "gen-rsnapshot.conf" ('' config_version 1.2 cmd_cp ${coreutils}/bin/cp cmd_rsync ${rsync}/bin/rsync cmd_ssh ${openssh}/bin/ssh cmd_logger ${inetutils}/bin/logger cmd_du ${coreutils}/bin/du - cmd_rsnapshot_diff ${rsnapshot}/bin/rsnapshot-diff lockfile /run/rsnapshot.pid - '' + cfg.extraConfig); - }; + ${cfg.extraConfig} + ''); + in { + environment.systemPackages = [ myRsnapshot ]; + + services.cron.systemCronJobs = + mapAttrsToList (interval: time: "${time} root ${myRsnapshot}/bin/rsnapshot ${interval}") cfg.cronIntervals; + } + ); }