You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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...
Cons: there's one particular edge case it wouldn't handle as well as the others (not sure how important that is)
Related to this, here's another tricky situation:
File is deleted on Path1
Delete is synced successfully during a run that later (ungracefully) aborts
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.
#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.
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.
Activity
nielash commentedon Nov 30, 2023
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
--workdirif 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...
nielash commentedon Dec 1, 2023
Related to this, here's another tricky situation:
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:
--resilientforever)--resilientor make a new flag. Reason being:--resilientis 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.#7471 definitely helps here, but unless you're using
--conflict-loser deleteit'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).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 inbisynctoo.nielash commentedon Dec 3, 2023
@crocinsocks I did some work on this and have a working proof-of-concept. Would you like to try it and give feedback?
nielash commentedon Dec 4, 2023
@crocinsocks Great, check this out: https://github.com/nielash/rclone/tree/bisync-recover-WIP
Ctrl+Cwill trigger the graceful shutdown sequence which will use best efforts to exit cleanly before the timer runs out.A second
Ctrl+Cwill trigger an immediate un-graceful exit, which--resilientwill recover from cleanly using the "diff from last trusted listing" method described above. (I stuck with--resilientfor now but it's easy to change the flag later.)I also implemented
--max-lockwith a pretty robust auto-renewal heartbeat mechanism.I recommend trying it with something like:
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!)
2 remaining items
bisync: Graceful Shutdown, --recover from interruptions without --res…
bisync: allow lock file expiration/renewal with --max-lock - rclone#7470
bisync: Graceful Shutdown, --recover from interruptions without --res…
bisync: allow lock file expiration/renewal with --max-lock - rclone#7470
bisync: Graceful Shutdown, --recover from interruptions without --res…
bisync: allow lock file expiration/renewal with --max-lock - #7470
Merge branch 'master' into ia-wt-1168
bisync: Graceful Shutdown, --recover from interruptions without --res…
bisync: allow lock file expiration/renewal with --max-lock - rclone#7470