Skip to content

rclone copy deletes files! #6142

Closed
Closed

Description

@JanHolger

The associated forum post URL from https://forum.rclone.org

We don't need a quick response or support so we didn't open one. This can be a severe issue though so we wanted to report it anyway.

What is the problem you are having with rclone?

TL;DR:
Using rclone copy with the sftp backend deletes files on the target when the file check after the upload fails, even though the docs clearly state something else.

We were using rclone copy to sync a large amount of files between 2 servers via sftp. After a short time we found out that some files that previously existed, didn't exist anymore. It took us 2 days to find out what actually happened but when we found "remove name" entries for the missing files in our SSH Logs we finally suspected rclone and started digging into the code and found this. The Update function tries to update the file on the server, then tries to read from it. If the read fails for any reason it suspects the upload to be failed and tries to delete the file on the server, which especially in case of a rclone copy shouldn't happen or there should be a warning in the docs. This issue for us lead to a severe data loss as some files were also deleted on the source site during the backsync.

What is your rclone version (output from rclone version)

1.58.0

Which OS you are using and how many bits (e.g. Windows 7, 64 bit)

Debian 11, 64 bit

Which cloud storage system are you using? (e.g. Google Drive)

SFTP

The command you were trying to run (e.g. rclone copy /tmp remote:tmp)

rclone copy -P --fast-list local:/home/my/data/dir remote:/home/my/data/dir

A log from the command with the -vv flag (e.g. output from rclone -vv copy /tmp remote:tmp)

Our logs are way too large and include confidential information

How to use GitHub

  • Please use the 👍 reaction to show that you are affected by the same issue.
  • Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
  • Subscribe to receive notifications on status change and new comments.

Activity

  1. ncw commented on May 4, 2022

    @ncw
    Member

    I'm sorry to hear about your data loss.

    I'd like to understand more before trying to fix the problem.

    The Update function tries to update the file on the server, then tries to read from it

    Why did it fail? Can you post that section of the log (redact the file names if you want).

    This issue for us lead to a severe data loss as some files were also deleted on the source site during the backsync.

    What is a backsync? Is that running a sync back the other way?

  2. JanHolger commented on May 4, 2022

    @JanHolger
    Author

    Why did it fail? Can you post that section of the log (redact the file names if you want).

    Unfortunately we can't provide you with the logs.

    What is a backsync? Is that running a sync back the other way?

    Yes, we occasionally ran an rclone copy back to the old machine to keep both systems in sync. We did move the files on a more scalable system and wanted to keep the previous system operational for a certain time in case there are any issues with the new system.

    The biggest issue with this for us isn't that rclone copy can delete files and there is probably a good reason for this behavior. The issue we had is the fact that the docs state that it doesn't. If the docs would've been clear about the fact that rclone copy can also delete files on the target, we wouldn't have run the sync and backsync at the same time and could've easily recovered the files.

  3. ncw commented on May 5, 2022

    @ncw
    Member

    Thank you for explaining - I understand the problem now.

    Can you confirm the log has a line "Removing failed copy" in it?

    This issue has come up before and I think there is an issue about it somewhere else, but I can't find it now.

    I would like to stop Copy ever deleting files. This needs a little bit of work in the backends which can upload partial files (eg local, sftp, ftp) so that they upload to a temporary name then move the file over the existing one when it is complete.

    What I want for rclone is when the copy has completed with either have the new file properly uploaded, or the old file as it was.

    Currently rclone deletes files when the copy didn't complete properly to make sure you don't ever get a corrupted file. This is overzealous and not documented as you pointed out.

  4. added this to the v1.59 milestone on May 5, 2022
  5. self-assigned this
    on May 5, 2022
  6. modified the milestones: v1.59, v1.60 on Jul 9, 2022
  7. modified the milestones: v1.60, v1.61, v1.62 on Dec 5, 2022
  8. modified the milestones: v1.62, v1.63 on May 9, 2023
  9. ncw commented on Jun 7, 2023

    @ncw
    Member

    This has now been fixed for v1.63 (currently in the latest beta). For local, ftp and sftp destinations rclone will upload to a .partial file and rename it over the destination if it checks out OK.

    See 5c594fe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions