From dd3bef33b0e3f4a108f661c919734d2e6fb5aa21 Mon Sep 17 00:00:00 2001 From: Chris Toph Date: Mon, 16 Sep 2024 17:24:28 -0400 Subject: [PATCH] New cron and logrotate jobs for DockerStorage backup --- nixos/default.nix | 4 ++++ nixos/modules/cron/default.nix | 11 +++++++++++ nixos/modules/logrotate/default.nix | 6 ++++++ nixos/modules/logrotate/logrotate.conf | 11 +++++++++++ nixos/modules/snapraid/default.nix | 9 --------- nixos/pkgs/snapraid-runner/default.nix | 3 +-- 6 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 nixos/modules/cron/default.nix create mode 100644 nixos/modules/logrotate/default.nix create mode 100644 nixos/modules/logrotate/logrotate.conf diff --git a/nixos/default.nix b/nixos/default.nix index a6052ad..15d98d5 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -23,6 +23,10 @@ in { # ACME ./modules/acme + # cron + ./modules/cron + # Logrotate + ./modules/logrotate # Nextcloud ./modules/nextcloud # Nginx diff --git a/nixos/modules/cron/default.nix b/nixos/modules/cron/default.nix new file mode 100644 index 0000000..5509bf0 --- /dev/null +++ b/nixos/modules/cron/default.nix @@ -0,0 +1,11 @@ +{ + services.cron = { + enable = true; + systemCronJobs = [ + # Runs snapraid-runner every day at 3am + "0 3 * * * root snapraid-runner" + # Runs a backup of the Docker storage directory every Monday at 4am + "0 4 * * 0 root tar -Pzcf /pool/Backups/DockerStorage/DockerStorage.tar.gz -C /mnt/drive1/DockerStorage ." + ]; + }; +} \ No newline at end of file diff --git a/nixos/modules/logrotate/default.nix b/nixos/modules/logrotate/default.nix new file mode 100644 index 0000000..c43432a --- /dev/null +++ b/nixos/modules/logrotate/default.nix @@ -0,0 +1,6 @@ +{ + services.logrotate = { + enable = true; + configFile = ./logrotate.conf; + }; +} \ No newline at end of file diff --git a/nixos/modules/logrotate/logrotate.conf b/nixos/modules/logrotate/logrotate.conf new file mode 100644 index 0000000..e155e11 --- /dev/null +++ b/nixos/modules/logrotate/logrotate.conf @@ -0,0 +1,11 @@ +dateext +missingok +notifempty +rotate 4 + +"/pool/Backups/DockerStorage/DockerStorage.tar.gz" { + weekly + rotate 8 + nocompress + su root root +} diff --git a/nixos/modules/snapraid/default.nix b/nixos/modules/snapraid/default.nix index e8b3df1..7559102 100644 --- a/nixos/modules/snapraid/default.nix +++ b/nixos/modules/snapraid/default.nix @@ -1,7 +1,6 @@ { pkgs, ... }: { - environment.etc."snapraid.conf".text = builtins.readFile ./snapraid.conf; environment.etc."snapraid-runner.conf".text = '' [snapraid] @@ -35,12 +34,4 @@ plan = 12 older-than = 10 ''; - - services.cron = { - enable = true; - systemCronJobs = [ - # Runs snapraid-runner every day at 3am - "0 3 * * * root snapraid-runner" - ]; - }; } diff --git a/nixos/pkgs/snapraid-runner/default.nix b/nixos/pkgs/snapraid-runner/default.nix index 28208c2..e4c9774 100644 --- a/nixos/pkgs/snapraid-runner/default.nix +++ b/nixos/pkgs/snapraid-runner/default.nix @@ -52,5 +52,4 @@ stdenv.mkDerivation rec { mkdir -p $out/bin ln -sf ${snapraid-runner}/bin/snapraid-runner $out/bin/snapraid-runner''; }; -} - +} \ No newline at end of file