-
Notifications
You must be signed in to change notification settings - Fork 0
/
bpupload
55 lines (48 loc) · 1.6 KB
/
bpupload
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
# Upload Data to BigPurple
bpupload() {
# Initialize variables
local local_data_dir=""
local remote_project_dir=""
local remote_user="${REMOTE_USER:-mm12865}"
local remote_host="${REMOTE_HOST:-bigpurple.nyumc.org}"
# Usage message
usage() {
echo "Usage: bpupload -l <local_data_dir> -r <remote_project_dir>"
echo "Options:"
echo " -l Local data directory"
echo " -r Remote project directory"
echo " -h Show this help message"
}
# Parse options
# Parse options
while getopts "l:r:h" opt; do
case $opt in
l) local_data_dir="$OPTARG" ;;
r) remote_project_dir="$OPTARG" ;;
h) usage
return 0 ;;
*) usage
return 1 ;;
esac
done
# Check if required arguments are provided
if [ -z "$local_data_dir" ] || [ -z "$remote_project_dir" ]; then
echo "Error: Both local data directory and remote project directory are required."
show_help
return 1
fi
# Validate local data directory
if [ ! -d "$local_data_dir" ]; then
echo "Error: Local data directory '$local_data_dir' does not exist."
return 1
fi
# Use rsync to upload the data folder
rsync -avz --progress "$local_data_dir" "$remote_user@$remote_host:$remote_project_dir"
local rsync_exit_code=$?
if [ $rsync_exit_code -eq 0 ]; then
echo "Data folder uploaded successfully."
else
echo "Error: Failed to upload data folder. rsync exit code: $rsync_exit_code"
return $rsync_exit_code
fi
}