2021-12-07 19:48:24 +01:00
|
|
|
{ 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
|
2022-01-24 19:20:09 +01:00
|
|
|
set -e
|
2021-12-07 19:48:24 +01:00
|
|
|
|
|
|
|
# Check, if the something is mounted in our sycdir
|
|
|
|
if grep -qs '/mnt/external-drive' /proc/mounts
|
|
|
|
then
|
2022-01-24 19:20:09 +01:00
|
|
|
echo "fine"
|
2021-12-07 19:48:24 +01:00
|
|
|
else
|
|
|
|
echo "Please plug in a backup drive and mount it using cb-mount"
|
2022-01-24 19:20:09 +01:00
|
|
|
exit 1
|
2021-12-07 19:48:24 +01:00
|
|
|
fi
|
2022-01-24 19:20:09 +01:00
|
|
|
|
|
|
|
SNAPSHOT_NAME=$(${pkgs.borgbackup}/bin/borg list --last 1 --short /mnt/palladium/clerie-backup)
|
|
|
|
${pkgs.borgbackup}/bin/borg mount /mnt/palladium/clerie-backup::$SNAPSHOT_NAME /mnt/clerie-backup-mount
|
|
|
|
${pkgs.bindfs}/bin/bindfs /mnt/clerie-backup-mount/mnt/clerie-backup /mnt/clerie-backup
|
|
|
|
${pkgs.borgbackup}/bin/borg create /mnt/external-drive/clerie-backup::$SNAPSHOT_NAME /mnt/clerie-backup
|
2022-02-08 20:31:54 +01:00
|
|
|
umount /mnt/clerie-backup
|
2022-01-24 19:20:09 +01:00
|
|
|
${pkgs.borgbackup}/bin/borg unmoumt /mnt/clerie-backup-mount
|
2021-12-07 19:48:24 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
cb-unmount = pkgs.writeScriptBin "cb-unmount" ''
|
|
|
|
#!${pkgs.bash}/bin/bash
|
|
|
|
|
|
|
|
umount /mnt/external-drive
|
|
|
|
cryptsetup luksClose external-drive
|
|
|
|
'';
|
|
|
|
|
|
|
|
in {
|
2022-02-08 20:32:59 +01:00
|
|
|
environment.systemPackages = with pkgs; [ pkgs.cryptsetup cb-mount cb-sync cb-unmount ];
|
2021-12-07 19:48:24 +01:00
|
|
|
}
|