Last active
January 14, 2016 22:18
-
-
Save moonwatcher/cdd04e95f75375501471 to your computer and use it in GitHub Desktop.
Scrip for pulling data from the scopes into the storage server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SOURCE="$1" | |
TARGET="$2" | |
NAME="$3" | |
EMAIL="eegi" | |
LOG_DIR="/var/log/scope/$NAME"; | |
FILTER_FILE="/var/lib/scope/filter/$NAME" | |
TIMESTAMP="$(date +%Y-%m-%d-%H-%M-%S)"; | |
CHMOD="a+rwx,g+rwx,o-w" | |
LOG_FILE="$LOG_DIR/$TIMESTAMP.log"; | |
SUBJECT="$NAME $TIMESTAMP" | |
# --recursive recurse into directories | |
# --times preserve modification times | |
# --omit-dir-times omit directories from --times | |
# --prune-empty-dirs prune empty directory chains from file-list | |
# --itemize-changes output a change-summary for all updates | |
# --partial keep partially transferred files | |
ARGUMENTS="--recursive --times --prune-empty-dirs --omit-dir-times --itemize-changes --partial" | |
# initial command | |
COMMAND="rsync $ARGUMENTS --log-file $LOG_FILE $SOURCE $TARGET" | |
# initial rm command | |
RM_COMMAND="rm -rf $SOURCE" | |
# if a chmod command exist | |
[ -n "$CHMOD" ] && COMMAND="$COMMAND --chmod $CHMOD" | |
# if the filter file exist add it | |
[ -e "$FILTER" ] && COMMAND="$COMMAND --filter '$FILTER_FILE'" | |
# create the log directory if it doesn't exist | |
[ -d $LOG_DIR ] || mkdir -p $LOG_DIR | |
# write the exectuted command to the log | |
echo "$COMMAND" > $LOG_FILE | |
# execute the commnd | |
$COMMAND | |
# get the rsync result | |
# 0 Success | |
# 1 Syntax or usage error | |
# 2 Protocol incompatibility | |
# 3 Errors selecting input/output files, dirs | |
# 4 Requested action not supported | |
# 5 Error starting client-server protocol | |
# 6 Daemon unable to append to log-file | |
# 10 Error in socket I/O | |
# 11 Error in file I/O | |
# 12 Error in rsync protocol data stream | |
# 13 Errors with program diagnostics | |
# 14 Error in IPC code | |
# 20 Received SIGUSR1 or SIGINT | |
# 21 Some error returned by waitpid() | |
# 22 Error allocating core memory buffers | |
# 23 Partial transfer due to error | |
# 24 Partial transfer due to vanished source files | |
# 25 The --max-delete limit stopped deletions | |
# 30 Timeout in data send/receive | |
# 35 Timeout waiting for daemon connection | |
RESULT=$? | |
if [ "$RESULT" == "0" ]; then | |
echo "rsync completed successfully. proceeding to remove source." >> $LOG_FILE | |
SUBJECT="$SUBJECT completed successfully" | |
# This is where we delete the source... | |
$RM_COMMAND | |
RM_RESULT=$? | |
if [ "$RM_RESULT" == "0" ]; then | |
SUBJECT="$SUBJECT and removed successfully" | |
else | |
SUBJECT="$SUBJECT and failed to remove" | |
fi | |
else | |
echo "rsync failed with error code $RESULT. Not removing source." >> $LOG_FILE | |
SUBJECT="$SUBJECT failed" | |
fi | |
cat $LOG_FILE | mail -s "$SUBJECT" "$EMAIL" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment