Hi, Squid.
The pop-up argument input was fine, but after I upgraded the plugin. It's gone.
Could you review my code?
#!/bin/bash
#description=Here is a housekeeping script. By default just deletes empty timestamp directories. Optionally, it can delete snapshots.
foregroundOnly=true
backgroundOnly=true
#arrayStarted=false
#name= BTRFS cleanup
#argumentDescription="-a purges all snapshots; -i <Comma seperated list of shares> purges the selected shares. example -i Downloads,Test1,Test2 will purge all snapshots for Downloads, Test1, and Test2."
#argumentDefault=-a
shopt -s nullglob
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-i|--include)
INCLUDE="$2"
shift # past argument
shift # past value
;;
-a|--all)
ALL=YES
shift
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
#Tokenize include list
declare -A includes
for token in ${INCLUDE//,/ }; do
includes[$token]=1
done
#iterate over all disks on array
for disk in /mnt/disk*[0-9]* ; do
#iterate over each timestamp
for timestamp in ${disk}/.snapshots/* ; do
#iterate over each share in the timestamp
for snap in $timestamp/* ; do
if [ -n "${includes[$(basename $snap)]}" ] || [ "$ALL" = "YES" ] ; then
echo "Purging - $snap"
btrfs subvolume delete $snap
fi
#check for empty timestamp
if [ ! "$(ls -A $timestamp)" ] ; then
echo "Purging empty directory - $timestamp"
rmdir $timestamp
fi
done
done
done
and it's original from
Thank you so much.