Skip to content

Instantly share code, notes, and snippets.

@harshavardhana
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harshavardhana/8a51766149f9b8f98af7 to your computer and use it in GitHub Desktop.
Save harshavardhana/8a51766149f9b8f98af7 to your computer and use it in GitHub Desktop.
rebalance_large_files
#!/bin/bash
list_large_files_checksum ()
{
local DIR=$1;
large_files=""
large_directories=""
# Get top ten culprit files
for i in $(du --exclude=".glusterfs" -akx $DIR | sort -nr | head -10 | awk {'print $2'}); do
if [ -f $i ]; then
large_files="$large_files $i"
else
large_directories="$large_directories $i"
fi
done
if [ -z "$large_files" ]; then
echo "No large files found, but there are large directories still"
echo "$large_directories"
exit 1;
fi
echo -n "Generating checksum for $large_files"
for i in $large_files; do
if [ -f $i ]; then
md5sum $i | awk {'print $1'} > /tmp/$(basename $i).md5sum
fi;
done
echo " Done."
}
mount_glusterfs ()
{
local volname="$1"
local mount_point="$2";
if [ -f "/var/lib/glusterd/vols/$volname/$volname-fuse.vol" ]; then
subvolumes_replicated=$(grep -w 'volume' /var/lib/glusterd/vols/$volname/$volname-fuse.vol | grep replicate | awk {\
'print $2'})
fi
while true; do
echo "Replicated subvolumes found are $subvolumes_replicated";
echo -n "Enter your subvolume name to mount and press [ENTER]: "
read subvolumename
echo -n "Mouting $subvolumename from $volname..";
mount -t glusterfs -ovolume-name=$subvolumename localhost:/$volname $mount_point;
echo "Done."
sleep 2;
echo -n "Enter absolute path of the filename to be transferred and press [ENTER]: "
read filename
relative_file=$(echo $filename | sed 's/PATTERN//g');
relative_dir=$(dirname $relative_file)
echo -n "Copying $filename to $relative_dir inside $mount_point ..";
rsync -at $filename $mount_point/$relative_dir;
echo "Done."
echo "Verifying.. from old checksum"
old_md5sum=$(cat /tmp/$(basename $filename).md5sum)
new_md5sum=$(md5sum $mount_point/$relative_file |awk {'print $1'});
umount $mount_point;
if [ $old_md5sum != $new_md5sum ]; then
echo "Catastrophic error exiting corruption found";
exit 1;
fi
echo -n "Are you done transferring? [y/n]:"
read yes
if [ $yes == "y" ]; then
exit 1;
fi
done
}
main ()
{
if [ $# -ne 3 ]; then
echo "wrong number of arguments given"
echo " $0 <large_file_checksum_dir> <volumename> <mount_point>"
exit 1;
fi
list_large_files_checksum $1;
mount_glusterfs $2 $3;
}
main "$@";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment