forked from sheepdog/sheepdog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple2farm
executable file
·51 lines (41 loc) · 1.07 KB
/
simple2farm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# This script is used to translate simple store backend into Farm.
# Usage: simple2farm /path/to/store/obj
set -e
E_BADARGS=65
if [ $# -ne 1 ]; then
echo "Usage: `basename $0` /path/to/store/obj"
exit $E_BADARGS
fi
if [ `basename $1` != "obj" ]; then
echo "You should specify path to store/obj"
exit $E_BADARGS
fi
if [ "$(pgrep sheep)" ]; then
echo "You need to shutdown cluster first"
exit 1
fi
cd $1
config_offset=11
# Get the backend store from config file
echo "Read config file"
store=$(od --skip-bytes=$config_offset -An -c ../config | sed 's/ //g' | sed 's/\\0//g')
if [ "x$store" == "xfarm" ]; then
echo "It's already the farm store, we'er done"
exit 0
fi
# find the highest numbered directory, remove older ones
max=00000001
for i in *; do
if [ $i -gt $max ]; then
rm -rf $max
max=$i
fi
done
echo "Find the highest numbered directory $max"
echo "Try to move the objects..."
mv $max/* .
rmdir $max
echo "Update config file"
echo -en 'farm\0' | dd of=../config seek=$config_offset bs=1 2> /dev/null
echo "Now simple store has been tranformed into Farm"