-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync.sh
executable file
·50 lines (44 loc) · 1.61 KB
/
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
43
44
45
46
47
48
# sync.sh
# Usage:
# ./sync.sh == see what files will be uploaded, make no changes
# ./sync.sh live == do the upload
set -e
HOME_DIR='/path/to/root/project' # The root directory of the files you want to upload
REMOTE_DIR='/var/www/html/' # The remote root directory to upload to
EXCLUDE_FILE='./sync_excludes.txt' # The file containing bash style excludes patterns
SSH_ID='ssh-config-entry OR [email protected]' # The ssh identity file that will be used
CURR_DIR=$(pwd)'/'
if [ $HOME_DIR != $CURR_DIR ]; then
echo 'Please run from the specified HOME_DIR'
exit
fi
if [ -n "$1" ] && [ $1 == 'live' ]; then
# $1 is not null && equal to 'live'
# ! This does the actual upload
if [ -n "$2" ] && [ $2 == 'down' ]; then
echo '[live] files down ...'
# remote to local
rsync -az --progress --size-only --exclude-from $EXCLUDE_FILE $SSH_ID:$REMOTE_DIR $HOME_DIR
elif [ -n "$2" ] && [ $2 == 'up' ]; then
echo '[live] files up ...'
rsync -az --progress --size-only --exclude-from $EXCLUDE_FILE $HOME_DIR $SSH_ID:$REMOTE_DIR
fi
else
case "$1" in
"down")
echo '[review] files down ...'
# -n == dry-run : show what would change without making any changes
# -i == itemized changes
# remote to local
rsync -ainz --progress --size-only --exclude-from $EXCLUDE_FILE $SSH_ID:$REMOTE_DIR $HOME_DIR | grep \>
;;
"up")
echo '[review] files up ...'
# The shows what files will be uploaded, does not change anything
rsync -ainz --progress --size-only --exclude-from $EXCLUDE_FILE $HOME_DIR $SSH_ID:$REMOTE_DIR | grep \<
;;
*)
echo 'default'
;;
esac
fi