同步server和自己电脑的文件
Here’s a basic example of how you might do this:
两边都安装rsync:
-
First, make sure that
rsyncis installed on both systems.On your Linux server you can install it using a package manager like
apt:sudo apt update sudo apt install rsyncOn 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
rsyncto transfer a directory from the Linux server to your MacBook.rsync -avz -e ssh user@your_server:/path/to/dir /path/to/local/dirIn this command:
-astands for “archive” mode which ensures that symbolic links, devices, permissions, ownerships, modification times, ACLs, and extended attributes are preserved.-vstands for “verbose” mode which provides detailed information about the amount and names of the data being transferred.-zstands for “compress” which compresses data before sending it over the network.-e sshuses SSH for the data transfer.user@your_server:/path/to/diris the source directory on the Linux server./path/to/local/diris 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.
文章介绍了如何使用rsync工具通过SSH在Linux服务器和MacOS之间进行增量文件同步。首先确保两边系统都安装了rsync,然后在MacOS上通过Homebrew安装。接着,使用带有参数的rsync命令(-a,-v,-z)通过SSH连接从服务器拉取文件夹。如果SSH端口非默认,需要指定端口号。rsync不会实现实时同步,若需实时同步,建议使用lsyncd。

6059

被折叠的 条评论
为什么被折叠?



