Skip to content

Instantly share code, notes, and snippets.

@MatMoore
Last active June 11, 2018 12:50
Show Gist options
  • Save MatMoore/1e828b55f70e6b75ebffb63791603631 to your computer and use it in GitHub Desktop.
Save MatMoore/1e828b55f70e6b75ebffb63791603631 to your computer and use it in GitHub Desktop.
Remove old bundles that aren't being used any more
#!/usr/bin/env bash
set -euo pipefail
for i in $( ls /data/vhost|grep -v 'lost+found'); do
echo $i
dir="/data/vhost/$i/shared/bundle/ruby"
versions=$(ls -1 $dir|grep -v '.backup');
in_use=$(cat /data/vhost/$i/releases/*/.ruby-version | sed 's/[0-9]\+$/0/' | sort | uniq);
echo -e "in use\n----\n$in_use\n"
echo -e "available\n---\n$versions\n"
redundant=$(comm -13 <(cat /data/vhost/$i/releases/*/.ruby-version | sort | uniq | sed 's/[0-9]\+$/0/') <(ls -1 /data/vhost/$i/shared/bundle/ruby))
echo -e "redundant\n---\n$redundant\n"
for tomove in $redundant; do
echo "moving from $dir/$tomove to $dir/$tomove.backup"
# Rename instead of delete to check nothing breaks
sudo mv $dir/$tomove $dir/$tomove.backup
done
done
# Total amount of space that can be saved
find /data/vhost -name '*.backup' -exec du -ch {} + | grep total$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment