-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackupGT.target
executable file
·92 lines (76 loc) · 3.31 KB
/
backupGT.target
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
#! /bin/sh
###############################################################
# script for remote backup of local modules/shares
###############################################################
. ${0%/*}/target.conf
KEY="$1" # a key may have been optionally specified
ELAPSED_START=`$ELAPSED_CMD`
###############################################################
# utilities
###############################################################
logHeader () {
# pass as $* the original command line
[ "$REQUEST_MODULE" = "_listModules" ] && printf "\n\n"
echo "===== begin ======================================================="
echo `$DATE_CMD`: command line = "$@"
#echo `$DATE_CMD`: SSH_ORIGINAL_COMMAND = "$SSH_ORIGINAL_COMMAND"
#echo `$DATE_CMD`: KEY = "$KEY"
echo `$DATE_CMD`: module spec = "$MODULE_SPEC"
echo `$DATE_CMD`: request module = "$REQUEST_MODULE"
echo `$DATE_CMD`: request parms = "$REQUEST_PARMS"
echo `$DATE_CMD`: request method = "$REQUEST_METHOD"
} >> $LOG_PATH
logFooter () {
echo "`$DATE_CMD`: complete (duration = $ELAPSED_MIN minutes)"
echo "===== end ========================================================="
echo ""
} >> $LOG_PATH
######################################################################
# main
# - if we are in a restricted environment there may be no SSH_ORIGINAL_COMMAND
# so we have to re-read the module spec from the modList
# - note information is passed from the client by using the 'ssh command'
# but if rsync is being used it will have 5 parameters
# '<hostname> rsync --server --daemon .' appended to it
###############################################################
if [ -n "$SSH_ORIGINAL_COMMAND" ]; then
MODULE_SPEC="$SSH_ORIGINAL_COMMAND"
elif [ -n "$KEY" ]; then
# restricted environment but caller supplied key so run target.modList
# and search for the line with the specified key
# append a space to each key so that key=1 doesn't match key=11, key=123, etc
MODULE_SPEC="`${0%/*}/target.modList | sed 's/\(key=[0-9]*\)/\1 /' | grep 'key='$KEY' '`"
else
# restricted environment but caller supplied no key so assume caller wants _listModules
MODULE_SPEC="`printf '%s\t' '_listModules'`"
fi
if echo "$MODULE_SPEC" | grep -vq ' ' ; then
echo "ERROR: protocol violated MODULE_SPEC missing tab delimeter" | tee -a $LOG_PATH 1>&2
fi
REQUEST_MODULE=`echo "$MODULE_SPEC" | sed 's/\([^[:blank:]]*\) *\(.*\)/\1/'` #cut -d " " -f 1
REQUEST_PARMS=` echo "$MODULE_SPEC" | sed 's/\([^[:blank:]]*\) *\(.*\)/\2/'` #cut -d " " -f 2
REQUEST_METHOD=`echo $REQUEST_PARMS | parseAssignment method`
logHeader "$0" "$@"
if [ "$REQUEST_MODULE" = "_listModules" ]; then
echo "`$DATE_CMD`: listing modules" >> $LOG_PATH
if [ -z "$REQUEST_PARMS" ]; then
${0%/*}/target.modList
else
modName=`echo "$REQUEST_PARMS" | parseAssignment modName`
${0%/*}/target.modList | grep "^$modName"
fi
else
if [ -f "${PROC_PATH_PREFIX}.${REQUEST_MODULE}" ]; then
. "${PROC_PATH_PREFIX}.${REQUEST_MODULE}"
fi
case $REQUEST_METHOD in
rsync) module_rsync_process ;;
tar) module_tar_process ;;
zfs|zfs.rsync) module_zfs_process ;;
esac
fi
rc=$?
ELAPSED_END=`$ELAPSED_CMD`
ELAPSED_MIN=$(( (ELAPSED_END - ELAPSED_START) / 60 ))
logFooter
exit $rc