#!/bin/bash
# You can find the short disk serial by: udevadm info --query=property --name=nvme0n1 | grep ID_SERIAL_SHORT | cut -d '=' -f 2
DISK_SERIAL="7VS0224F"
DISK_ID=$(readlink -f /dev/disk/by-id/*"${DISK_SERIAL}") # Returns /dev/nvme0n1

PARTITIONS=$(lsblk -o NAME,TYPE -p -n -l "$DISK_ID" | awk '$2 == "part" {print $1}')
echo "Partitions of $DISK_ID:"
echo "$PARTITIONS"
echo "Disk Identifier: $DISK_ID"

# Example output:
# Partitions of /dev/nvme1n1:
# /dev/nvme1n1p1
# /dev/nvme1n1p2
# /dev/nvme1n1p3
# Disk Identifier: /dev/nvme1n1
# borg create /path/to/repo::{now} /dev/nvme1n1
# borg create /path/to/repo::{now} /dev/nvme1n1p1 /dev/nvme1n1p2 /dev/nvme1n1p3

# Use the following line to perform a borg backup for the full disk:
# borg create /path/to/repo::{now} $DISK_ID

# Use the following to perform a borg backup for all partitions of the disk
# borg create /path/to/repo::{now} "${PARTITIONS[*]}"
