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
mount /dev/mapper/luks /mnt/btrfs
if [[ -e /mnt/btrfs/root ]]; then
mkdir -p /mnt/btrfs/root.bak
timestamp=$(date --date="@$(stat -c %Y /mnt/btrfs/root)" "+%Y-%m-%-d_%H:%M:%S")
mv /mnt/btrfs/root "/mnt/btrfs/root.bak/$timestamp"
if [[ -e /mnt/btrfs/@ ]]; then
mkdir -p /mnt/btrfs/@.bak
timestamp=$(date --date="@$(stat -c %Y /mnt/btrfs/@)" "+%Y-%m-%-d_%H:%M:%S")
mv /mnt/btrfs/@ "/mnt/btrfs/@.bak/$timestamp"
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"
done
btrfs subvolume create /mnt/btrfs/root
btrfs subvolume create /mnt/btrfs/@
umount /mnt/btrfs
rmdir /mnt/btrfs

View File

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

View File

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