backups: add option postgresqlDatabases
This simplifies defining postgresql backups. This change is covered by tests.py.
This commit is contained in:
parent
faa7831708
commit
0d2db4e79f
@ -18,17 +18,22 @@ let
|
|||||||
${config.services.nbxplorer.dataDir}
|
${config.services.nbxplorer.dataDir}
|
||||||
${config.services.btcpayserver.dataDir}
|
${config.services.btcpayserver.dataDir}
|
||||||
${config.services.joinmarket.dataDir}
|
${config.services.joinmarket.dataDir}
|
||||||
${config.services.postgresqlBackup.location}/btcpaydb.sql.gz
|
|
||||||
${optionalString config.nix-bitcoin.generateSecrets "${config.nix-bitcoin.secretsDir}"}
|
${optionalString config.nix-bitcoin.generateSecrets "${config.nix-bitcoin.secretsDir}"}
|
||||||
/var/lib/tor
|
/var/lib/tor
|
||||||
/var/lib/nixos
|
/var/lib/nixos
|
||||||
|
|
||||||
|
${builtins.concatStringsSep "\n" postgresqlBackupPaths}
|
||||||
|
|
||||||
# Extra files
|
# Extra files
|
||||||
${cfg.extraFiles}
|
${cfg.extraFiles}
|
||||||
|
|
||||||
# Exclude all unspecified files and directories
|
# Exclude all unspecified files and directories
|
||||||
- /
|
- /
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
postgresqlBackupDir = config.services.postgresqlBackup.location;
|
||||||
|
postgresqlBackupPaths = map (db: "${postgresqlBackupDir}/${db}.sql.gz") cfg.postgresqlDatabases;
|
||||||
|
postgresqlBackupServices = map (db: "postgresqlBackup-${db}.service") cfg.postgresqlDatabases;
|
||||||
in {
|
in {
|
||||||
options.services.backups = {
|
options.services.backups = {
|
||||||
enable = mkEnableOption "Backups service";
|
enable = mkEnableOption "Backups service";
|
||||||
@ -53,6 +58,11 @@ in {
|
|||||||
Run backup with the given frequency. If null, do not run automatically.
|
Run backup with the given frequency. If null, do not run automatically.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
postgresqlDatabases = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
default = [];
|
||||||
|
description = "List of database names to backup.";
|
||||||
|
};
|
||||||
extraFiles = mkOption {
|
extraFiles = mkOption {
|
||||||
type = types.lines;
|
type = types.lines;
|
||||||
default = "";
|
default = "";
|
||||||
@ -63,8 +73,7 @@ in {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable (mkMerge [
|
config = mkIf cfg.enable {
|
||||||
{
|
|
||||||
environment.systemPackages = [ pkgs.duplicity ];
|
environment.systemPackages = [ pkgs.duplicity ];
|
||||||
|
|
||||||
services.duplicity = {
|
services.duplicity = {
|
||||||
@ -78,17 +87,18 @@ in {
|
|||||||
secretFile = "${config.nix-bitcoin.secretsDir}/backup-encryption-env";
|
secretFile = "${config.nix-bitcoin.secretsDir}/backup-encryption-env";
|
||||||
};
|
};
|
||||||
|
|
||||||
nix-bitcoin.secrets.backup-encryption-env.user = "root";
|
systemd.services.duplicity = {
|
||||||
}
|
wants = postgresqlBackupServices;
|
||||||
(mkIf config.services.btcpayserver.enable {
|
after = postgresqlBackupServices;
|
||||||
|
};
|
||||||
|
|
||||||
services.postgresqlBackup = {
|
services.postgresqlBackup = {
|
||||||
enable = true;
|
enable = mkIf (cfg.postgresqlDatabases != []) true;
|
||||||
databases = [ "btcpaydb" ];
|
databases = cfg.postgresqlDatabases;
|
||||||
};
|
};
|
||||||
systemd.services.duplicity = rec {
|
|
||||||
wants = [ "postgresqlBackup-btcpaydb.service" ];
|
nix-bitcoin.secrets.backup-encryption-env.user = "root";
|
||||||
after = wants;
|
|
||||||
|
services.backups.postgresqlDatabases = mkIf config.services.btcpayserver.enable [ "btcpaydb" ];
|
||||||
};
|
};
|
||||||
})
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user