about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/backup/tsm.nix
blob: 3b2bb37491b5eb2ad6bf41a88b81bde50d738e59 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
{ config, lib, ... }:

let

  inherit (lib.attrsets) hasAttr;
  inherit (lib.modules) mkDefault mkIf;
  inherit (lib.options) mkEnableOption mkOption;
  inherit (lib.types) nullOr strMatching;

  options.services.tsmBackup = {
    enable = mkEnableOption ''
      automatic backups with the
      IBM Spectrum Protect (Tivoli Storage Manager, TSM) client.
      This also enables
      <option>programs.tsmClient.enable</option>
    '';
    command = mkOption {
      type = strMatching ".+";
      default = "backup";
      example = "incr";
      description = ''
        The actual command passed to the
        <literal>dsmc</literal> executable to start the backup.
      '';
    };
    servername = mkOption {
      type = strMatching ".+";
      example = "mainTsmServer";
      description = ''
        Create a systemd system service
        <literal>tsm-backup.service</literal> that starts
        a backup based on the given servername's stanza.
        Note that this server's
        <option>passwdDir</option> will default to
        <filename>/var/lib/tsm-backup/password</filename>
        (but may be overridden);
        also, the service will use
        <filename>/var/lib/tsm-backup</filename> as
        <literal>HOME</literal> when calling
        <literal>dsmc</literal>.
      '';
    };
    autoTime = mkOption {
      type = nullOr (strMatching ".+");
      default = null;
      example = "12:00";
      description = ''
        The backup service will be invoked
        automatically at the given date/time,
        which must be in the format described in
        <citerefentry><refentrytitle>systemd.time</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
        The default <literal>null</literal>
        disables automatic backups.
      '';
    };
  };

  cfg = config.services.tsmBackup;
  cfgPrg = config.programs.tsmClient;

  assertions = [
    {
      assertion = hasAttr cfg.servername cfgPrg.servers;
      message = "TSM service servername not found in list of servers";
    }
    {
      assertion = cfgPrg.servers.${cfg.servername}.genPasswd;
      message = "TSM service requires automatic password generation";
    }
  ];

in

{

  inherit options;

  config = mkIf cfg.enable {
    inherit assertions;
    programs.tsmClient.enable = true;
    programs.tsmClient.servers."${cfg.servername}".passwdDir =
      mkDefault "/var/lib/tsm-backup/password";
    systemd.services.tsm-backup = {
      description = "IBM Spectrum Protect (Tivoli Storage Manager) Backup";
      # DSM_LOG needs a trailing slash to have it treated as a directory.
      # `/var/log` would be littered with TSM log files otherwise.
      environment.DSM_LOG = "/var/log/tsm-backup/";
      # TSM needs a HOME dir to store certificates.
      environment.HOME = "/var/lib/tsm-backup";
      # for exit status description see
      # https://www.ibm.com/support/knowledgecenter/en/SSEQVQ_8.1.8/client/c_sched_rtncode.html
      serviceConfig.SuccessExitStatus = "4 8";
      # The `-se` option must come after the command.
      # The `-optfile` option suppresses a `dsm.opt`-not-found warning.
      serviceConfig.ExecStart =
        "${cfgPrg.wrappedPackage}/bin/dsmc ${cfg.command} -se='${cfg.servername}' -optfile=/dev/null";
      serviceConfig.LogsDirectory = "tsm-backup";
      serviceConfig.StateDirectory = "tsm-backup";
      serviceConfig.StateDirectoryMode = "0750";
      startAt = mkIf (cfg.autoTime!=null) cfg.autoTime;
    };
  };

  meta.maintainers = [ lib.maintainers.yarny ];

}