大网数据广告活动
服务器运维问答

Rsync --link-dest create folder only when there is something to update

· 52CE 我爱测

Firstly, I have a hard time understanding what the --update parameter does. I thought that without it, it would logically update any file that changes and I believe that's what it does, so why does the --update parameter even exi…

问题原文

原帖链接 · Ulukai · CC BY-SA 3.0

Firstly, I have a hard time understanding what the --update parameter does. I thought that without it, it would logically update any file that changes and I believe that's what it does, so why does the --update parameter even exist?

Secondly, related to what I asked because I thought it would solve my issue, but it doesn't, I have a bunch of config files that I would want updated into a different folder every time they change by having a cronjob that runs the below command every hour or every day, this way I can have a few previous versions in case something goes awry. The problem is that these files rarely change, but rsync creates another folder with hard links regardless it changes or not, which is a bit annoying because then you have loads of folders of the same thing, even them being a hard link and not taking space, it creates a lot of clutter.

Isn't there any way to stop rsync --link-dest from doing this? That is, create the folder only if anything changes, otherwise do nothing. Seems like a pretty basic case scenario so I would have thought there is an easy way to do this with a parameter, but I can't find the answer anywhere.

rsync -azP --delete --stats --update --log-file=/var/log/rsync/apacheconfdate +%F_%T.log -e "ssh -i /home/user/.ssh/id_rsa" /etc/apache2/sites-available --link-dest=/mnt/backup/apache2/apache [email omitted]:/mnt/backup/apache2/apachedate +%F_%T.log

已采纳解答

原帖链接 · shodanshok · CC BY-SA 3.0

Regarding --update, the rsync man page is very clear:

-u, --update: skip files that are newer on the receiver. This forces rsync to skip any files which exist on the destination and have a modified time that is newer than the source file. (If an existing destination file has a modification time equal to the source file's, it will be updated if the sizes are different.)

Without this option, an old file on src can overwrite a newer file on dst. Using this option, you are sure that newer files are never overwritten by older version.

For your second problem, simply avoid using --link-desk. The entire point of this option is to have a complete directory/file tree without have to pay the space of a true, full copy. If you don't want a complete tree each time, but you only want to see the changed files/dirs, avoid using --link-desk

Moreover, for added efficiency in the file transfer process, you may use --compare-dest:

--compare-dest=DIR This option instructs rsync to use DIR on the destination machine as an additional hierarchy to compare destination files against doing transfers (if the files are missing in the destination directory). If a file is found in DIR that is identical to the sender's file, the file will NOT be transferred to the destination directory. This is useful for creating a sparse backup of just files that have changed from an earlier backup.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-01-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。