Reorganize imports
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
30
hosts/common/configs/system/impermanence/scripts/wipe.sh
Normal file
30
hosts/common/configs/system/impermanence/scripts/wipe.sh
Normal file
@@ -0,0 +1,30 @@
|
||||
delete_subvolume_recursively() {
|
||||
IFS=$'\n'
|
||||
for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
|
||||
delete_subvolume_recursively "/mnt/btrfs/${i}"
|
||||
done
|
||||
btrfs subvolume delete "$1"
|
||||
}
|
||||
|
||||
if [[ -z "$DEVICE" ]]; then
|
||||
echo "Error: DEVICE variable is not set."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p /mnt/btrfs
|
||||
mount "/dev/mapper/$DEVICE" /mnt/btrfs
|
||||
|
||||
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/@.bak/ -maxdepth 1 -mtime +14 | while IFS= read -r i; do
|
||||
delete_subvolume_recursively "${i}"
|
||||
done
|
||||
|
||||
btrfs subvolume create /mnt/btrfs/@
|
||||
|
||||
umount /mnt/btrfs
|
||||
rmdir /mnt/btrfs
|
Reference in New Issue
Block a user