Skip to content

bisync: recover from exit without --resync #7470

Closed

Description

It would be great if bisync could recover from an exit (SIGINT, SIGTERM, SIGKILL) without the need of a --resync.

e.g. powercut, Ctrl+C, shutdown

This would save the extra work to get it to play nice with everyday usage. Currently, have to run a script to wait for sync(s) to finish then shutdown/restart/etc. In some cases there is nothing that can be done to prevent this such as as system crash or power cut resulting in --resync being required. Or sometimes you just want a quick restart due to a kernel/application update or other issue and instead you have to wait or accept the consequences.

Thanks

Activity

  1. nielash commented on Nov 30, 2023

    @nielash
    Contributor

    Definitely agree this could and should be improved!

    (For others reading this: here's our previous discussion about it, with some good background info about why this is a particularly tough challenge for bisync.)

    Some possible solution approaches include:

    • "autosave" -- save progress state every X seconds (or after every X transfers) throughout a run, so in the event of a crash, the next run can resume from the last autosave.
      Pros: probably the most accurate method
      Cons: may be complicated to build, may slow down the sync with lots of writes to disk, may not be practical with a non-local --workdir if that is eventually supported

    • "replay queues" -- save the queue list at the beginning of each sync, and in the event of an interruption, the next run attempts to finish the prior run by "replaying" it, before starting the new run.
      Pros: easier and less expensive than "autosave"
      Cons: potentially not robust to changes that occurred after the interrupted run

    • "graceful shutdown" -- upon receiving Ctrl+C, gracefully wrap up what we're doing at the earliest opportunity, cleaning up after ourselves to make things easy for next time.
      Pros: relatively easy and clean
      Cons: only works when we have some warning (won't help with powercut, sudden crash, etc.)

    • "diff from last trusted listing" -- similar idea to ef4b47a, but revert the whole listing instead of individual files, and re-diff.
      Pros: the easiest and perhaps most elegant option
      Cons: there's one particular edge case it wouldn't handle as well as the others (not sure how important that is)

    One question I have for you is: how important is it to handle the "crash" scenarios in addition to the ones where we have some warning? i.e. would a "graceful shutdown" option go far enough for you?

    Another use case to keep in mind here is using a laptop while traveling, and losing internet or needing to close the laptop mid-sync...

  2. added this to the Known Problem milestone on Nov 30, 2023
  3. nielash commented on Dec 1, 2023

    @nielash
    Contributor

    Related to this, here's another tricky situation:

    1. File is deleted on Path1
    2. Delete is synced successfully during a run that later (ungracefully) aborts
    3. Same file is added back on Path2 before the next run (with same timestamp)

    With the "diff from last trusted listing" method, it will look like the file should be deleted from Path2, when in fact it should be copied to Path1. (Note that if the timestamp is different in step 3, it arrives at the right answer because it's deleted vs. newer, not deleted vs. unchanged.) Again, kind of an edge case that probably wouldn't happen too often.

    Two other things to track here:

    • we'll need to make some kind of change to lock files, for the same reasons discussed in bisync: auto-resolve conflicts #7471 (else one ungraceful shutdown would break --resilient forever)
    • I'm not currently sure if it's best to bundle this feature into --resilient or make a new flag. Reason being: --resilient is currently about retrying, which is a slight difference in kind from recovering. There may be some users who want the retrying features but are not comfortable with recovering due to risks like the edge case described above.

    handle the edge case of conflicts as in #7471.

    #7471 definitely helps here, but unless you're using --conflict-loser delete it's still not ideal, as it's really a false conflict... if we had the correct state, we'd know that only one of the sides has changed (and the unchanged side should be overwritten, not renamed).

    With graceful shutdown perhaps you could even resume file upload from where it was left off when files have not changed on either side (particularly useful for larger uploads).

    Many (most?) rclone backends don't support partial uploads, so it's probably not possible, but check out #87... if it is someday supported in sync, it will be supported in bisync too.

  4. nielash commented on Dec 3, 2023

    @nielash
    Contributor

    @crocinsocks I did some work on this and have a working proof-of-concept. Would you like to try it and give feedback?

  5. nielash commented on Dec 4, 2023

    @nielash
    Contributor

    @crocinsocks Great, check this out: https://github.com/nielash/rclone/tree/bisync-recover-WIP

    Ctrl+C will trigger the graceful shutdown sequence which will use best efforts to exit cleanly before the timer runs out.

    A second Ctrl+C will trigger an immediate un-graceful exit, which --resilient will recover from cleanly using the "diff from last trusted listing" method described above. (I stuck with --resilient for now but it's easy to change the flag later.)

    I also implemented --max-lock with a pretty robust auto-renewal heartbeat mechanism.

    I recommend trying it with something like:

    rclone bisync path1 path2 --resilient --max-lock 2m -vP
    

    so you can see what it's doing more clearly.

    It is not yet production-ready, so make sure you have a backup or use test data in case there are bugs. (And if you find any, please let me know!)

  6. self-assigned this
    on Dec 4, 2023
  7. modified the milestones: Known Problem, Soon on Dec 4, 2023
  8. 2 remaining items

  9. added 2 commits that reference this issue on Dec 15, 2023
    c5c630c
    9881adf
  10. added 2 commits that reference this issue on Jan 20, 2024
    e568f11
    eaf3cc7
  11. added 2 commits that reference this issue on Jan 20, 2024
    4025f42
    e9cd3e5
  12. added a commit that references this issue on Jan 23, 2024
  13. moved this to Done in bisyncon Aug 20, 2024
  14. added 2 commits that reference this issue on Jul 20, 2026
    270b925
    d9c7666
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

  • Status
    Done

Relationships

None yet

Development

No branches or pull requests

Issue actions