-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrsync_upload.sh
58 lines (52 loc) · 1.18 KB
/
rsync_upload.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
#!/bin/bash
set -e
# Define constants
RSYNC="rsync"
DEFAULT_TIMEOUT=30
RSYNC_EXCLUDES=(
"--exclude=jobs/*/bin"
"--exclude=jobs/*/data"
"--exclude=jobs/*/logs"
)
RSYNC_OPTIONS=(
"--timeout=$DEFAULT_TIMEOUT"
"--inplace"
"--whole-file"
"--checksum"
"--recursive"
"--force"
"--delete-after"
"--delete"
"--group"
"--owner"
"--executability"
"--compress"
)
# Check required variables
if [[ -z "$SSH_KEY" || -z "$AGENT_DIR" || -z "$SSH_USER" || -z "$AGENT_IP" || -z "$BUCKET" ]]; then
echo "Error: Missing required environment variables (SSH_KEY, AGENT_DIR, SSH_USER, AGENT_IP, or BUCKET)." >&2
exit 1
fi
# Enable sudo for rsync if specified
if [[ "${USE_SUDO:-0}" -eq 1 ]]; then
RSYNC="sudo rsync"
fi
# Validate input arguments
if [[ $# -lt 1 ]]; then
echo "Usage: $0 <rule_file>" >&2
exit 1
fi
RULE_FILE=$1
# Construct the rsync command
RSYNC_CMD=(
$RSYNC -v
--rsync-path="$RSYNC"
"${RSYNC_OPTIONS[@]}"
"${RSYNC_EXCLUDES[@]}"
--filter="merge /tmp/${RULE_FILE}.txt"
--rsh="ssh -o BatchMode=true -o ConnectTimeout=10 -i /bucket/$SSH_KEY"
"$AGENT_DIR/"
"$SSH_USER@$AGENT_IP:/opt/agent/$BUCKET"
)
# Execute the rsync command
"${RSYNC_CMD[@]}" > /dev/null