moved snapraid_snapshots.sh to script folder

This commit is contained in:
mc-fucker 2025-11-10 14:17:36 +01:00
parent 44d649c555
commit 3d93bffc31
2 changed files with 34 additions and 8 deletions

32
scripts/snapraid_snapshots.sh Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env bash
day="$(date -I)"
drivelist="$(grep -F "data d" /etc/snapraid.conf | grep -Po "(?<=/mnt/snapshot/)[[:alnum:]]*")"
param=$1
function create {
echo "$drivelist" | while IFS="" read -r serial; do
drive="/mnt/drives/${serial}"
if [[ ! -s "${drive}/snapraid?.parity" ]]; then
if [[ ! -d "${drive}/.snapshot/${day}" ]]; then
btrfs subvolume snapshot -r "$drive" "${drive}/.snapshot/${day}"
ln -nsfr "${drive}/.snapshot/${day}" "/mnt/snapshot/${serial}"
fi
fi
done
}
function delete {
echo "$drivelist" | while IFS="" read -r serial; do
drive="/mnt/drives/${serial}"
snapshots="$(ls -1 -d "${drive}/.snapshot/"* | head -n -1)"
echo "$snapshots" | while IFS="" read -r snap; do
btrfs subvolume delete "$snap"
done
done
}
if [[ "$param" == "create" ]]; then
create
elif [[ "$param" == "delete" ]]; then
delete
fi

View file

@ -14,12 +14,6 @@ in
#systemd.timers."snapraid-scrub".enable = false; #temporarily #systemd.timers."snapraid-scrub".enable = false; #temporarily
systemd.services."snapraid-sync" = { systemd.services."snapraid-sync" = {
#preStart = "systemctl start snapraid-pre";
#postStart = "systemctl start snapraid-post";
#path = [
# pkgs.bash
# pkgs.btrfs-progs
#];
serviceConfig = { serviceConfig = {
ReadWritePaths = [ ReadWritePaths = [
"/mnt/snapshot/ZVV0688G/.snapshot/" "/mnt/snapshot/ZVV0688G/.snapshot/"
@ -49,7 +43,7 @@ in
description = "Create btrfs snapshots for each disk in the array"; description = "Create btrfs snapshots for each disk in the array";
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
ExecStart = "/etc/nixos/modules/snapraid_snapshots.sh create"; ExecStart = "/etc/nixos/scripts/snapraid_snapshots.sh create";
}; };
path = snapshot-path; path = snapshot-path;
}; };
@ -57,7 +51,7 @@ in
description = "Delete btrfs snapshots for each disk in the array"; description = "Delete btrfs snapshots for each disk in the array";
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
ExecStart = "/etc/nixos/modules/snapraid_snapshots.sh delete"; ExecStart = "/etc/nixos/scripts/snapraid_snapshots.sh delete";
}; };
path = snapshot-path; path = snapshot-path;
}; };