From a76916d06dfeb211eb4aeaf4399dd6d739a2d227 Mon Sep 17 00:00:00 2001 From: clerie Date: Tue, 7 Dec 2021 19:48:24 +0100 Subject: [PATCH] Add backup scripts to version control --- hosts/palladium/backup-scripts.nix | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 hosts/palladium/backup-scripts.nix diff --git a/hosts/palladium/backup-scripts.nix b/hosts/palladium/backup-scripts.nix new file mode 100644 index 0000000..c5a232b --- /dev/null +++ b/hosts/palladium/backup-scripts.nix @@ -0,0 +1,35 @@ +{ pkgs, ... }: + +let + cb-mount = pkgs.writeScriptBin "cb-mount" '' + #!${pkgs.bash}/bin/bash + + DEVICE=/dev/disk/by-path/pci-0000:00:12.0-ata-2-part1 + + cryptsetup luksOpen ''${DEVICE} external-drive + mkdir -p /mnt/external-drive + mount /dev/mapper/external-drive /mnt/external-drive + ''; + + cb-sync = pkgs.writeScriptBin "cb-sync" '' + #!${pkgs.bash}/bin/bash + + # Check, if the something is mounted in our sycdir + if grep -qs '/mnt/external-drive' /proc/mounts + then + rsync -rltD '/mnt/palladium/alpha.0/clerie-backup/clerie-backup-replication/' '/mnt/external-drive/clerie-backup' + else + echo "Please plug in a backup drive and mount it using cb-mount" + fi + ''; + + cb-unmount = pkgs.writeScriptBin "cb-unmount" '' + #!${pkgs.bash}/bin/bash + + umount /mnt/external-drive + cryptsetup luksClose external-drive + ''; + +in { + environment.systemPackages = with pkgs; [ pkgs.cryptsetup pkgs.rsync cb-mount cb-sync cb-unmount ]; +}