Rsync tries to delete everything

using this script:

rsync -r -t -v -a --delete --update  --exclude ".*" \
--exclude-from=/home/pc/Install/LINUX/BACKUP/excludes /home/pc/ \
/media/pc/DIESEL/pc/

It does this:

cannot delete non-empty directory: pc/Sync/AGS
cannot delete non-empty directory: pc/Sync/AGS
cannot delete non-empty directory: pc/Sync
cannot delete non-empty directory: pc/Sync
cannot delete non-empty directory: pc/SELL
cannot delete non-empty directory: pc/SELL
cannot delete non-empty directory: pc/Pictures
cannot delete non-empty directory: pc/Pictures
cannot delete non-empty directory: pc/Install
cannot delete non-empty directory: pc/Install
cannot delete non-empty directory: pc/Downloads
cannot delete non-empty directory: pc/Downloads
cannot delete non-empty directory: pc/Documents
cannot delete non-empty directory: pc/Documents
cannot delete non-empty directory: pc/Desktop
cannot delete non-empty directory: pc/Desktop
cannot delete non-empty directory: pc/Desires
cannot delete non-empty directory: pc/Desires
cannot delete non-empty directory: pc/BUY
cannot delete non-empty directory: pc/BUY
cannot delete non-empty directory: pc
...

You likely want --force - from the man page:

--force force deletion of dirs even if not empty

Also, -a already includes -r and -t.

So maybe simplify to:

rsync -av --delete --update --exclude ".*" --exclude-from=/home/pc/Install/LINUX/BACKUP/excludes /home/pc/ /media/pc/DIESEL/pc

I would suggest that whatever changes you make should be tested first to ensure the expected outcome is what you want.

Add --dry-run to the end of the line and test.

If all is good, simply remove to let the script run normally.

2 Likes

Thanks, but I do not see how that helps.

I am looking for some advice about why this command should be doing these deletes.

What are you expecting, and why?

It might be helpful if you actually ask a question :wink:

Just dumping two logs without any context here doesn’t make us magically know what you are after…

2 Likes

Sorry everyone. And thanks for the replies. Should have said more. It seemed obvious - which is always a stupid thought!

Running Mint MATE all fresh and up to date.

This is supposed to just back up /home/pc

There are a number of exclusions listed in the …/ excludes

But it is trying to delete /home/pc - the thing I am trying to backup.

And all the things it is trying to delete are things I am trying to back up. (and none are in the excludes, of course)

The suggestion from popey would help it delete the things I do not want deleted. But thanks for the idea, will be useful somewhere.

Of course. Sorry.

Objective is to backup /home/pc

Why is it trying to delete the very directories I want to back up. It goes on to do the backup. But the presence of this list of failed deletes suggests something is very wrong.

are you sure it is referring to /home/pc ? the --delete option deletes on the target, not at the source usually … (and the output doesn’t really tell you the full path )

3 Likes

That logs it is probably showing folders that rsync is trying to delete at the destination. This is most likely because those folders are not present on the origin anymore.

If you are trying to create a script that will backup files from time to time, maybe using --delete is not the best option as it will keep the destination sync’d with the origin and this is not the best backup strategy. Of course, this depends on what are your needs.

1 Like

[andrew-1dtv] here. Had to start a new account as could not post for 15 hours. [So helpful for those of us with Ubuntu forum for a decade who are migrating. ]

Thanks. I understand that. It is trying to delete /home/pc on the target.

But the whole idea is to incrementally backup /home/pc on the target.

I cannot fathom why it begins by trying to delete it.

Plus the backup process is taking an absolute age, which may or may not have anything to do with it.

[andrew-1dtv] here. Had to start a new account as could not post for 15 hours. [So helpful for those of us with Ubuntu forum for a decade who are migrating. ]

Thanks. This is the output from rscync that I have posted.

The origin is my main home directory. Nothing has been deleted there.

And yes, I am trying to keep the thumb drive precisely synced with the home directory. That way if I reorganise a big directory, or just rename it, I do not get the thumb drive duplicating stuff and running out of space. I do my backups online with dropbox and pCloud.

You mention wanting to keep a precise sync on your target, yet using excludes & update can result in variations between source & target. Not a bad thing, quite useful depending on your needs.

Regarding --delete:
Imagine this. You rename a directory on source, --delete will delete the original directory & its contents on your target, because the directory does not exist on source anymore, then the new directory & contents are rewritten to target. Rsync doesn’t move data around, or rename directories like gui file managers act. To see this in action, give a -vvv and a -n (dry-run). This may also give you a clearer visual whether your paths & excludes are correct. You have a lot going on in your command.

When you tell rsync to --delete, it tries.
Could we have a single, itty bitty file somewhere in the hierarchy that is owned by root, or George or some other user? If so, rsyc --delete will get hung up without elevated permissions.

Careful with --delete, it can wipe your target or source if you have a mistake in you command path statements. Accidental disaster is avoided with -n and an examination of what would have happened. I almost wiped a 4tb HDD once, but -n saved me.

4 Likes

i assume the deletes are being applied to the target, not the source. if you have a case of source files being deleted, alert us and say that specifically because that is not possible as far as we know (unless you get source and target swapped on the command line).

what makes you think “/home/pc” (at the target) is being deleted? all i see is it trying to delete stuff in a SUBdirectory named “pc”. could there be such a subdirectory named “pc” on that device (that maybe you recently had and renamed) ? maybe you should make a list of what is there and chech it out. one sore point about rsync is that if you rename a big (or small, or huge) directory, it tries to upload it all, again, and delete the old stuff. maybe you should change “–delete” to “–delete-after”.

a really good backup tool would manage a database with checksums of the backup and when new files need to be uploaded with matching dates and sizes as other files, it checksums the new one to see if a move, or copy, or even a hard link, in the backup, will make things right without using all that bandwidth.

Thanks for this. Great points.

The idea is to keep the thumb drive synced with the main drive. Excludes are just to keep off the massive files like distro isos so the drive does not get filled up.

Great tip about -n. Lucky escapes are indeed the moment to take stock and put in one more cautionary step!

Thanks. You must be right. Of course. :slight_smile:

I ran it again later and the lines I posted did not recur.

Will look into --delete -after.

Very grateful for all the help.

A post was split to a new topic: How to launch pcloud from startup