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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
#!/bin/sh
#
# create a forest of archives suitable for using with pmlogger_daily
#
# only arg from the command line is the root of the forest, which must
# already exist
#
# -c config specifies an alternate recipe with one archive per line
# and the fields
# hostname source-archive-base-name destination-archive-base-name
#
_usage()
{
echo >&2 "Usage: mk.logfarm [-c config] rootdir"
exit 1
}
tmp=/var/tmp/mk.logfarm.$$
trap "rm -f $tmp.*; exit \$sts" 0 1 2 3 15
# need to be able to find pmlogrewrite
#
if [ ! -f /etc/pcp.conf ]
then
echo "mk.logfarm: Error: cannot find /etc/pcp.conf"
exit
fi
eval `grep PCP_BINADM_DIR= /etc/pcp.conf`
if [ -z "$PCP_BINADM_DIR" ]
then
echo "mk.logfarm: Error: cannot find PCP_BINADM_DIR from /etc/pcp.conf"
exit
fi
export PATH=$PCP_BINADM_DIR:$PATH
if which pmlogrewrite >/dev/null 2>&1
then
:
else
echo "mk.logfarm: Error: cannot find pmlogrewrite"
exit
fi
sts=1
config=''
while getopts 'c:?' p
do
case "$p"
in
c) config="$OPTARG"
if [ ! -f "$config" ]
then
echo "mk.logfarm: Error: config ($config) does not exist"
exit
fi
;;
?) _usage
# NOTREACHED
esac
done
shift `expr $OPTIND - 1`
if [ $# -ne 1 ]
then
_usage
# NOTREACHED
fi
rootdir="$1"
if [ ! -d "$rootdir" ]
then
echo "mk.logfarm: Error: rootdir ($rootdir) does not exist"
exit
fi
rm -f $tmp.abort
if [ -z "$config" ]
then
cat <<End-of-File
thishost archives/foo+ 20011002
thishost archives/foo+ 20011003
thishost archives/foo+ 20011004.01.02
thishost archives/foo+ 20011004.03.04
thishost archives/foo+ 20011004.05.06
thishost archives/foo+ 20011004.05.06-00
thishost archives/foo+ 20011004.07.08
thishost archives/foo+ 20011005
thishost archives/foo+ 20011006.00.10
thishost archives/foo+ 20011007
otherhost archives/ok-foo 20011002.00.10
otherhost archives/ok-foo 20011002.00.10-00
otherhost archives/ok-foo 20011002.02.03
otherhost archives/ok-foo 20011002.03.04
otherhost archives/ok-foo 20011003.00.10
otherhost archives/ok-foo 20011004
otherhost archives/ok-foo 20011005.00.10
otherhost archives/ok-foo 20011006
End-of-File
else
cat "$config"
fi \
| sed \
-e 's/#.*//' \
-e '/^[ ]*$/d' \
| while read host src dst
do
if [ ! -d "$rootdir"/"$host" ]
then
if mkdir "$rootdir"/"$host"
then
:
else
echo "mk.logfarm: Error: mkdir failed for $rootdir/$host"
touch $tmp.abort
break
fi
fi
for file in "$src".*
do
if [ "$file" = "$src.*" ]
then
echo "mk.logfarm: Error: no files match source ($src.*)"
touch $tmp.abort
break
fi
cp "$file" "$rootdir"/"$host"
done
[ -f $tmp.abort ] && break
srcbase="`basename $src`"
# rename if needed ...
#
if [ "$srcbase" != "$dst" ]
then
if pmlogmv "$rootdir"/"$host"/"$srcbase" "$rootdir"/"$host"/"$dst"
then
:
else
echo "mk.logfarm: Error: pmlogmv $host/$srcbase -> $host/$dst failed"
touch $tmp.abort
break
fi
fi
# if the destination archive name is of the YYYYMMDD... format, then
# align timestamps, unless this is a bad archive (maybe we're testing
# with one of the badarchives ones) ...
#
rm -f $tmp.dostamp
case "$dst"
in
2[0-9][0-9][0-9][01][0-9][0-3][0-9]*)
touch $tmp.dostamp
;;
esac
if [ -f $tmp.dostamp ]
then
if pmlogcheck -w "$rootdir"/"$host"/"$dst">/dev/null 2>&1
then
# now align the timestamps of the archive with the date-and-time
# of the destination archive name
#
delta=`src/timeshift -z -a "$rootdir"/"$host"/"$dst" "$dst"`
cat <<End-of-File >$tmp.config
GLOBAL {
time -> $delta
}
End-of-File
if pmlogrewrite -c $tmp.config -i "$rootdir"/"$host"/"$dst"
then
:
else
echo "mk.logfarm: Error: pmlogrewrite $host/$dst failed"
touch $tmp.abort
break
fi
fi
# And finally change the access and modification times.
#
# Need to use the *bsd verson of touch(1) syntax for -t, namely
# "YYYYMMDDhhmm.SS" which also works for the Linux variants
# of touch(1).
#
stamp="`echo "$dst" | sed \
-e 's/-[0-9][0-9]*$//' \
-e 's/^\(....\)\(..\)\(..\)\.\(..\)\.\(..\)$/\1\2\3\4\5.00/' \
-e 's/^\(....\)\(..\)\(..\)$/\1\2\30000.00/' \
`"
#debug# echo "dst=$dst stamp=$stamp"
for file in "$rootdir"/"$host"/"$dst".*
do
touch -t "$stamp" "$file"
done
else
# skip timestamp for $dst"
#
:
fi
done
[ ! -f $tmp.abort ] && sts=0
exit $sts
|