-
Notifications
You must be signed in to change notification settings - Fork 3
/
update_afs.sh
executable file
·144 lines (125 loc) · 4.16 KB
/
update_afs.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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/sh
# $Id: update_afs.sh,v 1.17 2004-09-18 09:00:32 turbo Exp $
cd /
# --------------
# Set some default variables
AFSSERVER="aurora.bayour.com"
AFSCELL="bayour.com"
# --------------
replicated () {
rw=$1 ; ro=$rw\.readonly
set -- `vos examine $rw $LOCALAUTH -encrypt | grep 'Last Update'`
shift ; shift
time1=`date -d "$*" "+%s"`
set -- `vos examine $ro $LOCALAUTH -encrypt | grep 'Last Update'`
shift ; shift
time2=`date -d "$*" "+%s"`
[ ! -z "$verbose" -a ! -z "$test" ] && printf "Vol: %-25s - $time1 ; $time2 => " $rw
if [ $time1 -ge $time2 ]; then
[ ! -z "$verbose" -a ! -z "$test" ] && echo "Needs to be released."
return 1
else
[ ! -z "$verbose" -a ! -z "$test" ] && echo "no need for release."
return 0
fi
}
# --------------
# 'Initialize' AFS access...
if ! tokens | grep -q ^User; then
ID=`id -u`
if [ "$ID" != "0" ]; then
echo "You must have a valid AFS token to do a backup (or be root)." > /dev/stderr
exit 1
else
LOCALAUTH="-localauth"
fi
fi
# --------------
# Get the CLI options...
VOLUMES="" ; TEMP=`getopt -o chprtuvV --long common,help,public,root,test,users,verbose,version -- "$@"`
eval set -- "$TEMP"
while true ; do
case "$1" in
-c|--common) search="$search common" ; shift ;;
-h|--help)
echo "Usage: `basename $0` [option] [volume]"
echo "Options:"
echo " -c,--common Release only the common.* volumes"
echo " -h,--help Show this help"
echo " -p,--public Release the public.* volumes"
echo " -r,--root Release the root.* volumes"
echo " -t,--test Get volumes, but don't relase them"
echo " -u,--users Release the user.* volumes"
echo " -v,--verbose Explain what's being done"
echo " -V,--version Show version number"
echo "If volume is given, only release that/those volumes."
echo "If no option and no volume is given, backup all replicated volumes."
echo
exit 0
;;
-p|--public) search="$search public" ; shift ;;
-r|--root) search="$search root" ; shift ;;
-t|--test) test=1 ; shift ;;
-u|--users) search="$search user" ; shift ;;
-v|--verbose) verbose="-verbose" ; shift ;;
-V|--version)
set -- `echo "$Id: update_afs.sh,v 1.17 2004-09-18 09:00:32 turbo Exp $"`
echo "Version: $3"
exit 0
;;
--) shift ; [ -z "$VOLUMES" ] && VOLUMES="$*" ; break ;;
*) echo "Internal error!" ; exit 1 ;;
esac
done
# --------------
# Get volumes for backup
if [ "$search" != "" ]; then
# Build a nice regexp for the volumes to search for.
search="^(`echo $search | sed -e 's@ @\\\..*\\\.readonly|^@' -e 's@\$@\\\..*\\\.readonly@'`).*RO.*"
# Get all the volumes contain the search criteria
VOLUMES=`vos listvol ${AFSSERVER:-localhost} -quiet $LOCALAUTH -encrypt | egrep "$search" | sed -e 's@\.readonly.*@@'`
else
if [ -z "$VOLUMES" ]; then
VOLUMES=`vos listvol ${AFSSERVER:-localhost} -quiet $LOCALAUTH -encrypt | grep readonly | sed -e 's@\ .*@@' -e 's@\.readonly@@'`
fi
fi
VOLUMES=`echo $VOLUMES`
# --------------
# Which of these should REALLY be released?
# Look in the 'Last Update' line of 'vos examine'.
#
# If the RW volume is _NEWER_ than the RO, then replicate!
for vol in $VOLUMES; do
if ! replicated $vol; then
RELEASE="$RELEASE $rw"
fi
done
VOLUMES="`echo $RELEASE | sed 's@^\ @@'`"
if [ ! -z "$test" ]; then
[ ! -z "$verbose" ] && spcs=" "
echo "Volumes to release: $spcs$VOLUMES"
exit 0
fi
for vol in $VOLUMES; do
if [ ! -z "$verbose" ]; then
set -- `vos examine $vol $LOCALAUTH | head -n1` ; SIZE=$4
S=`date +"%Y%m%d %H:%M:%S"` ; START=`date +"%s"`
echo "Releasing volume $vol ($S): "
vos release $vol $LOCALAUTH $verbose -encrypt
E=`date +"%Y%m%d %H:%M:%S"` ; END=`date +"%s"`
SEC=`expr $END - $START` ; MIN=`expr $SEC / 60`
TIME=`expr $SIZE / $SEC`
echo "Volume released at $E. Took $SEC sec (~$MIN min)"
echo "This means that $TIME Kb was released per second"
else
RES=`vos release $vol $LOCALAUTH -encrypt 2>&1`
fi
res=$?
if [ "$res" != "0" ]; then
# An error occured!
RES=`echo $RES | sed 's@Could not lock.*@@'`
echo "ERROR: Could not release volume $vol - $res/$RES"
else
[ ! -z "$verbose" ] && echo
fi
done