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

rsync not deleting Folders in destination

· 52CE 我爱测

I know there are some questings with the same topic here but no answers helped me. First, this is my script. It should copy all files from the source to the destination (preserving all rights, etc). If a file or directory is dele…

问题原文

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

I know there are some questings with the same topic here but no answers helped me.

First, this is my script. It should copy all files from the source to the destination (preserving all rights, etc). If a file or directory is deleted in the source it should also be deleted in the target. Which is not correctly working.

#!/bin/bash
## Basic RSync Command
RCMD="rsync -rulpEXogtzh --stats --delete --force"
DDIR="/tank/bak/s1/archive/"
SDIR="/tank/bak/s1/backup/"
CDAY=`date '+%u'`

echo "Archive Number: ${CDAY}"
echo "Archiving current backup"
$RCMD $SDIR $DDIR/$CDAY

If I have the following directories in the source:

/etc
/home
/root
/usr

and sync them I have the following directories in the target:

/etc
/home
/root
/usr

so this works fine. Now when I delete /usr from the source, my source looks like this:

/etc
/home
/root

but when I run the script again my target still looks like this:

/etc
/home
/root
/usr

so somehow rsync ignores the --delete

rsync Outputs this:

Number of files: 1983645
Number of files transferred: 0
Total file size: 17.69G bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 42.68M
File list generation time: 0.083 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 42.68M
Total bytes received: 4.70K

sent 42.68M bytes  received 4.70K bytes  155.52K bytes/sec
total size is 17.69G  speedup is 414.50

Has anyone an idea why?

Thanks for any answer!

已采纳解答

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

The directory won't be deleted if permissions forbid it, or if the directory is not empty. Often there are files that can't be deleted because they are immutable or otherwise protected. What does ls -a /usr show on the destination?

You might want to try the --force-delete flag, but first run it with -n (dry run mode) to see what it would delete.

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

资料来源与适用范围

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

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

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