No need to back up .rand files in /usr/lib/courier/
[clinton/scripts.git] / apache-sync-logs
... / ...
CommitLineData
1#!/bin/bash
2
3# invoke this as root on mire
4
5exec 2>&1
6
7# drop any tokens; use only users' cgi tokens
8kdestroy > /dev/null 2>&1
9unlog
10
11#VERBOSE=true
12VERBOSE=false
13
14LOCAL_LOG_DIR=/var/log/apache2/user
15KEYTAB_DIR=/etc/keytabs/user.daemon
16AFS_USER_DIR=/afs/hcoop.net/user
17ERROR=no
18
19# Sanify permissions so that we can safely create tmp directories and
20# run rsync.
21chmod -R u=rwX,g=rX,o=X $LOCAL_LOG_DIR
22
23# Iterate through logs for each user
24for A in $(find $LOCAL_LOG_DIR -mindepth 3 -maxdepth 3 -print); do
25 USER=`basename $A`
26 PATHBITS=`echo $USER | head -c 1`/`echo $USER | head -c 2`/$USER
27 LOG_SRC=$A/apache/log
28 LOG_DEST=$AFS_USER_DIR/$PATHBITS/.logs/apache/
29 TMP_DEST=$LOG_SRC.tmp
30
31 if [ "$VERBOSE" = "true" ]; then
32 echo
33 echo "=============================================================================="
34 echo "syncing logs for $USER from $A"
35 echo " to $LOG_DEST ..."
36 fi
37
38 if [ ! -d "$LOG_DEST" ]; then
39 echo "Error: $LOG_DEST does not exist, please make it"
40 ERROR=yes
41 else
42 rm -fr $TMP_DEST
43 cp -r $LOG_SRC $TMP_DEST
44 chown -R $USER:nogroup $TMP_DEST
45 chmod -R u=rwX,go=X $TMP_DEST
46 k5start -qtU -f $KEYTAB_DIR/$USER \
47 -- su $USER -c "rsync -a $TMP_DEST/ $LOG_DEST/"
48 rm -fr $TMP_DEST
49 [ "$VERBOSE" = "true" ] && echo " done."
50 fi
51done
52
53if [ "$ERROR" = "yes" ]; then
54 exit 1
55else
56 exit 0
57fi
58