-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvosmove2
More file actions
executable file
·126 lines (111 loc) · 3.31 KB
/
vosmove2
File metadata and controls
executable file
·126 lines (111 loc) · 3.31 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
PATH=/usr/afsws/bin:$PATH ; export PATH
function usage () {
echo Usage: $0 volume fromserver frompartition toserver topartition; exit 1;
}
localauth=""
if [ $# != 5 ];
then
if [ $# != 6 ] ; then
usage
else
case "$6" in
-loc*)
localauth=$6
;;
*)
usage
;;
esac
fi
fi
volume=$1
volbase=`basename $volume .readonly`
fromserver=$2
frompart=$3
toserver=$4
topart=$5
verbose="-verbose"
volcache=/tmp/move-volume.$$
rm -f $volcache
#vos listvol $fromserver $frompart $localauth > $volcache
vos exa $volbase > $volcache
echo ""
echo "# MOVING $volume FROM $fromserver:$frompart TO $toserver:$topart"
echo ""
# ```
if awk '$5 == "Backup" { if ($6 == "0") exit 1; else exit 0}' $volcache > /dev/null ; then
echo ""
echo "# Backup of $volume exists ==> must remember make a new backup ..."
echo ""
dobackup=true
fi
volumesize=`awk '$5 == "K" && $6 == "On-line" { print $4 }' $volcache`
starttime=`perl -e 'print time(),"\n"'`
function movereadonly () {
# First add one more so that we never have one too little
echo "------"
echo vos addsite $toserver $topart $volbase $verbose $localauth
echo "------"
if vos addsite $toserver $topart $volbase $verbose $localauth 2>/tmp/rocopy$$ ; then
: ok
else
if grep "already exists" /tmp/rocopy$$ ; then
: ok
else
exit 1
fi
fi
rm /tmp/rocopy$$
vos rele $volbase $verbose $localauth || exit 1
echo "------"
echo vos remove $fromserver $frompart $volbase.readonly $verbose $localauth
echo "------"
vos remove $fromserver $frompart $volbase.readonly $verbose $localauth || exit 1
echo "------"
readonlymoved=true
}
function movereadwrite () {
echo "------"
echo vos move $volume $fromserver $frompart $toserver $topart $verbose $localauth
echo "------"
vos move $volume $fromserver $frompart $toserver $topart $verbose $localauth || exit 1
echo "------"
readwritemoved=true
}
if [ $volume = $volbase.readonly ] ; then
# We were asked to move the RO copy.
# But we want to move both, so make two steps.
rwline=`awk '$1 == "server" && $3 == "partition" && $5 == "RO" && $2 == "'$fromserver'" && $4 == "'$frompart'" {sub(/RO/,"RW",$5); print}' $volcache`
if test "$rwline" && grep "$rwline" $volcache > /dev/null ; then
#we have both RW and RO, move RW first
volume=$volbase
movereadwrite
# undo name change
volume=$volbase.readonly
fi
movereadonly
else
# this not a RO, probably a RW
movereadwrite
roline=`awk '$1 == "server" && $3 == "partition" && $5 == "RW" {sub(/RW/,"RO",$5); print}' $volcache`
if test "$roline" && grep "$roline" $volcache > /dev/null ; then
#we have both RW and RO
movereadonly
fi
fi
if echo $dobackup | grep true > /dev/null && echo $readwritemoved | grep true > /dev/null ; then
echo "------"
echo vos backup $volbase $localauth
echo "------"
vos backup $volbase $localauth | sed 's/^/# /' || exit 1
fi
if echo $readonlymoved | grep true > /dev/null ; then
: "Don't remenber if there was something more to do ;)"
fi
# Statistics
echo -n "------ Speed was "
vos exa $volbase -format | awk '$1 == "name" || $1 == "filecount" || $1 == "diskused" {printf " %s ",$0}'
perl -e '$diff=time()-'$starttime'+0.0; $diff=1 if $diff == 0; print " ",'$volumesize'/$diff," kbytes/sec\n"'
rm -f $volcache
echo "------ $volume done"