
디스크 할당량에 도달한 후 가장 오래된 BTRFS 스냅샷을 삭제하는 간단한 스크립트가 없다는 것이 이상하게 보입니다. BTRFS 도구 제품군의 일부였지만 더 이상은 아닙니다.
나는 bash에서 그다지 좋은 프로그래머가 아니기 때문에 여유 디스크 공간을 확인하고 특정 임계값에 도달하면 가장 오래된 BTRFS 스냅샷을 찾아 삭제하는 방법을 아는 사람이 있습니까? 매우 감사합니다!
답변1
좋아요, 대답이 없습니다. 내 솔루션이 도움이 되기를 바랍니다.
#!/bin/bash
value=80 #Disk % threshold - if disk full above, then oldest snapshots will be deleted until disk is below threshold
for i in 1 2 3 4 5 6 7 8 9
do
echo Attempt: $i of 9
echo Getting snapshot list...
to=$(sudo btrfs subvol list /mnt/timeshift/backup/timeshift-btrfs/snapshots)
search="snapshots"
prefix=${to%%$search*}
position=$(awk -v a="$to" -v b=$search 'BEGIN{print index(a,b)}')
fn=$(echo $to | cut -c $(($position+10))-$(($position+28)))
echo Oldest snapshot name: $fn
diskfull=$(df -hP / | awk '{print $5}' |tail -1|sed 's/%$//g')
if [ $value -gt $diskfull ]; then
echo Threshold $value% greater than Used disk $diskfull%
echo should not delete any more snapshots
echo Creating one more snapshot
sudo timeshift --create --comments "automatic"
exit 1
else
echo Threshold $value% is less than Used disk $diskfull%
echo Deleting snapshot $fn...
sudo timeshift --delete --snapshot "$fn"
echo Waiting for changes to be written...
sudo btrfs subvolume sync /
echo Checking if disk space resolved...
fi
done