Repository navigation
Description
This is a feature request for the ability to access a complete list of files transferred/deleted by Sync/Copy/Move, as well as their basic attributes and any errors encountered. This is similar to rclone check's ability to output lists for MissingOnDst, MissingOnSrc, etc.
While this would be a nice feature in general for many reasons, I am primarily interested because it's currently the blocking issue for Bisync's biggest bug.
Prior discussion (from #6797)
Just wanted to mention, in case it's related to the work you're planning here, that it would be really helpful for future
bisyncwork to have an easy way to access a complete list of transfers. Similar toaccounting.Stats(ctx).Transferred(), but that one is limited toMaxCompletedTransfers(100) and doesn't includemodtimeorhash. My hope is to use this to avoid having to re-list each fs at the end of a bisync run to find out what happened during thesyncCopyMoveoperations, as re-listing is more expensive and error-prone.If this maybe already exists and I'm missing it, please let me know 😃 I see how to access the total number of transfers/errors, but we would need a list to reconcile it with the initial directory listings to build the "after" snapshot. If keeping the full transfer list in memory is a concern, we could potentially work with just a list of errored transfers (and infer that anything not on this list was successful and now matches what we passed in.) But this is not entirely foolproof, as it leaves open the possibility that files changed in between the listing and copying.
@ncw:
That isn't quite what is under discussion here, but what I think you want is something like we have for
operations.Checkwhere you can pass inio.Writers to have the file names written to.type CheckOpt struct { Fdst, Fsrc fs.Fs // fses to check Check checkFn // function to use for checking OneWay bool // one way only? Combined io.Writer // a file with file names with leading sigils MissingOnSrc io.Writer // files only in the destination MissingOnDst io.Writer // files only in the source Match io.Writer // matching files Differ io.Writer // differing files Error io.Writer // files with errors of some kind }If you read the docs for rclone check you'll see the bits about outputting file names to files. People have asked for exactly this for sync/copy/move and I think this internal inteface would suit your requirements too.
I should probably change the
io.Writerinto afunc(remote string) errorto explicitly say it will be called with a path each time. We'd need a way of signalling high level retries also as the functions potentially get called each high level retry.
Yes, this would be great! (I used this recently in 5ca61ab.) For bisync purposes I think we'd also need the
size,modtime, andhashin addition to the list of names (at least to the extent thatsyncCopyMovealready has this info -- and I think it does, as that's how it knows if a file is "corrupted on transfer".)
In addition to the above, it would also be important to know whether each operation was a copy or delete, and whether it had an error. The end goal is to update the initial listing, which uses this format:
Lines 27 to 32 in b750c50
| // flags <- size -> <- hash -> id <------------ modtime -----------> "<----- remote" | |
| // - 3009805 md5:xxxxxx - 2006-01-02T15:04:05.000000000-0700 "12 - Wait.mp3" | |
| // | |
| // flags: "-" for a file and "d" for a directory (reserved) | |
| // hash: "type:value" or "-" (example: "md5:378840336ab14afa9c6b8d887e68a340") | |
| // id: "-" (reserved) |
See also:
- On failed transfers give list of failed files at end of rclone run #3933
- bisync: handle volatile changes consistently #5676
- Bisync fails when files are added during bisync operation #6841
- Forum discussion
- A recent user post about this bug
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
nielash commentedon Sep 9, 2023
@ncw I started working on a proof-of-concept for this. If you have a moment, could you let me know if it's generally headed in the right direction? nielash@50bf6a6
ncw commentedon Sep 9, 2023
I see you have instrumented
Copy,Move,Deleteso the fundamental operations. This won't get you all of the things hereI was thinking to instrument the
sync.Syncroutine where you know exactly what status each thing is. Check out howoperations.Checkis instrumented withc.reportandc.reportFilename.I think there only needs to be one function with a signature like this
The sigils define exactly what is happening. These could of course be constants which might make the code easier to read.
You can then read filenames, modtimes or hashes from the objects. However you must only read them if you are going to need them as reading modtimes or hashes can both be expensive on some backends. If you aren't sure then just store the object until you do know.
Rather than changing all the function prototypes for everything, the modern go way of passing a function through lots of layers would be to add it to the context.
So you'd export a function from
fs/syncto add a function pointer to the context, saysync.WithLoggerand then you'd extract this logger function in sync.newSyncCopyMove and store it in thesyncCopyMovestructure if found or a no-op function if not so you can call it without checking it fornil. This will make the patch much smaller!Then in the
newSyncCopyMovesomething like this (though thinking ahead this should probably be in operations inoperations.GetLogger(ctx)as should theWithLoggerand definitions.Then to close the circle we can do the same thing in
operations.Checkand factor the duplicate code intooperations.nielash commentedon Sep 10, 2023
Thanks so much! Excellent feedback. I will take another stab at it with this in mind.
I think one challenge this approach will present for Bisync is that the sigils indicate the state before the transfers, not after. For example,
*indicates that the file differed on src and dst, but that does not necessarily mean that sync updated the dst -- perhaps we did not attempt to due to--ignore-existing, or perhaps we did attempt to but there was an error. The sigils tell us "here's how the src and dst were different before my changes", whereas what Bisync really wants is "here's a complete list of every change I made on the dest". This could maybe be solved by adding an additional sigil, but I'm not exactly sure where in the code would be the cleanest place to call it from.Totally agree, and that's why I was hoping to record them while copy is already using them, to avoid having to request them twice. For example, we already print hashes to the log here:
rclone/fs/operations/operations.go
Lines 538 to 549 in d4d530b
But I realize this may not be possible in some cases -- ex. renames and server-side copies.
Bisync does always need all modtimes, as it's currently the only way it can detect whether a file changed between bisync runs. If we do have to read modtimes/hashes a second time, what is crucial is that we do it during the sync, not after, to minimize the possibility of the file changing again before we have a chance to read it (for instance, in an hours-long sync). (This is why I'm pretty sure the code for this will have to live in
syncoroperations, as opposed tobisync, even if it will only be called during bisync.)Totally agree about passing it through the context -- much cleaner 🙂
ncw commentedon Sep 10, 2023
:-)
That is a good point. The set of sigils was designed for
rclone checkwhich doesn't alter the state. Probably all the existing sigils should have an implied meaning forsyncthatsyncsuccessfully corrected the situation.Or maybe the logger should take an
errortoo and if it is notnilwe assume that the operation failed?Not quite sure how to report
--ignore-existing- I'd be tempted to report=as ok and didn't need copying.You'll see in the sync code that there is a log or a debug at all these terminal places. There are no logs in the Copy/Move section as Copy and Move themselves make the logs. This is so that every file makes one log.
Modtimes and hashes will be cached in the object so if they've been looked up once, then it is cheap to look them up again.
Hopefully the caching will fix that.
I can see it is going to be quite tricky getting the correct logging in to sync so I expect we'll have to collaborate on that.
nielash commentedon Sep 12, 2023
New version based on your feedback: nielash@60fc9c7 Still very much a work-in-progress, but I think it's a lot closer to what you had in mind. I included an example of how
rclone synccould use the same flags asrclone checkand output the same file lists.I wrote a very basic test script to test whether
rclone checkandrclone syncoutput exactly the same file lists, and so far it seems that they do, in all the scenarios I tried. But more testing is needed. (Relatedly: is there a better way to do this kind of thing within the actual go testing framework? i.e. run a trusted command with CLI args from a different rclone package, as opposed to trying to recreate it with internal functions.)--erroris not fully implemented yet.processError()seems like the obvious place to do it, but it doesn't have thefs.Objects in scope, so it might need to be one layer back.The
Completedstream is also not done -- it's the trickiest part, as we discussed. I will probably need your help with it. I'm also coming around to the idea that it may not be totally necessary, since we can infer that the dst should always end up matching the src, unless there were errors. One concern is high-level retries, if the src could be changing during the course of a long sync. Does it refresh the src object each high-level retry or is the src cached the first time only? If the former, we may want to add some logic to de-dupe the stream in favor of the newest line for each path.Also, scratch what I said about the bisync code having to live elsewhere... after I wrote that, it occurred to me that I could pass in a custom
LoggerFn😊ncw commentedon Sep 12, 2023
Yes that is looking very neat now - I like it! I put a few more comments on it.
Very nice.
Yes there is the https://pkg.go.dev/github.com/rogpeppe/[email protected]/testscript package which is for exactly this purpose.
Though I'm not sure how you make sure you've built an rclone binary first. I guess it could be a separate step in the CI build process.
Your test script could fairly easily be wrapped up into a separate script, though it might be better to add a logger to the operations and sync tests and check the outputs there were as expected - that would then give you more chance to track down the problems as the individual features get exercised.
I think
processErroris probably too low level as lots of things can hit that (eg directory reading error).I think completed probably has to be logged in the sync routine.
Yes that should be true!
Yes it does
High level retries throw a bit of a spanner in the works here... If we were just logging to files what would you expect to see?
Here are some ideas
#sigil meaning start of next try (would need to be written to all logs)--retries 1(this will be how bisync calls the code anyway as internal calls don't have retries).Deduplicating the logs (so trying to make them appear as if there was only one run) sounds attractive but I think will be very hard and might use up lots of memory.
:-)
DarrenPIngram commentedon Sep 15, 2023
I cannot add much to the programming side, but I am excited about this feature plan [even though I probably must script some hack to achieve similar over the weekend]. I would just like to highlight, if possible, it would be desirable for any output to be configured and parseable, so one could, for example, act on the transferred data file list with other scripting,
e.g. /path/to/dog1.txt
/path/to/dogstories/dog2.txt
So you could add this to a list, a report, or other action of your choosing [outside of rclone].
ncw commentedon Sep 15, 2023
@DarrenPIngram the plan is to make the output match that of rclone check which is very easy to parse.
DarrenPIngram commentedon Sep 15, 2023
30 remaining items
operations: add logger to log list of sync results -- fixes rclone#7282
sync: report list of synced paths to file -- see rclone#7282
operations: add logger to log list of sync results -- fixes #7282
sync: report list of synced paths to file -- see #7282
marvin-roesch commentedon Sep 23, 2024
I will happily create a follow-up issue for this, but I was wondering if there were any plans to also support this kind of log output for
rclone copyas well. We have a use case where we want to only add onto a destination and perform deletes at a later date based on some additional external information. We would like to maintain a list of files that are on the source, however (and whether they needed to be transferred or not).Obviously deletes/
--missing-on-srcwould not need to be supported in this case.We could implement this by listing everything in the source first and extracting the transfers from the
rclone copylogs, but due to the number of files in our source, it would be much preferable to have this done in a single step. Considering the infrastructure for it already seems to be in place, maybe this is something that can easily be added torclone copy?nielash commentedon Sep 25, 2024
Indeed there were!
rclone/cmd/sync/sync.go
Line 31 in 498d9cf
And then we never got around to it, I guess. It would be pretty easy to implement though, as you could copy and paste a lot of the same code from here. Any chance you'd want to give it a go and submit a PR?
In any case, yes -- please create a new issue for this so it stays on our radar!
marvin-roesch commentedon Oct 4, 2024
Thanks for the response, @nielash! I have created #8115 and will have a look at implementing this myself to submit as a PR.
operations: add logger to log list of sync results -- fixes rclone#7282
sync: report list of synced paths to file -- see rclone#7282