From 7de328e48f0babdd7b8bdc3a7e3132b9d56aa6e5 Mon Sep 17 00:00:00 2001 From: Chaos Date: Sun, 19 Mar 2023 11:44:27 +0000 Subject: [PATCH] rclone sync redo --- .../storage/profiles/rclone-sync.nix | 6 ++++ .../storage/profiles/rclone_config.template | 19 +++-------- hosts/hetzner-vm/profiles/misskey.nix | 1 + modules/nixos/rclone-sync.nix | 34 ++++++++++++------- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/hosts/hetzner-vm/containers/storage/profiles/rclone-sync.nix b/hosts/hetzner-vm/containers/storage/profiles/rclone-sync.nix index 81c03aa..891717c 100644 --- a/hosts/hetzner-vm/containers/storage/profiles/rclone-sync.nix +++ b/hosts/hetzner-vm/containers/storage/profiles/rclone-sync.nix @@ -15,27 +15,33 @@ { source = "StorageBox:Backups"; dest = "B2-Chaos-Backups:"; + id = "chaos_b2_backups"; } { source = "StorageBox:Photos"; dest = "B2-Chaos-Photos:"; + id = "chaos_b2_photos"; } { source = "StorageBox:Music"; dest = "B2-Chaos-Music:"; + id = "chaos_b2_music"; } # Pheonix System's B2 { source = "StorageBox:Backups"; dest = "B2-Phoenix-Cryptidz-Storage:Backups"; + id = "phoenix_b2_backups"; } { source = "StorageBox:Photos"; dest = "B2-Phoenix-Cryptidz-Storage:Photos"; + id = "phoenix_b2_photos"; } { source = "StorageBox:Music"; dest = "B2-Phoenix-Cryptidz-Storage:Music"; + id = "phoenix_b2_music"; } ]; }; diff --git a/hosts/hetzner-vm/containers/storage/profiles/rclone_config.template b/hosts/hetzner-vm/containers/storage/profiles/rclone_config.template index 0170899..de50d41 100644 --- a/hosts/hetzner-vm/containers/storage/profiles/rclone_config.template +++ b/hosts/hetzner-vm/containers/storage/profiles/rclone_config.template @@ -1,25 +1,14 @@ [StorageBox-Remote] -type = sftp +type = webdav +vendor = nextcloud host = u323231.your-storagebox.de +url = https://u323231.your-storagebox.de user = u323231 pass = STORAGEBOX_PASSWORD -port = 23 -shell_type = unix -md5sum_command = md5 -r -sha1sum_command = sha1 -r - -#type = smb -#type = webdav -#vendor = nextcloud -#host = u323231.your-storagebox.de -#url = https://u323231.your-storagebox.de -#user = u323231 -#pass = STORAGEBOX_PASSWORD - + [StorageBox] type = alias remote = StorageBox-Remote: -#backup [B2-Chaos-Backups-Source] type = b2 diff --git a/hosts/hetzner-vm/profiles/misskey.nix b/hosts/hetzner-vm/profiles/misskey.nix index b3635a4..7391628 100644 --- a/hosts/hetzner-vm/profiles/misskey.nix +++ b/hosts/hetzner-vm/profiles/misskey.nix @@ -141,6 +141,7 @@ in { { source = "/home/misskey/misskey-files"; dest = "Storage-Media-Crypt:"; + id = "misskey_media"; timerConfig = { OnStartupSec = "60"; OnCalendar = "4h"; diff --git a/modules/nixos/rclone-sync.nix b/modules/nixos/rclone-sync.nix index 1288c9d..e1f7fa4 100644 --- a/modules/nixos/rclone-sync.nix +++ b/modules/nixos/rclone-sync.nix @@ -7,8 +7,6 @@ with lib; let cfg = config.services.rclone-sync; - makeNameSafe = name: builtins.replaceStrings ["/" ":"] ["-" "-"] name; - daemonService = sync_config: { serviceConfig = lib.mkMerge [ { @@ -47,6 +45,8 @@ in { options = { source = mkOption {type = types.str;}; dest = mkOption {type = types.str;}; + id = mkOption {type = types.str;}; + autoRestart = mkOption { type = types.bool; default = true; @@ -72,23 +72,33 @@ in { config = mkMerge [ (mkIf (cfg.enable && cfg.sync_jobs != []) { - envionment.systemPackages = let - allServices = lib.concatStringsSep " " (map (job: "rclone-sync-${makeNameSafe job.source}-${makeNameSafe job.dest}")); - in [ - (pkgs.writeShellScriptBin "rclone-sync-all" '' - systemctl stop ${allServices} - systemctl start --wait ${allServices} - '') - ]; + environment.systemPackages = + [ + (pkgs.writeShellScriptBin "rclone-sync-all" (lib.concatStringsSep "\n" (map ( + job: '' + ${pkgs.rclone}/bin/rclone sync ${job.source} ${job.dest} -P + '' + ) + cfg.sync_jobs))) + ] + ++ ( + map ( + job: + pkgs.writeShellScriptBin "rclone-manual-sync-${job.id}" '' + exec ${pkgs.rclone}/bin/rclone sync ${job.source} ${job.dest} -P + '' + ) + cfg.sync_jobs + ); systemd.services = listToAttrs (map (job: { - name = "rclone-sync-${makeNameSafe job.source}-${makeNameSafe job.dest}"; + name = "rclone-sync-${job.id}"; value = daemonService job; }) cfg.sync_jobs); systemd.timers = listToAttrs (map (job: let - name = "rclone-sync-${makeNameSafe job.source}-${makeNameSafe job.dest}"; + name = "rclone-sync-${job.id}"; in { inherit name; value = {