Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The --remove-source-files destroys data when source & destination are the same (data loss!) #359

Closed
samueloph opened this issue Aug 17, 2022 · 1 comment

Comments

@samueloph
Copy link
Contributor

Hello,

I'm forwarding this bug report I've received on Debian:
https://bugs.debian.org/1016102

I'm verbatim copying the report below:

I accidentally ran:

  $ rsync -va --progress --remove-source-files "$dir_with_many_files" "$dir_with_many_files"

Due to a typo when using bash history substitution, the source and
destination were both directories and they both named the same
directory.

The expectation is that rsync should detect movement from A to A and
do nothing apart from warning the user that there is nothing to do.
Instead, because of the “--remove-source-files” option, rsync DESTROYS
all the files in "$dir_with_many_files" irrevokably.

There needs to be a safeguard that prevents --remove-source-files from
having effect if:

 * Files are not copied to the destination (for any reason)
 * The source and destination are the same

I suffered data loss because of this.  At the very least, if it’s
really intended for “rsync --remove-source-files $A $A” to effectively
behave like “rm -rf $A/*”, there AT LEAST needs to be a very loud
warning prompting the user for confirmation. But I conjecture that there
never is a legit scenario where “rsync --remove-source-files” simply
destroys files without safely ensuring they exist somewhere in the
end.

The issue can be reproduced with:

mkdir testdir-remove-source-files-1016102 && touch testdir-remove-source-files-1016102/file-a && touch testdir-remove-source-files-1016102/file-b
ls testdir-remove-source-files-1016102
rsync -va --progress --remove-source-files testdir-remove-source-files-1016102/ testdir-remove-source-files-1016102/
ls testdir-remove-source-files-1016102
@WayneD
Copy link
Member

WayneD commented Aug 18, 2022

Duplicate of #304.

@WayneD WayneD closed this as completed Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants