Advertisement
Guest User

tahoe-prune.sh

a guest
Mar 3rd, 2012
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.50 KB | None | 0 0
  1. #tahoe-prune.sh
  2. #Run tahoe-prune.sh when in a tahoe node dir to delete ONE share of files having "n" shares stored in this node
  3. #Script performs some safety checks to ensure it is in a tahoe node dir before doing any rm
  4. #usage:
  5. #   tahoe-prune.sh num-of-shares [node-dir-path]
  6. #
  7. #A. Montero
  8.  
  9. if [ -e $2]; then
  10.     dir=`pwd`
  11.     echo "No node dir specified. Defaulting to $dir"
  12. else
  13.     dir=$2
  14. fi
  15.  
  16. dir="${dir}/storage/shares"
  17.  
  18. file="my_nodeid"
  19. echo "Checking if a tahoe node directory..."
  20. if [ -f "$file" ]; then
  21.     echo "File $file found."
  22. else
  23.     echo "File $file NOT found."
  24.     echo "ABORTING"
  25.     exit
  26. fi
  27.  
  28. echo "Directory checking..."
  29. if [ -d "$dir" ]; then
  30.     echo "Share directory $dir found."
  31. else
  32.     echo "Share directory $dir NOT found."
  33.     echo "ABORTING"
  34.     exit
  35. fi
  36.  
  37. if [ -e $1 ]; then
  38.     echo "Share count filter not specified. Exiting."
  39.     exit
  40. else
  41.     shares=$1
  42. fi
  43.  
  44. echo "Pruning files with '$shares' shares... "
  45.  
  46. echo "Counting..."
  47. pushd "$dir" > /dev/null
  48. find . -type f | uniq -w 32 -c | grep " $shares " | tr -s "  " " " | cut -d " " -f 3 | wc -l
  49. read -e -p "Display file listing? (y/n) " -i "n" DISPLAY
  50. if [ "$DISPLAY" = "y" ]; then
  51.     find . -type f | uniq -w 32 -c | grep " $shares " | tr -s "  " " " | cut -d " " -f 3 | less
  52. fi
  53. popd > /dev/null
  54.  
  55. read -e -p "Remove first share in each dir? (y/n) " -i "n" PURGE
  56. if [ "$PURGE" = "y" ]; then
  57.     pushd "$dir" > /dev/null
  58.     rm --preserve-root -v `find . -type f | uniq -w 32 -c | grep " $shares " | tr -s "  " " " | cut -d " " -f 3`
  59.     popd > /dev/null
  60. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement