From 663e78e5dd8ece9fc2603d7f284bb8a46e06da36 Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Sat, 28 Dec 2024 11:26:55 -0800 Subject: [PATCH] Added a backup for a specific shared folder --- hosts/Alaska/default.nix | 5 +++++ hosts/Alaska/modules/backup_script.nix | 18 ++++++++++++++++++ hosts/Alaska/modules/samba.nix | 13 +++++++++++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/hosts/Alaska/default.nix b/hosts/Alaska/default.nix index 7ed165c..56bc328 100644 --- a/hosts/Alaska/default.nix +++ b/hosts/Alaska/default.nix @@ -37,6 +37,11 @@ backup_dir = "/Aurora/Backups/Vaultwarden"; }; + samba_shares = { + enable = true; + backup_dir = "/Aurora/SharedFolders/Blizzard"; # only backup one folder + }; + forgejo = { enable = true; backups_dir = "/Aurora/Backups/Forgejo"; diff --git a/hosts/Alaska/modules/backup_script.nix b/hosts/Alaska/modules/backup_script.nix index 8b5a7c3..4f9f814 100644 --- a/hosts/Alaska/modules/backup_script.nix +++ b/hosts/Alaska/modules/backup_script.nix @@ -63,6 +63,18 @@ in }; }; + samba_shares = { + enable = lib.mkEnableOption (lib.mdDoc "Back up Samba shared folders"); + + backup_dir = lib.mkOption { + type = lib.types.path; + default = "/Aurora/SharedFolders"; + description = lib.mdDoc '' + The path of the shared folders used by samba + ''; + }; + }; + nextcloud = { enable = lib.mkEnableOption (lib.mkDoc "Back up nextcloud instance"); root_dir = lib.mkOption { @@ -139,6 +151,12 @@ in echo "Mounting the external backup drive" mount /dev/disk/by-label/${cfg.backup1_drive_label} ${builtins.toString cfg.tmp_mount_point} -t ntfs3 + #----- BEGIN SAMBA SHARES + if [ "${builtins.toString cfg.samba_shares.enable}" = "1" ]; then + rsync -av ${cfg.samba_shares.backup_dir} ${builtins.toString cfg.tmp_mount_point} + fi + #----- END SAMBA SHARES + #------ BEGIN NEXTCLOUD if [ "${builtins.toString cfg.nextcloud.enable}" = "1" ]; then echo "Putting nextcloud into maintenance mode so that changes cannot happen during the backup" diff --git a/hosts/Alaska/modules/samba.nix b/hosts/Alaska/modules/samba.nix index 1d1bf56..6ec65d0 100644 --- a/hosts/Alaska/modules/samba.nix +++ b/hosts/Alaska/modules/samba.nix @@ -7,18 +7,27 @@ in { enable = true; openFirewall = true; settings = { + global.workgroup = "WORKGROUP"; global."invalid users" = [ "root" ]; global.security = "user"; global."passwd program" = "/run/wrappers/bin/passwd %u"; - Iceberg = { + iceberg = { comment = "the Alaska SMB share"; path = "/Aurora/SharedFolders/Iceberg"; - "guest ok" = "yes"; + "guest ok" = "no"; "read only" = "no"; browseable = "yes"; }; + blizzard = { + comment = "Backed up Alaska SMB share"; + path = "/Aurora/SharedFolders/Blizzard"; + "guest ok" = "no"; + "read only" = "no"; + browseable = "yes"; + }; + }; };