apache-sync-logs: copy to a temp dir, set perms, and then copy over to AFS
[clinton/scripts.git] / apache-sync-logs
CommitLineData
d2462e94 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
b7036601 8kdestroy > /dev/null 2>&1
d2462e94 9unlog
10
b7036601 11#VERBOSE=true
12VERBOSE=false
13
14LOCAL_LOG_DIR=/var/log/apache2
15KEYTAB_DIR=/etc/keytabs/user.daemon
16AFS_USER_DIR=/afs/hcoop.net/user
17
18for A in $(find $LOCAL_LOG_DIR/user -mindepth 3 -maxdepth 3 -print); do
19 USER=`basename $A`
20 PATHBITS=`echo $USER | head -c 1`/`echo $USER | head -c 2`/$USER
6d0a0367 21 LOG_SRC=$A/apache/log
b7036601 22 LOG_DEST=$AFS_USER_DIR/$PATHBITS/logs/apache/
6d0a0367 23 TMP_DEST=$LOG_SRC.tmp
b7036601 24
25 if [ "$VERBOSE" = "true" ]; then
26 echo
27 echo "=============================================================================="
28 echo "syncing logs for $USER from $A"
29 echo " to $LOG_DEST ..."
30 fi
31
b7036601 32 if [ ! -d "$LOG_DEST" ]; then
33 echo "Error: $LOG_DEST does not exist, please make it"
f9be7472 34 exit 1
b7036601 35 else
6d0a0367 36 rm -fr $TMP_DEST
37 cp -a $LOG_SRC $TMP_DEST
38 chown -R $USER $TMP_DEST
39 chmod -R u+rw $TMP_DEST
b7036601 40 k5start -qtU -f $KEYTAB_DIR/$USER \
6d0a0367 41 -- su $USER -c "rsync -a $TMP_DEST/ $LOG_DEST/"
42 rm -fr $TMP_DEST
b7036601 43 [ "$VERBOSE" = "true" ] && echo " done."
f9be7472 44 exit 0
b7036601 45 fi
d2462e94 46done