forked from cbg-ethz/pangolin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync_sftp
executable file
·49 lines (39 loc) · 1.22 KB
/
sync_sftp
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
#!/bin/bash
configfile=server.conf
usage() { echo "Usage: $0 [-c <configfile>] [filter [...]]" 1>&2; exit $1; }
while getopts "c:h" o; do
case "${o}" in
c) configfile=${OPTARG}
if [[ ! -r ${configfile} ]]; then
echo "Cannot read ${configfile}" 1>&2
usage 1
fi
;;
h) usage 0 ;;
*) usage 1 ;;
esac
done
shift $((OPTIND-1))
. ${configfile}
: ${fileserver:?}
# ${srvport}
: ${expname:?}
: ${basedir:=$(pwd)}
: ${download:?}
: ${parallel:=16}
: ${contimeout:=300}
: ${retries:=10}
: ${iotimeout:=300}
if [[ $( < ~/.netrc ) =~ machine[[:space:]]+${fileserver}[[:space:]]?login[[:space:]]+([^[:space:]]+) ]]; then
username="${BASH_REMATCH[1]}"
else
echo "cannot find login for machine ${fileserver} in ~/.netrc" >&2
exit 1
fi
if (( ${#@} )); then
dir=( "${@/#/ --directory=${expname}/}" )
source="${dir[*]}"
else
source="--directory=${expname}/*"
fi
exec lftp -c "set cmd:move-background false; set net:timeout $(( contimeout / retries)); set net:max-retries ${retries}; set net:reconnect-interval-base 8; set xfer:timeout ${iotimeout}; connect sftp://${username}@${fileserver}${srvport:+:${srvport}}; mirror --continue --no-perms --no-umask --parallel=16 --loop --target-directory=${basedir}/${download} ${source}"