summaryrefslogtreecommitdiff
path: root/os/srv/backup.nix
diff options
context:
space:
mode:
Diffstat (limited to 'os/srv/backup.nix')
-rw-r--r--os/srv/backup.nix110
1 files changed, 86 insertions, 24 deletions
diff --git a/os/srv/backup.nix b/os/srv/backup.nix
index dad9b66..3d1d583 100644
--- a/os/srv/backup.nix
+++ b/os/srv/backup.nix
@@ -1,32 +1,94 @@
-{ config, lib, ... }:
+{
+ config,
+ lib,
+ pkgs,
+ ...
+}:
let
- cfg = config.os.srv.backup;
+ cfg = config.os.srv.replication;
+ pgLockScript = pkgs.writeScriptBin "pg-lock" ''
+ #!/bin/sh
+ microvm -s database-vm -- sudo -u postgres psql -c "SELECT pg_backup_start('sanoid_snap');"
+ '';
+
+ pgUnlockScript = pkgs.writeScriptBin "pg-unlock" ''
+ #!/bin/sh
+ microvm -s database-vm -- sudo -u postgres psql -c "SELECT pg_backup_stop();"
+ '';
in
{
- options.os.srv.backup.enable = lib.mkEnableOption "enables backups";
+ options.os.srv.replication.enable = lib.mkEnableOption "enables replications";
config = lib.mkIf cfg.enable {
- services.sanoid = {
- enable = true;
- templates.production = {
- hourly = 36;
- daily = 30;
- monthly = 3;
- };
- datasets."zroot/rpool/appdata/databases".useTemplate = [ "production" ];
- datasets."ztank/vault".useTemplates = [ "production" ];
- };
- services.syncoid = {
- enable = true;
- commands = {
- "sync-db" = {
- source = "zroot/rpool/appdata/databases";
- target = "ztank/backups/nvme/databases";
- sendOptions = "w";
+ services = {
+ sanoid = {
+ enable = true;
+ templates.production = {
+ autosnap = true;
+ autoprune = true;
+ hourly = 24;
+ daily = 7;
+ weekly = 4;
+ monthly = 3;
};
- "sync-configs" = {
- source = "zroot/rpool/appdata/configs";
- target = "ztank/backups/nvme/configs";
- sendOptions = "w";
+ datasets = {
+ "zroot/rpool/appdata/db/postgres" = {
+ useTemplate = [ "production" ];
+
+ pre_snapshot_script = "${pgLockScript}/bin/pg-lock";
+ post_snapshot_script = "${pgUnlockScript}/bin/pg-unlock";
+ no_inconsistent_snapshot = true;
+ force_post_snapshot_script = true;
+ script_timeout = 30;
+ };
+
+ "zroot/rpool/appdata/db/redis".useTemplate = [ "production" ];
+
+ "zroot/rpool/appdata/db/couchdb".useTemplate = [ "production" ];
+
+ "zroot/rpool/appdata/cfg".useTemplate = [ "production" ];
+
+ "zroot/rpool/appdata/games".useTemplate = [ "production" ];
+
+ "zroot/rpool/appdata/mail".useTemplate = [ "production" ];
+
+ "zroot/rpool/containers".useTemplate = [ "production" ];
+ };
+ };
+
+ syncoid = {
+ enable = true;
+ commonArgs = [
+ "-w"
+ "--delete-target-snapshots"
+ "--use-hold"
+ "--no-sync-snap"
+ ];
+ commands = {
+ "sync-databases" = {
+ source = "zroot/rpool/appdata/db";
+ target = "tank/ztank/backup/nvme/db";
+ recursive = true;
+ };
+
+ "sync-config" = {
+ source = "zroot/rpool/appdata/cfg";
+ target = "tank/ztank/backup/nvme/cfg";
+ };
+
+ "sync-games" = {
+ source = "zroot/rpool/appdata/games";
+ target = "tank/ztank/backup/nvme/games";
+ };
+
+ "sync-mail" = {
+ source = "zroot/rpool/appdata/mail";
+ target = "tank/ztank/backup/nvme/mail";
+ };
+
+ "sync-docker" = {
+ source = "zroot/rpool/containers";
+ target = "tank/ztank/backup/nvme/containers";
+ };
};
};
};