Rsync realizes synchronization of directory files between servers

Rsync realizes synchronization of directory files between servers

Under normal circumstances

There are generally three service environments

  1. dev development environment
  2. test test environment
  3. prod production environment

There are more environments, the inevitable thing is some repeated operations, deployment or something

Can it be directly synchronized to the test environment after the development environment is packaged? (After all, doing too many repetitive things will be annoying)

is allowed

The rsync command can be used directly under linux

You can install cygwin under windows to achieve

copy a picture 

 Here is the operation of synchronizing to the remote server, which is the push on the picture

Take two servers

Local :

Remote :

Requirements: Synchronize the/opt/vue/index.html file and/opt/vue/static directory of to the/opt/dist directory of remote


rsync -avP -e "ssh -i ~/.ssh/130/my.pem"/opt/vue/static/opt/vue/index.html root@

Parameter Description

  • -a --archive: Archive mode, which means recursive transmission and preservation of file attributes. Equivalent to "-rtopgDl"
  • -v: Display detailed information during rsync. You can use "-vvvv" to get more detailed information
  • -P: Display the progress information of the file transfer. (Actually "-P"="--partial --progress", where "--progress" is the display progress information)
  • The my.pem file is the private key to log in to the server. The generation method can be viewed in this article.  SSH logs in to the server through the pem file 

Since I want to operate in real time, what should I do if I don’t want to execute such a script every time

Cooperate with linux timing task crontab, execute it regularly

 Method: Write the command into a script and execute it regularly


vim rsync -avP -e "ssh -i ~/.ssh/130/my.pem"/opt/vue/static/opt/vue/index.html root@192.168. 1.130:/opt/dist
//crontab -e edits the timing task, writes, the following is the synchronization every two minutes

*/2 * * * */root/

If it is a windows environment, you need to install cygwin, which will provide a linux environment on the windows platform

As shown in the figure:

For installation, please refer to

perfect! ! !

Reference: rsync realizes synchronization of directory files between servers-Cloud + Community-Tencent Cloud