Rename btrfs subvolumes

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2024-07-03 10:18:58 +03:00
parent a960df740b
commit 2cca11bfaa
3 changed files with 17 additions and 17 deletions

View File

@@ -9,17 +9,17 @@ delete_subvolume_recursively() {
mkdir -p /mnt/btrfs mkdir -p /mnt/btrfs
mount /dev/mapper/luks /mnt/btrfs mount /dev/mapper/luks /mnt/btrfs
if [[ -e /mnt/btrfs/root ]]; then if [[ -e /mnt/btrfs/@ ]]; then
mkdir -p /mnt/btrfs/root.bak mkdir -p /mnt/btrfs/@.bak
timestamp=$(date --date="@$(stat -c %Y /mnt/btrfs/root)" "+%Y-%m-%-d_%H:%M:%S") timestamp=$(date --date="@$(stat -c %Y /mnt/btrfs/@)" "+%Y-%m-%-d_%H:%M:%S")
mv /mnt/btrfs/root "/mnt/btrfs/root.bak/$timestamp" mv /mnt/btrfs/@ "/mnt/btrfs/@.bak/$timestamp"
fi fi
find /mnt/btrfs/root.bak/ -maxdepth 1 -mtime +14 | while IFS= read -r i; do find /mnt/btrfs/@.bak/ -maxdepth 1 -mtime +14 | while IFS= read -r i; do
delete_subvolume_recursively "$i" delete_subvolume_recursively "$i"
done done
btrfs subvolume create /mnt/btrfs/root btrfs subvolume create /mnt/btrfs/@
umount /mnt/btrfs umount /mnt/btrfs
rmdir /mnt/btrfs rmdir /mnt/btrfs

View File

@@ -19,13 +19,13 @@ fi
mkdir -p /mnt/btrfs mkdir -p /mnt/btrfs
mount /dev/mapper/luks /mnt/btrfs mount /dev/mapper/luks /mnt/btrfs
if [[ -e /mnt/btrfs/root.bak ]]; then if [[ -e /mnt/btrfs/@.bak ]]; then
if [ "$(ls -A /mnt/btrfs/root.bak)" ]; then if [ "$(ls -A /mnt/btrfs/@.bak)" ]; then
for i in /mnt/btrfs/root.bak/*; do for i in /mnt/btrfs/@.bak/*; do
delete_subvolume_recursively "$i" delete_subvolume_recursively "$i"
done done
else else
echo "/mnt/btrfs/root.bak is empty. Nothing to delete." echo "/mnt/btrfs/@.bak is empty. Nothing to delete."
fi fi
fi fi

View File

@@ -44,20 +44,20 @@
type = "btrfs"; type = "btrfs";
extraArgs = [ "-f" ]; extraArgs = [ "-f" ];
subvolumes = { subvolumes = {
"/root" = { "@" = {
mountpoint = "/"; mountpoint = "/";
}; };
"/persist" = { "@persist" = {
mountpoint = "/persist"; mountpoint = "/persist";
mountOptions = [ "subvol=persist" "compress=zstd" "noatime" ]; mountOptions = [ "compress=zstd" "noatime" ];
}; };
"/nix" = { "@nix" = {
mountpoint = "/nix"; mountpoint = "/nix";
mountOptions = [ "subvol=nix" "compress=zstd" "noatime" ]; mountOptions = [ "compress=zstd" "noatime" ];
}; };
"/cache" = { "@cache" = {
mountpoint = "/cache"; mountpoint = "/cache";
mountOptions = [ "subvol=cache" "compress=zstd" "noatime" ]; mountOptions = [ "compress=zstd" "noatime" ];
}; };
}; };
}; };