-
Notifications
You must be signed in to change notification settings - Fork 0
/
kk47chunkmigrate.sh
executable file
·66 lines (59 loc) · 1.44 KB
/
kk47chunkmigrate.sh
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# copy the chunk from old disk to the new disk
# file chklist is the list of chunk
# file badlist is the corrupted chunk
function copy
{
if [[ ! -f ./chklist ]]; then
echo "There is no chklist file"
exit 1
fi
for chk in `cat chklist`
do
fdir=`echo "$chk" |rev|cut -c -6|rev|cut -c -3`
if [ -f $olddir/$fdir/$chk ]; then
cp $olddir/$fdir/$chk $newdir/$chk >> ./copy.log
if [ $? -ne 0 ]; then
echo "$chk copy failed"
rm -f /$newdir/$chk
echo "$chk" >> ./badlist
else
mv $newdir/$chk /$newdir/$fdir/
echo "$chk copy ok"
fi
else
echo "$chk not exist"
echo "$chk" >> ./nonexistlist
fi
done
}
#judge the input parm
if [ $# -ne 2 ];
then
echo "Usage $0 olddiskdir newdiskdir "
exit 1
fi
read -n1 -p "Are you sure to copy chunk (Y/N):" input
case $input in
Y|y)
echo -e "\n Copy chunk starting ... ...";;
N|n)
echo -e "\nExit";
exit 1;;
*)
echo -e "\nerror choice";
exit 1;;
esac
#get old and new disk dir
olddir=$1
newdir=$2
# init files
echo > ./badlist
echo > ./nonexistlist
# init new disk dir
for i in `seq -f %03g 0 999`; do
mkdir -p $2/$i
done
logname="./$(date +%F-%H%M%S)_copy.log"
copy | tee -a $logname
echo "Finished. Check badlist nonexistlist copy.log."