Commit c0cad259cf785a269ebb8c0aac85d393d45a4630

Authored by ly525
1 parent 5ca00069

chore: add sync2server.sh to support sync local code to server

Showing 1 changed file with 104 additions and 0 deletions
sync2server.sh 0 → 100755
  1 +#! /bin/sh
  2 +
  3 +###
  4 + # @Author: ly525
  5 + # @Date: 2020-01-12 11:21:11
  6 + # @LastEditors : ly525
  7 + # @LastEditTime : 2020-01-12 16:29:05
  8 + # @FilePath: /luban-h5/sync2server.sh
  9 + # @Github: https://github.com/ly525/luban-h5
  10 + # @Description: script for sync source code from local to server
  11 + # @Copyright 2018 - 2019 luban-h5. All Rights Reserved
  12 + ###
  13 +SOURCE_PATH=/centos/luban-h5
  14 +PEM_PATH=~/.ssh/id_rsa
  15 +
  16 +# usage:
  17 +# $ ./sync2server.sh host --dry
  18 +# $ ./sync2server.sh host --source
  19 +
  20 +usage() {
  21 + N=$(basename "$0")
  22 + echo "Usage: $N host [--source|--dry]" >&2
  23 + exit 1
  24 +}
  25 +
  26 +if [ $# != 2 ]; then
  27 + echo $# $1 $2
  28 + usage
  29 +fi
  30 +
  31 +SERVER_HOST=$1
  32 +
  33 +# 正式同步
  34 +sync_source() {
  35 + echo "sync_source to $SERVER_HOST"
  36 + rsync\
  37 + -atzvhcP\
  38 + -e "ssh -i $PEM_PATH"\
  39 + --exclude "node_modules"\
  40 + --exclude "build*"\
  41 + --exclude "public"\
  42 + --exclude "dist"\
  43 + --exclude ".git"\
  44 + --exclude ".cache"\
  45 + --exclude ".DS_Store"\
  46 + --exclude "*.apk"\
  47 + --exclude "*.bak"\
  48 + --exclude "logs"\
  49 + --exclude "*.pyc"\
  50 + --exclude "local_settings.py"\
  51 + --exclude "*.swp"\
  52 + --exclude "*.md"\
  53 + --exclude "sync.sh"\
  54 + --exclude ".idea"\
  55 + --exclude ".vscode"\
  56 + --exclude "*.db"\
  57 + --exclude "db.sqlite3"\
  58 + --exclude "vagrant"\
  59 + ./* root@$SERVER_HOST:$SOURCE_PATH
  60 +}
  61 +
  62 +#!zh: 正式同步代码前的试运行,不会真正同步代码,主要用来检测本地和服务器代码有哪些不同
  63 +#!en: dry run before sync code
  64 +sync_sourcedryrun() {
  65 + echo "sync_source to $SERVER_HOST"
  66 + rsync\
  67 + -atzvhncP\
  68 + -e "ssh -i $PEM_PATH"\
  69 + --exclude "node_modules"\
  70 + --exclude "dist"\
  71 + --exclude "build*"\
  72 + --exclude "public"\
  73 + --exclude ".DS_Store"\
  74 + --exclude ".git"\
  75 + --exclude ".cache"\
  76 + --exclude "*.apk"\
  77 + --exclude "*.bak"\
  78 + --exclude "logs"\
  79 + --exclude "*.pyc"\
  80 + --exclude "local_settings.py"\
  81 + --exclude "*.swp"\
  82 + --exclude "*.md"\
  83 + --exclude "sync.sh"\
  84 + --exclude ".idea"\
  85 + --exclude ".vscode"\
  86 + --exclude "*.db"\
  87 + --exclude "db.sqlite3"\
  88 + --exclude "vagrant"\
  89 + ./* root@$SERVER_HOST:$SOURCE_PATH
  90 +}
  91 +
  92 +case "$2" in
  93 + --source)
  94 + sync_source
  95 + ;;
  96 + --dry)
  97 + sync_sourcedryrun
  98 + ;;
  99 + *)
  100 + usage
  101 + ;;
  102 +esac
  103 +
  104 +exit 0
0 105 \ No newline at end of file
... ...