Migrate to rsnapshot for backups
This commit is contained in:
@@ -132,12 +132,12 @@
|
||||
greg.backup.jobs.zwave = {
|
||||
src = "/var/lib/zwave";
|
||||
dest = "zwave";
|
||||
id = "zwave-asdf";
|
||||
id = "zwave-rsnap";
|
||||
};
|
||||
|
||||
greg.backup.jobs.hass-backup = {
|
||||
src = "/var/lib/hass";
|
||||
dest = "hass";
|
||||
id = "hass-asdf";
|
||||
id = "hass-rsnap";
|
||||
};
|
||||
}
|
||||
|
||||
@@ -66,18 +66,10 @@ in
|
||||
|
||||
virtualisation.docker.enable = true;
|
||||
|
||||
programs.ssh.extraConfig = lib.strings.concatStringsSep "\n" [
|
||||
"Host nas"
|
||||
" User backup"
|
||||
" IdentityFile /etc/ssh/duplicity_ed25519"
|
||||
" StrictHostKeyChecking no"
|
||||
" UserKnownHostsFile /dev/null"
|
||||
];
|
||||
|
||||
greg.backup.jobs.nas-backup = {
|
||||
src = "/var/gitlab/state/backup/";
|
||||
dest = "gitlab";
|
||||
id = "yha^-s45h";
|
||||
id = "container-gitlab";
|
||||
};
|
||||
|
||||
services = {
|
||||
|
||||
@@ -33,6 +33,6 @@
|
||||
greg.backup.jobs.nextcloud-bkup = {
|
||||
src = "/var/lib/nextcloud";
|
||||
dest = "nextcloud-backup";
|
||||
id = "rbfco-rvmis";
|
||||
id = "nextcloud-backup";
|
||||
};
|
||||
}
|
||||
|
||||
@@ -54,6 +54,6 @@
|
||||
greg.backup.jobs.greg-postgresql-backup = {
|
||||
src = config.services.postgresqlBackup.location;
|
||||
dest = "linode-postgres";
|
||||
id = "9pwvg-s257a";
|
||||
id = "linode-postgres";
|
||||
};
|
||||
}
|
||||
|
||||
+26
-15
@@ -8,7 +8,15 @@
|
||||
let
|
||||
cfg = config.greg.backup;
|
||||
|
||||
where = j: "${config.services.syncthing.dataDir}/${j.dest}";
|
||||
where = j: "${config.services.syncthing.dataDir}/daily.0/${j.dest}";
|
||||
|
||||
postexec = pkgs.writeShellApplication {
|
||||
name = "postexec";
|
||||
runtimeInputs = [ pkgs.coreutils ];
|
||||
text = ''
|
||||
chown -R ${config.services.syncthing.user} ${config.services.syncthing.dataDir}
|
||||
'';
|
||||
};
|
||||
|
||||
makeSyncFolders = _: job: {
|
||||
devices = [ "chronicles" ];
|
||||
@@ -19,19 +27,7 @@ let
|
||||
type = "sendonly";
|
||||
};
|
||||
|
||||
makeRestic =
|
||||
_: job:
|
||||
let
|
||||
who = "${config.services.syncthing.user}:${config.services.syncthing.group}";
|
||||
in
|
||||
rec {
|
||||
initialize = true;
|
||||
passwordFile = config.age.secrets.restic-pw.path;
|
||||
paths = [ job.src ];
|
||||
repository = where job;
|
||||
backupCleanupCommand = ''${pkgs.coreutils}/bin/chown -R ${who} "${repository}"'';
|
||||
};
|
||||
|
||||
makeRsnapshot = _: job: "backup ${job.src}/ ${job.dest}/";
|
||||
in
|
||||
with lib;
|
||||
{
|
||||
@@ -76,7 +72,22 @@ with lib;
|
||||
};
|
||||
services = {
|
||||
syncthing.settings.folders = mapAttrs makeSyncFolders cfg.jobs;
|
||||
restic.backups = mapAttrs makeRestic cfg.jobs;
|
||||
rsnapshot = {
|
||||
enable = true;
|
||||
enableManualRsnapshot = true;
|
||||
extraConfig =
|
||||
''
|
||||
snapshot_root ${config.services.syncthing.dataDir}/
|
||||
retain daily 7
|
||||
retain weekly 2
|
||||
cmd_postexec ${lib.getExe postexec}
|
||||
''
|
||||
+ (builtins.concatStringsSep "\n" (mapAttrsToList makeRsnapshot cfg.jobs));
|
||||
cronIntervals = {
|
||||
daily = "19 02 * * *"; # At 2:19 am every day
|
||||
weekly = "19 01 * * 1"; # At 1:19 am every Monday
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user