3

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!

2

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.

  • Thanks! The problem was in fact, that the directory was not empty. – Marc Vollmer Jul 7 '14 at 16:09
  • As of 2019 rsync version 3.1.1/ protocol version 31 has no option --force-delete, you have to use --force --delete – Fabian Thommen Feb 26 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.