本機同步資料夾
以 /tmp/destination/
為主要, 將 /tmp/source/ 同步
rsync -avr --delete /tmp/destination/ /tmp/source/
- -a, –archive archive mode; equals -rlptgoD (no -H,-A,-X)
- -v, –verbose increase verbosity
- -r, –recursive recurse into directories
- –delete delete extraneous files from destination dirs
- -e, –rsh=COMMAND specify the remote shell to use
將本機資料夾複製到遠端 projects/ 下
rsync -ae "ssh -p 9022" test test@106.185.77.26:/home/test/note/projects/
將遠端的 test 資料夾 sync 到 /tmp
rsync -av -e ssh test@example.com:~/test/ /tmp
- 注意!! test 資料夾後面一定要加
/
- 以上指令不會將 tmp 有但 test 沒有的檔案做刪除, 如果要與 test 完全一樣, 加上
--delete
參數即可
將本地的資料夾 sync 到遠端
rsync -av -e ssh /tmp/test test@example.com:/tmp
同上, 不過指定金鑰
rsync -av -e "ssh -i .ssh/aws-me-tokyo.pem" ~/test ubuntu@my_web:/tmp
如果來源資料夾有些檔案刪除再去做同步後,目的資料夾是不會刪掉的原本存在的檔案,除非加上 --delete
同步到遠端, 指定 port
rsync -av --delete --checksum --rsh=/usr/bin/ssh /tmp test:/tmp -e "ssh -p 3333"
-c, –checksum skip based on checksum, not mod-time & size
以 ssh rsync 到遠端, 如果資料夾不存在自動建立
rsync -avr --rsh='ssh -p41111' reporting/ jx@my-base:/home/m/reporting/
/usr/bin/rsync -rlpvz --delete --exclude-from=/tmp/exclude_file --checksum --rsh=/usr/bin/ssh /home/test/code/ test@remoteServer.com:/var/www/code -e "ssh -p 1234"
exclude
rsync -av --exclude 'modules/qq' --exclude 'modules/cc' /home/test/index /tmp/
exclude file
rsync -av --exclude-from=$HOME/exclude_file /home/test/index /tmp/
$HOME/exclude_file :
.git
.gitignore
.htaccess