backups shenanagians
This commit is contained in:
@@ -107,6 +107,9 @@ in {
|
||||
}
|
||||
];
|
||||
|
||||
# add postgresql database that is automatically created to the backup list
|
||||
services.postgresqlBackup.databases = ["immich"]; # set to all databases defined in esure databases
|
||||
|
||||
# add to backups
|
||||
homelab.baks = {
|
||||
${service} = {paths = [cfg.data_dir "/var/lib/redis-immich" "/var/backup/postgresql/immich.sql.zstd"];};
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
servers = {
|
||||
velocity = {
|
||||
data_dir = "/var/lib/gameservers/minecraft_recpro/velocity";
|
||||
db_dumb_dir = "/var/backup/mysql/${service}_db.zst";
|
||||
db_dump_dir = "/var/backup/mysql/${service}_db.zst";
|
||||
ram = "2G";
|
||||
};
|
||||
smp = {
|
||||
@@ -138,7 +138,12 @@ in {
|
||||
services.borgbackup.jobs.${service} = {
|
||||
archiveBaseName = service;
|
||||
repo = cfg.backup_repo;
|
||||
paths = lib.flatten (lib.attrValues (lib.mapAttrs (_: srv: [srv.data_dir]) servers));
|
||||
#paths = lib.flatten (lib.attrValues (lib.mapAttrs (_: srv: [srv.data_dir]) servers));
|
||||
paths = lib.flatten (
|
||||
lib.attrValues (
|
||||
lib.mapAttrs (_: srv: [srv.data_dir] ++ (if builtins.hasAttr "db_dump_dir" srv then [srv.db_dump_dir] else [])) servers
|
||||
)
|
||||
);
|
||||
compression = "auto,zstd";
|
||||
startAt = "*-*-* *:00:00";
|
||||
group = "archives";
|
||||
|
||||
@@ -5,17 +5,7 @@
|
||||
...
|
||||
}:
|
||||
/*
|
||||
this module enables a backup script made with borg!
|
||||
to use import & set the options below
|
||||
to declare a backup add the following code
|
||||
to a module and it will backup all listed paths
|
||||
in a borg archive to the specified repo
|
||||
|
||||
| <3yy> |
|
||||
V V
|
||||
system.backups.baks = {
|
||||
${service} = { paths = [ cfg.data_dir ]; };
|
||||
};
|
||||
this module
|
||||
*/
|
||||
let
|
||||
cfg = config.system.backups;
|
||||
@@ -34,59 +24,33 @@ in {
|
||||
default = {};
|
||||
description = "backup jobs for game servers, nested attribute sets should be <bak_name> = paths [<list_of_paths>]";
|
||||
};
|
||||
repo = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
default = "/holocron/archives/devices/snowbelle";
|
||||
description = "borg repository path";
|
||||
};
|
||||
gameserver_repo = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
default = "/holocron/archives/gameservers/borg";
|
||||
description = "borg repository path";
|
||||
};
|
||||
passwd_file = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
default = sec."borg_passwd".path;
|
||||
description = "borg repository passphrase file";
|
||||
};
|
||||
mode = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "split"; # "all"
|
||||
description = "choice between creating one archive of all paths or one archive per service";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf (cfg.enable && cfg.baks != {}) {
|
||||
|
||||
# db backups
|
||||
# mysql backups currently minecraft_recpro is the only thing using this
|
||||
services.mysqlBackup = lib.mkIf config.services.mysql.enable {
|
||||
# mc servers use this
|
||||
enable = true;
|
||||
location = "/var/backup/mysql";
|
||||
user = "root";
|
||||
calendar = "*-*-* *:59:50";
|
||||
calendar = "*-*-* *:59:45"; # goes fast, included in back up with server dirs at **:00
|
||||
compressionAlg = "zstd";
|
||||
databases = config.services.mysql.ensureDatabases; # set to all databases defined in esure databases
|
||||
};
|
||||
# postgresql backups currently immich is the only user
|
||||
services.postgresqlBackup = lib.mkIf config.services.postgresql.enable {
|
||||
# immich uses this
|
||||
enable = true;
|
||||
location = "/var/backup/postgresql";
|
||||
compression = "zstd"; # optional: "xz", "zstd", "none"
|
||||
startAt = "03:59";
|
||||
databases = ["immich"]; # set to all databases defined in esure databases
|
||||
startAt = "03:59"; # the dump is included in a backup taken at 4:00
|
||||
# currently setting this in the immich file
|
||||
#databases = ["immich"]; # set to all databases defined in esure databases
|
||||
#databases = config.services.postgresql.ensureDatabases; # set to all databases defined in esure databases
|
||||
};
|
||||
|
||||
# helpful
|
||||
# helpful and for scripts
|
||||
environment.systemPackages = with pkgs; [borgbackup tree];
|
||||
|
||||
# declare secret for repo password
|
||||
sops.secrets = {
|
||||
"borg_passwd" = {
|
||||
owner = "root";
|
||||
group = "root";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user