diff options
author | lassulus <lass@aidsballs.de> | 2016-04-20 13:59:22 +0200 |
---|---|---|
committer | lassulus <lass@aidsballs.de> | 2016-04-20 13:59:22 +0200 |
commit | 18775d670660df408bb8310daa8b507b3b1a3f87 (patch) | |
tree | 38c6b6fdb185a5914b9cedff006587aa1b59edbe /lass/3modules | |
parent | b8aee5d8f5c325f7b3b01201aadbe048aa2e5bda (diff) |
l 3: add mysql-backup
Diffstat (limited to 'lass/3modules')
-rw-r--r-- | lass/3modules/default.nix | 4 | ||||
-rw-r--r-- | lass/3modules/mysql-backup.nix | 86 |
2 files changed, 88 insertions, 2 deletions
diff --git a/lass/3modules/default.nix b/lass/3modules/default.nix index f891498c2..71e39d874 100644 --- a/lass/3modules/default.nix +++ b/lass/3modules/default.nix @@ -1,11 +1,11 @@ _: { imports = [ - ./xresources.nix ./folderPerms.nix + ./mysql-backup.nix ./per-user.nix ./urxvtd.nix - ./xresources.nix ./wordpress_nginx.nix + ./xresources.nix ]; } diff --git a/lass/3modules/mysql-backup.nix b/lass/3modules/mysql-backup.nix new file mode 100644 index 000000000..d2ae67171 --- /dev/null +++ b/lass/3modules/mysql-backup.nix @@ -0,0 +1,86 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.lass.mysqlBackup; + + out = { + options.lass.mysqlBackup = api; + config = mkIf cfg.enable imp; + }; + + api = { + enable = mkEnableOption "mysqlBackup"; + config = mkOption { + type = with types; attrsOf (submodule ({ config, ... }: { + options = { + name = mkOption { + type = types.str; + default = config._module.args.name; + }; + startAt = mkOption { + type = with types; nullOr str; # TODO systemd.time(7)'s calendar event + default = "*-*-* 01:15:00"; + }; + user = mkOption { + type = str; + default = "root"; + }; + password = mkOption { + type = nullOr str; + default = null; + description = '' + path to a file containing the mysqlPassword for the specified user. + ''; + }; + databases = mkOption { + type = listOf str; + default = []; + }; + location = mkOption { + type = str; + default = "/bku/sql_dumps"; + }; + }; + })); + description = "configuration for mysqlBackup"; + }; + }; + + imp = { + + #systemd.timers = + # mapAttrs (_: plan: { + # wantedBy = [ "timers.target" ]; + # timerConfig = plan.timerConfig; + #}) cfg.config; + + systemd.services = + mapAttrs' (_: plan: nameValuePair "mysqlBackup-${plan.name}" { + path = with pkgs; [ + mysql + gzip + ]; + serviceConfig = rec { + ExecStart = start plan; + SyslogIdentifier = ExecStart.name; + Type = "oneshot"; + User = plan.user; + }; + startAt = plan.startAt; + }) cfg.config; + }; + + + start = plan: let + backupScript = plan: db: + "mysqldump -u ${plan.user} ${optionalString (plan.password != null) "-p$(cat ${plan.password})"} ${db} | gzip -c > ${plan.location}/${db}.gz"; + + in pkgs.pkgs.writeDash "mysqlBackup.${plan.name}" '' + ${concatMapStringsSep "\n" (backupScript plan) plan.databases} + ''; + + +in out |