同步server和自己电脑的文件
Here’s a basic example of how you might do this:
两边都安装rsync:
-
First, make sure that
rsync
is installed on both systems.On your Linux server you can install it using a package manager like
apt
:sudo apt update sudo apt install rsync
On macOS, you can install it using Homebrew:
brew install rsync
直接在电脑端运行rsync拉取服务器的文件夹:
- 这样就会增量的把dir里面的文件同步到自己电脑的dir文件夹下:
-
Now, assuming you have SSH access from your MacBook to your Linux server, you can use
rsync
to transfer a directory from the Linux server to your MacBook.rsync -avz -e ssh user@your_server:/path/to/dir /path/to/local/dir
In this command:
-a
stands for “archive” mode which ensures that symbolic links, devices, permissions, ownerships, modification times, ACLs, and extended attributes are preserved.-v
stands for “verbose” mode which provides detailed information about the amount and names of the data being transferred.-z
stands for “compress” which compresses data before sending it over the network.-e ssh
uses SSH for the data transfer.user@your_server:/path/to/dir
is the source directory on the Linux server./path/to/local/dir
is the destination directory on your MacBook.
如果服务器ssh端口不是默认的22:
rsync -avz -e 'ssh -p 2222' user@your_server:/path/to/dir /path/to/local/dir
This rsync
command will need to be run from your MacBook. If you want this to happen automatically at regular intervals, you can set up a cron job on your MacBook to run the command.
Note that rsync
does not provide real-time synchronization, it simply synchronizes at the point the command is run. If you need real-time file synchronization, you might want to look into other solutions like lsyncd
.