-
Notifications
You must be signed in to change notification settings - Fork 6
/
sync.sh
executable file
·42 lines (32 loc) · 1022 Bytes
/
sync.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
#!/bin/bash
set -e
set_dir () { DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; }
safe_source () { source $1; set_dir; }
set_dir
if [[ $(id -u) > 0 ]]; then sudo $0 "$@"; exit; fi
safe_source $DIR/aktos-bash-lib/basic-functions.sh
safe_source $DIR/aktos-bash-lib/fs-functions.sh
safe_source $DIR/aktos-bash-lib/ssh-functions.sh
safe_source $DIR/common.sh
$DIR/create-ssh-config
sync_dir=$(get_relative $PWD $(realpath $DIR/../sync-root))
source="/"
RSYNC="nice -n19 ionice -c3 rsync"
die () {
errcho "ERROR: "
errcho "ERROR: $@"
errcho "ERROR: "
show_help
exit 255
}
conn_method=$1
[ $conn_method ] || die "Connection method must be provided"
if [[ ! -d $sync_dir ]]; then
die "sync directory must exist: $sync_dir"
else
echo_green "Using sync directory: $sync_dir"
fi
start_timer
$RSYNC -aHAXvPh --delete --delete-excluded --exclude-from "$DIR/exclude-list.txt" \
--rsh="$SSH" --rsync-path="sudo rsync" target_$conn_method:$source $sync_dir
show_timer "sync completed in:"