1
0
Просмотр исходного кода

chore(impermanence): change old root retention to keep last 5 instead of 30 days⏎

Zander Hawke 7 месяцев назад
Родитель
Сommit
d1235bcf6d
1 измененных файлов с 6 добавлено и 9 удалено
  1. 6 9
      hosts/odin/system/impermanence.nix

+ 6 - 9
hosts/odin/system/impermanence.nix

@@ -42,16 +42,13 @@
       fi
     }
 
-    # Delete old roots older than 30 days
-    for i in $(btrfs subvolume list /mnt | grep 'old-roots/@root-' | cut -f 9- -d ' '); do
-      subvol_time=$(echo "$i" | grep -o '[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}_[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}')
-      if [[ -n "$subvol_time" ]]; then
-        subvol_secs=$(date -d "$subvol_time" +%s 2>/dev/null || continue)
-        thirty_days_ago=$(date -d "30 days ago" +%s)
-        if [[ $subvol_secs -lt $thirty_days_ago ]]; then
-          delete_subvolume_recursively "/mnt/$i"
-        fi
+    # Delete old roots more than 5
+    index=0
+    for i in $(btrfs subvolume list /mnt | grep 'old-roots/@root-' | cut -f 9- -d ' ' | sort -r); do
+      if [[ $index -ge 5 ]]; then
+        delete_subvolume_recursively "/mnt/$i"
       fi
+      index=$((index + 1))
     done
 
     # Create or restore fresh root