在Linux系统上设置文件同步有多种方法,以下是几种常用的解决方案:
rsync -avz /source/directory/ user@remote_host:/destination/directory/
-a
: 归档模式,保留权限、时间戳等-v
: 详细输出-z
: 压缩传输crontab -e
# 添加以下内容,每天凌晨2点同步
0 2 * * * rsync -avz /source/ user@remote:/destination/
rsync -avz --exclude='*.tmp' --exclude='temp/' /source/ user@remote:/destination/
安装:
sudo apt install lsyncd # Debian/Ubuntu
sudo yum install lsyncd # CentOS/RHEL
配置示例(/etc/lsyncd.conf
):
settings {
logfile = "/var/log/lsyncd.log",
statusFile = "/var/log/lsyncd-status.log",
statusInterval = 20
}
sync {
default.rsync,
source = "/source/directory",
target = "user@remote_host:/destination/directory",
rsync = {
archive = true,
compress = true,
verbose = true
}
}
启动服务:
sudo systemctl start lsyncd
sudo systemctl enable lsyncd
安装:
# Debian/Ubuntu
sudo apt install syncthing
# CentOS/RHEL
sudo yum install syncthing
启动并设置开机自启:
systemctl --user start syncthing
systemctl --user enable syncthing
访问Web界面: http://localhost:8384
安装:
sudo apt install unison # Debian/Ubuntu
sudo yum install unison # CentOS/RHEL
基本用法:
unison /local/directory ssh://user@remote//remote/directory
# 配置
rclone config
# 同步到Google Drive
rclone sync /local/path remote:path
sudo apt install nextcloud-client # Debian/Ubuntu
--bwlimit
限制带宽(rsync)需要更具体的解决方案或有任何疑问,请提供您的具体使用场景和需求。