summaryrefslogtreecommitdiffstats
path: root/extras/defrag.sh
diff options
context:
space:
mode:
authorPavan Sondur <pavan@gluster.com>2010-01-19 08:11:05 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-01-19 05:56:39 -0800
commita6a1f596a443b6a015dca6435f1d22fc582acc80 (patch)
tree2a3f876cc0eab33a225978d306a96a37a3e8f9a4 /extras/defrag.sh
parenta23185f3a43ec95a56af9f0f543b67a1fcfb4852 (diff)
extras: Add defrag scripts to the repository
Signed-off-by: Pavan Vilas Sondur <pavan@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 478 (Add defrag scripts into glusterfs) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=478
Diffstat (limited to 'extras/defrag.sh')
-rw-r--r--extras/defrag.sh60
1 files changed, 60 insertions, 0 deletions
diff --git a/extras/defrag.sh b/extras/defrag.sh
new file mode 100644
index 00000000000..465b0979488
--- /dev/null
+++ b/extras/defrag.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+# This script gets called from 'scale-n-defrag.sh' script.
+# Don't run this stand alone.
+#
+#
+
+set -e
+
+CP="cp"
+MV="mv"
+
+scan_dir()
+{
+ path=$1;
+ find "$path" -type f -perm +01000 -exec $0 '{}' \;
+}
+
+rsync_filename()
+{
+ path=$1
+ dir=$(dirname "$path");
+ file=$(basename "$path");
+
+ echo "$dir/.$file.zr$$";
+}
+
+relocate_file()
+{
+ path=$1;
+ tmp_path=$(rsync_filename "$path");
+
+ pre_mtime=$(stat -c '%Y' "$path");
+ $CP -a "$path" "$tmp_path";
+ post_mtime=$(stat -c '%Y' "$path");
+
+ if [ $pre_mtime = $post_mtime ]; then
+ chmod -t "$tmp_path";
+ $MV "$tmp_path" "$path";
+ echo "file '$path' relocated"
+ else
+ echo "file '$path' modified during defrag. skipping"
+ rm -f "$tmp_path";
+ fi
+}
+
+main()
+{
+ path="$1";
+
+ if [ -d "$path" ]; then
+ scan_dir "$path";
+ else
+ relocate_file "$@";
+ fi
+
+ usleep 500000 # 500ms
+}
+
+main "$1"