From 855cdfa312ad3bce7604d1ecd8a9eff7aceb1eee Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Tue, 2 Apr 2024 10:31:45 -0400 Subject: [PATCH] rustboro: delete old roots after 5 days --- hosts/rustboro/default.nix | 40 ++++++++++++++------------------------ 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/hosts/rustboro/default.nix b/hosts/rustboro/default.nix index c31d945f..d9468935 100644 --- a/hosts/rustboro/default.nix +++ b/hosts/rustboro/default.nix @@ -14,37 +14,27 @@ loader.systemd-boot.enable = true; loader.efi.canTouchEfiVariables = true; - # initrd.postDeviceCommands = lib.mkAfter '' - # mkdir /btrfs_tmp - # mount /dev/sda2 /btrfs_tmp - # if [[ -e /btrfs_tmp/rootfs ]]; then - # mkdir -p /btrfs_tmp/old_roots - # timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/rootfs)" "+%Y-%m-%-d_%H:%M:%S") - # mv /btrfs_tmp/rootfs "/btrfs_tmp/old_roots/$timestamp" - # fi - - # delete_subvolume_recursively() { - # IFS=$'\n' - # for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do - # delete_subvolume_recursively "/btrfs_tmp/$i" - # done - # btrfs subvolume delete "$1" - # } - - # for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +10); do - # delete_subvolume_recursively "$i" - # done - - # btrfs subvolume create /btrfs_tmp/rootfs - # umount /btrfs_tmp - # ''; initrd.postDeviceCommands = lib.mkAfter '' mkdir /btrfs_tmp mount /dev/sda2 /btrfs_tmp if [[ -e /btrfs_tmp/rootfs ]]; then - btrfs subvolume delete /btrfs_tmp/rootfs + mkdir -p /btrfs_tmp/old_roots + timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/rootfs)" "+%Y-%m-%-d_%H:%M:%S") + mv /btrfs_tmp/rootfs "/btrfs_tmp/old_roots/$timestamp" fi + delete_subvolume_recursively() { + IFS=$'\n' + for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do + delete_subvolume_recursively "/btrfs_tmp/$i" + done + btrfs subvolume delete "$1" + } + + for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +5); do + delete_subvolume_recursively "$i" + done + btrfs subvolume create /btrfs_tmp/rootfs umount /btrfs_tmp '';