72 lines
1.9 KiB
Nix
72 lines
1.9 KiB
Nix
{ pkgs, ... }:
|
|
|
|
let
|
|
user = "ccqcraft";
|
|
host = "ccqcraft.de";
|
|
path = "~/server/mc/plugins/EasyBackup/backups";
|
|
|
|
fetchTime = "*-*-* 03:00:00";
|
|
clearTime = "Mon *-*-* 04:00:00";
|
|
|
|
insertResetNoteCmd = with pkgs;
|
|
pkgs.writeScriptBin "insert-reset-note" ''
|
|
#!${stdenv.shell}
|
|
DATE=$(${coreutils}/bin/date +backup_%Y-%m-%d_%H:%M:%S%z.reset)
|
|
touch ./''${DATE}
|
|
'';
|
|
|
|
in {
|
|
systemd.services = {
|
|
ccqcraft-pull-backups = {
|
|
unitConfig = {
|
|
Description = ''
|
|
Pull backups from CCQCraft Minecraft Server via rsync
|
|
'';
|
|
After = [ "network.target" ];
|
|
};
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
ExecStart = [
|
|
''
|
|
${pkgs.rsync}/bin/rsync -tr --partial --rsh=${pkgs.openssh}/bin/ssh "${user}@${host}:${path}/" .''
|
|
];
|
|
WorkingDirectory = "/srv/hnd/ccqcraft-backups";
|
|
};
|
|
};
|
|
|
|
ccqcraft-restart-incremental-backups = {
|
|
unitConfig = {
|
|
Description = ''
|
|
Restart incremental backups for CCQCraft server
|
|
'';
|
|
Requires = [ "ccqcraft-pull-backups.service" ];
|
|
After = [ "network.target" "ccqcraft-pull-backups.service" ];
|
|
};
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
WorkingDirectory = "/srv/hnd/ccqcraft-backups";
|
|
ExecStart =
|
|
[ ''${pkgs.openssh}/bin/ssh "${user}@${host}" rm ${path}/*'' ];
|
|
ExecStartPost = [ "${insertResetNoteCmd}/bin/insert-reset-note" ];
|
|
};
|
|
};
|
|
};
|
|
|
|
systemd.timers = {
|
|
ccqcraft-pull-backups = {
|
|
wantedBy = [ "timers.target" ];
|
|
unitConfig = { Description = "Run CCQCraft Backups every day"; };
|
|
timerConfig = { OnCalendar = fetchTime; };
|
|
};
|
|
|
|
ccqcraft-restart-incremental-backups = {
|
|
wantedBy = [ "timers.target" ];
|
|
unitConfig = {
|
|
Description = "Restart CCQCraft incremental backups weekly";
|
|
};
|
|
timerConfig = { OnCalendar = clearTime; };
|
|
};
|
|
};
|
|
|
|
}
|