#!/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