-
Notifications
You must be signed in to change notification settings - Fork 0
/
mirrorExternalDsvr.sh
executable file
·126 lines (111 loc) · 2.8 KB
/
mirrorExternalDsvr.sh
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
#! /bin/bash --
#
# Mirrors remove dockserver directories to a local destination using
# passwordless ssh, which must be set up by the user.
#
# ============================================================================
# $RCSfile$
# $Source$
# $Revision$
# $Date$
# $Author$
# $Name$
# ============================================================================
#
PATH=${PATH}:/bin;
app=$(basename $0);
# Usage message
USAGE="
NAME
$app - mirror remote dockserver directories via passwordless ssh
SYNOPSIS
$app [hx]
DESCRIPTION
-h
show help message
-x
Dry run. Shows which files are to be mirrored, but does NOT actually
mirror them
";
# Default values for options
# Process options
while getopts "hx" option
do
case "$option" in
"h")
echo -e "$USAGE";
exit 0;
;;
"x")
DRY_RUN=1;
;;
"*")
echo -e "Invalid option specified: $option\n$USAGE";
exit 1;
;;
esac
done
# Remove option from $@
shift $((OPTIND-1));
# CONFIGURATION ==============================================================
REMOTE_URL='remote.server.com'; # CHANGE THIS
REMOTE_ROOT='/var/opt/gmc/gliders'; # MAY NEED TO CHANGE THIS
USER='YOUR_USER_NAME'; # CHANGE THIS
SSH_KEY='LOCATION_OF_LOCAL_SSH_KEY'; # CHANGE THIS
RULES='LOCATION_OF_RULES_FILE'; # CHANGE THIS
LOCAL_DEST_ROOT='LOCAL_DESTINATION'; # CHANGE THIS
GLIDERS='GLIDER_NAME'; # CHANGE THIS. SEPARATE MULTIPLE GLIDERS WITH WHITESPACE
REMOTE_DIRS='from-glider logs to-glider';
# ============================================================================
# Validate configuration variables
if [ -z "$LOCAL_DEST_ROOT" -o ! -d "$LOCAL_DEST_ROOT" ]
then
echo "LOCAL_DEST_ROOT is not valid!" >&2;
exit 1;
elif [ -z "$REMOTE_URL" ]
then
echo "REMOTE_URL is not set!" >&2;
exit 1;
elif [ -z "$REMOTE_ROOT" ]
then
echo "REMOTE_ROOT is not set!" >&2;
exit 1;
elif [ -z "$SSH_KEY" -o ! -f "$SSH_KEY" ]
then
echo "SSH_KEY is not a valid ssh key!" >&2;
exit 1;
elif [ -z "$USER" ]
then
echo "USER is not set!" >&2;
exit 1;
elif [ -z "$GLIDERS" ]
then
echo "GLIDERS is not set!" >&2;
exit 1;
elif [ -z "$REMOTE_DIRS" ]
then
echo "REMOTE_DIRS is not set!" >&2;
exit 1;
fi
for GLIDER in $GLIDERS
do
echo "Mirroring Glider: $GLIDER";
for d in $REMOTE_DIRS
do
if [ -n "$DRY_RUN" ]
then
rsync -avz \
--rsh="ssh -i $SSH_KEY" \
--exclude-from=$RULES \
--dry-run \
${USER}@${REMOTE_URL}:${REMOTE_ROOT}/${GLIDER}/${d} \
${LOCAL_DEST_ROOT}/${GLIDER}
else
rsync -avz \
--rsh="ssh -i $SSH_KEY" \
--exclude-from=$RULES \
${USER}@${REMOTE_URL}:${REMOTE_ROOT}/${GLIDER}/${d} \
${LOCAL_DEST_ROOT}/${GLIDER}
fi
done
done