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

Does this tool support online rollback? #37

Closed
developer91234 opened this issue Jul 27, 2024 · 5 comments
Closed

Does this tool support online rollback? #37

developer91234 opened this issue Jul 27, 2024 · 5 comments

Comments

@developer91234
Copy link

Not clear from the documentation and I don't have an arch btrfs system to test. Would you be able to rollback the mounted root subvolume in place? Also, if I were booted into a snapshot, the rollback script would rollback the root subvolume, correct?

@hirak99
Copy link
Owner

hirak99 commented Jul 28, 2024

Yes, online rollback is supported.

The yabsnap rollback-gen ID command generates a short bash script.

You will need to review the script and run it manually (or type in the commands one by one).

It can be run from the system mounted on the root which you want to roll back. After you run the script, the system will continue to function with the current snapshot until you reboot, upon which the rollback will take effect.

For rollback to work correctly, root should be mounted (in fstab) with subvol= and not subvolid=.

@hirak99
Copy link
Owner

hirak99 commented Jul 28, 2024

Also fyi, here's an example of rollback script it generates. This should clarify exactly how the rollback process works.

Command -

$ yabsnap rollback-gen 20240728183030

Output -

#!/bin/bash
# Save this to a script, review and run as root to perform the rollback.

set -uexo pipefail

mkdir -p /run/mount/_yabsnap_internal_0
mount /dev/mapper/luksdev /run/mount/_yabsnap_internal_0 -o subvolid=5

cd /run/mount/_yabsnap_internal_0

mv @home @.snapshots/rollback_20240728192848_@home
btrfs subvolume snapshot /.snapshots/@home-20240728183030 @home

mv @ @.snapshots/rollback_20240728192848_@
btrfs subvolume snapshot /.snapshots/@root-20240728183030 @

echo Please reboot to complete the rollback.
echo
echo After reboot you may delete -
echo "# sudo btrfs subvolume delete /.snapshots/rollback_20240728192848_@home"
echo "# sudo btrfs subvolume delete /.snapshots/rollback_20240728192848_@"

@developer91234
Copy link
Author

Thanks. Please consider letting the user do rollbacks without saving the script as this is quite cumbersome. After all the operation is reversible, maybe just inform the user of the changes after they're done and allow them to undo it if they want.

@hirak99
Copy link
Owner

hirak99 commented Jan 10, 2025

Perhaps we should add a --run option to rollback-gen. Might as well alias that to a new command, rollback.

It can print the script, confirm with the user, then run it.

Initial reason for not doing this was safety, but I think the code has matured enough (and tested enough times) for this to makes sense.

Optionally, --noconfirm can also be added, although that is probably veering a bit too far into the "dangerous" territory.

@hirak99 hirak99 mentioned this issue Jan 11, 2025
Tql-ws1 added a commit to Tql-ws1/yabsnap that referenced this issue Jan 16, 2025
See hirak99#37 and hirak99#6 (comment)

Tests -
- Added test cases for rollbacker.py

Refactor -
- Split the rollbacker.rollback() function

Style -
- Formatted main.py, os_utils.py, rollbacker.py, and rollbacker_test.py using isort and black
  - `isort --python-version 310 --profile google --line-length 80 --src-path "src/code"`
  - `black --line-length 80 --target-version py310 --target-version py311 --target-version py312`
Tql-ws1 added a commit to Tql-ws1/yabsnap that referenced this issue Jan 16, 2025
See hirak99#37 and hirak99#6 (comment) for details

Tests -
- Added test cases for rollbacker.py

Refactor -
- Split the rollbacker.rollback() function

Style -
- Formatted main.py, os_utils.py, rollbacker.py, and rollbacker_test.py using isort and black
  - `isort --python-version 310 --profile google --line-length 80 --src-path "src/code"`
  - `black --line-length 80 --target-version py310 --target-version py311 --target-version py312`
Tql-ws1 added a commit to Tql-ws1/yabsnap that referenced this issue Jan 16, 2025
See hirak99#37 and hirak99#6 (comment) for details

Tests -
- Added test cases for rollbacker.py

Refactor -
- Split the rollbacker.rollback() function

Style -
- Formatted main.py, os_utils.py, rollbacker.py, and rollbacker_test.py using isort and black
  - `isort --python-version 310 --profile google --line-length 80 --src-path "src/code"`
  - `black --line-length 80 --target-version py310 --target-version py311 --target-version py312`
Tql-ws1 added a commit to Tql-ws1/yabsnap that referenced this issue Jan 16, 2025
See hirak99#37 and hirak99#6 (comment) for details

Tests -
- Added test cases for rollbacker.py

Refactor -
- Split the rollbacker.rollback() function

Style -
- Formatted main.py, os_utils.py, rollbacker.py, and rollbacker_test.py using isort and black
  - `isort --python-version 310 --profile google --line-length 80 --src-path "src/code"`
  - `black --line-length 80 --target-version py310 --target-version py311 --target-version py312`
hirak99 added a commit that referenced this issue Jan 17, 2025
Also added some additional changes such as documentation.

- Reformatted a few files.
- batch_deleter: Removed interactive_confirm (it's already in os_utils).
- os_utils.interactive_confirm: Moved [Y/n] prompt there.
- rollback.py
  - Reorganized rollback() and some functions.
  - Removed some trivial functions.
  - Using a temporary directory to save script to prevent any collusion.
  - Honor the dry-run flag, and do not actually execute if it is set.
  - Added few tests.
  - Updated README.md and manpage.

Related to #37, #44, #45.
@hirak99
Copy link
Owner

hirak99 commented Jan 17, 2025

The rollback command (with optional --noconfirm) is implemented and released as v2.2.2. Along with displaying the script for review, this will also execute it after an interactive confirmation.

Thanks to @Tql-ws1 for help with this and more!

@hirak99 hirak99 closed this as completed Jan 17, 2025
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