Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #tahoe-prune.sh
- #Run tahoe-prune.sh when in a tahoe node dir to delete ONE share of files having "n" shares stored in this node
- #Script performs some safety checks to ensure it is in a tahoe node dir before doing any rm
- #usage:
- # tahoe-prune.sh num-of-shares [node-dir-path]
- #
- #A. Montero
- if [ -e $2]; then
- dir=`pwd`
- echo "No node dir specified. Defaulting to $dir"
- else
- dir=$2
- fi
- dir="${dir}/storage/shares"
- file="my_nodeid"
- echo "Checking if a tahoe node directory..."
- if [ -f "$file" ]; then
- echo "File $file found."
- else
- echo "File $file NOT found."
- echo "ABORTING"
- exit
- fi
- echo "Directory checking..."
- if [ -d "$dir" ]; then
- echo "Share directory $dir found."
- else
- echo "Share directory $dir NOT found."
- echo "ABORTING"
- exit
- fi
- if [ -e $1 ]; then
- echo "Share count filter not specified. Exiting."
- exit
- else
- shares=$1
- fi
- echo "Pruning files with '$shares' shares... "
- echo "Counting..."
- pushd "$dir" > /dev/null
- find . -type f | uniq -w 32 -c | grep " $shares " | tr -s " " " " | cut -d " " -f 3 | wc -l
- read -e -p "Display file listing? (y/n) " -i "n" DISPLAY
- if [ "$DISPLAY" = "y" ]; then
- find . -type f | uniq -w 32 -c | grep " $shares " | tr -s " " " " | cut -d " " -f 3 | less
- fi
- popd > /dev/null
- read -e -p "Remove first share in each dir? (y/n) " -i "n" PURGE
- if [ "$PURGE" = "y" ]; then
- pushd "$dir" > /dev/null
- rm --preserve-root -v `find . -type f | uniq -w 32 -c | grep " $shares " | tr -s " " " " | cut -d " " -f 3`
- popd > /dev/null
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement