在 Debian 系统里做“文件同步”有很多种方式,取决于你是本地同步、远程同步、实时同步还是定时同步。下面按常见场景给你总结一下。
rsync -av /source/ /dest/
-a:归档模式(保留权限、时间等)-v:显示过程/source/ 和 /source 区别(是否包含目录本身)rsync -avz -e ssh user@remote:/path/ /local/path/
或反向:
rsync -avz /local/path/ user@remote:/path/
rsync -av --delete /src/ /dst/
crontab -e
例如每天 3 点同步:
0 3 * * * rsync -avz /data/ user@backup:/backup/
apt install inotify-tools
示例脚本:
while inotifywait -r -e modify,create,delete /data; do
rsync -avz /data/ user@remote:/backup/
done
apt install lsyncd
配置 /etc/lsyncd/lsyncd.conf.lua:
sync{
default.rsync,
source="/data",
target="user@remote:/backup",
rsync={rsh="/usr/bin/ssh"}
}
启动:
systemctl start lsyncd
apt install unison
unison /dir1 ssh://remote//dir2
apt install syncthing
http://localhost:8384| 需求 | 推荐 |
|---|---|
| 备份 | rsync |
| 实时 | lsyncd |
| 双向 | Syncthing / unison |
| 大规模 | GlusterFS |
如果你能告诉我:
我可以直接给你一套可复制的配置。