forked from ly525/luban-h5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync2server.sh
executable file
·104 lines (95 loc) · 2.26 KB
/
sync2server.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#! /bin/sh
###
# @Author: ly525
# @Date: 2020-01-12 11:21:11
# @LastEditors : ly525
# @LastEditTime : 2020-01-12 16:30:08
# @FilePath: /luban-h5/sync2server.sh
# @Github: https://github.com/ly525/luban-h5
# @Description: script for sync source code from local to server
# @Copyright 2018 - 2019 luban-h5. All Rights Reserved
###
SOURCE_PATH=/centos/luban-h5
PEM_PATH=~/.ssh/id_rsa
# usage:
# $ ./sync2server.sh host --dry
# $ ./sync2server.sh host --source
usage() {
N=$(basename "$0")
echo "Usage: $N host [--source|--dry]" >&2
exit 1
}
if [ $# != 2 ]; then
echo $# $1 $2
usage
fi
SERVER_HOST=$1
# 正式同步
sync_source() {
echo "sync_source to $SERVER_HOST"
rsync\
-atzvhcP\
-e "ssh -i $PEM_PATH"\
--exclude "node_modules"\
--exclude "build*"\
--exclude "public"\
--exclude "dist"\
--exclude ".git"\
--exclude ".cache"\
--exclude ".DS_Store"\
--exclude "*.apk"\
--exclude "*.bak"\
--exclude "logs"\
--exclude "*.pyc"\
--exclude "local_settings.py"\
--exclude "*.swp"\
--exclude "*.md"\
--exclude "sync.sh"\
--exclude ".idea"\
--exclude ".vscode"\
--exclude "*.db"\
--exclude "db.sqlite3"\
--exclude "vagrant"\
./* centos@$SERVER_HOST:$SOURCE_PATH
}
#!zh: 正式同步代码前的试运行,不会真正同步代码,主要用来检测本地和服务器代码有哪些不同
#!en: dry run before sync code
sync_sourcedryrun() {
echo "sync_source to $SERVER_HOST"
rsync\
-atzvhncP\
-e "ssh -i $PEM_PATH"\
--exclude "node_modules"\
--exclude "dist"\
--exclude "build*"\
--exclude "public"\
--exclude ".DS_Store"\
--exclude ".git"\
--exclude ".cache"\
--exclude "*.apk"\
--exclude "*.bak"\
--exclude "logs"\
--exclude "*.pyc"\
--exclude "local_settings.py"\
--exclude "*.swp"\
--exclude "*.md"\
--exclude "sync.sh"\
--exclude ".idea"\
--exclude ".vscode"\
--exclude "*.db"\
--exclude "db.sqlite3"\
--exclude "vagrant"\
./* centos@$SERVER_HOST:$SOURCE_PATH
}
case "$2" in
--source)
sync_source
;;
--dry)
sync_sourcedryrun
;;
*)
usage
;;
esac
exit 0