简体   繁体   English

Linux rsync 命令

[英]Linux rsync command

I work now with a Linux Server and an Apple Mac.我现在使用 Linux 服务器和 Apple Mac。 Each morning I update my data on my MacBook with the command rsync -a -v server:~/work_dir ~/ .每天早上我都会使用命令rsync -a -v server:~/work_dir ~/更新我的 MacBook 上的数据。 I looked up the manual already, but I can not found any command which helps me.我已经查阅了手册,但找不到任何可以帮助我的命令。 Because I wanted the command to delete the files which are not any more on the server automatically.因为我希望该命令自动删除服务器上不再存在的文件。 But when I delete a file on the server and run the rsync command, the files is still on my laptop.但是当我删除服务器上的文件并运行rsync命令时,这些文件仍然在我的笔记本电脑上。 Do I use the wrong command?我使用了错误的命令吗? Or do I miss an option?还是我错过了一个选择?

If your script is adapted to look like this,如果你的脚本被改编成这样,

MASTER="server:${HOME}/work_dir"
REPLICA="${HOME}/"

rsync --archive --delete --verbose "${MASTER}" "${REPLICA}"

the --delete option will delete any files existing in REPLICA that do not exist in MASTER. --delete选项将删除 REPLICA 中存在但 MASTER 中不存在的所有文件。 I will assume you meant to have rsync create the directory "work_dir" in your laptop ${HOME} if it did not exist.我假设您打算让 rsync 在您的笔记本电脑 ${HOME} 中创建目录“work_dir”,如果它不存在的话。 Otherwise, as a failsafe, I would create "work_dir" on the laptop and add the trailing "/" to the MASTER definition.否则,作为故障保险,我将在笔记本电脑上创建“work_dir”并将尾随“/”添加到 MASTER 定义中。

Note that there are many modes of behaviour for that delete action, controlling the timing of when the delete occurs.请注意,该删除操作有多种行为模式,用于控制删除发生的时间。

I recommend against using我建议不要使用

--delete-before
--delete-during

unless the REPLICA is a folder intended as a handoff buffer for other downstream processes .除非 REPLICA 是一个文件夹,旨在作为其他下游进程的切换缓冲区

If REPLICA is intended to be a duplicate of MASTER, then it is highly recommended that you use the delete o ptions which preserve all data until after the copying has been verified as good.如果 REPLICA打算成为 MASTER 的副本,那么强烈建议您使用删除选项,该选项会保留所有数据,直到复制被验证为良好为止。 That leaves you with the two options这让你有两个选择

--delete-delay
--delete-after

of which the --delete-delay is likely the preferred choice because it won't force a second scan of the REPLICA to locate the files to be purged.其中--delete-delay可能是首选,因为它不会强制对 REPLICA 进行第二次扫描以定位要清除的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM