Giter Club home page Giter Club logo

snapper-rollback's Introduction

Snapper-Rollback

Python script to rollback BTRFS systems using the ArchWiki suggested subvolume layout

Installation

ArchLinux

Install through the AUR, or download the PKGBUILD file and run makepkg -sri while in the same directory

Other

git clone 'https://github.com/jrabinow/snapper-rollback.git'
cd snapper-rollback
sudo cp snapper-rollback.py /usr/local/sbin/snapper-rollback
sudo cp snapper-rollback.conf /etc/

Config file

Edit /etc/snapper-rollback.conf and make sure all the settings have the right values. You don't have to do this, but if you don't, you'll have to manually mount your btrfs root subvolume to /btrfsroot before running the script.

Usage

usage: snapper-rollback.py [-h] [--dry-run] [-c CONFIG] SNAPID

Rollback to snapper snapshot based on snapshot ID

positional arguments:
  SNAPID                ID of snapper snapshot

optional arguments:
  -h, --help            show this help message and exit
  --dry-run             don't actually do anything, just print the actions out
  -c CONFIG, --config CONFIG
                        configuration file to use (default: /etc/snapper-
                        rollback.conf)

Example usage

$ snapper list
 # | Type   | Pre # | Date                            | User | Cleanup  | Description  | Userdata
 ---+--------+-------+---------------------------------+------+----------+--------------+---------------------
 0  | single |       |                                 | root |          | current      |
 1  | single |       | Mon 19 Jul 2021 08:59:01 PM PDT | root |          | base_install |
 2  | single |       | Fri 30 Jul 2021 10:00:08 PM PDT | root | timeline | timeline     |
 3  | single |       | Fri 30 Jul 2021 11:00:08 PM PDT | root | timeline | timeline     |
$ snapper-rollback 1        # let's revert back to the snapshot whos description is `base_install`
Are you SURE you want to rollback? Type 'CONFIRM' to continue: CONFIRM
2021-10-17 23:25:47,889 - INFO - Rollback to /btrfsroot/@snapshots/1/snapshot complete. Reboot to finish

Credits

@GabTheBab for creating the first iteration of this script and for sharing it on the AUR.
Original repo here: https://gitlab.freedesktop.org/Gabby/rollback

snapper-rollback's People

Contributors

david-cortes avatar jrabinow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

snapper-rollback's Issues

Don't have subvolid 5

Hi, I've installed this package and I tried to use with grub-btrfs for rollback, similar to opensuse. If I used old snapshot read-only, when I used snapper-rollback number of snapshot I confirmed but I had error because subvolid wasn't ID 5.

Error on rollback

I'm getting the follow error when trying to rollback:

ERROR - [BtrfsUtilError 7 Errno 2] Could not open: No such file or directory: '/btrfsroot/@.snapshots/29/snapshot' -> '/btrfsroot/@'

I can see my snapshots with snapper ls and I can see them in the /.snapshots directory. I'm guessing it might be related to this comment from the readme:

"Edit /etc/snapper-rollback.conf and make sure all the settings have the right values. You don't have to do this, but if you don't, you'll have to manually mount your btrfs root subvolume to /btrfsroot before running the script."

Did I miss a step somewhere?

Edit: sorry I didn't mean to mark this a bug as I'm certain I did something wrong.

[BUG]

Hi, I've installed this package and I tried to use with grub-btrfs for rollback, similar to opensuse. If I used old snapshot read-only, when I used snapper-rollback number of snapshot I confirmed but I had error because subvolid wasn't ID 5.

So, this were my steps:

  • step 1:
    zar_marco@cosmogram:~ % mount proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) sys on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) dev on /dev type devtmpfs (rw,nosuid,relatime,size=8024844k,nr_inodes=2006211,mode=755,inode64) run on /run type tmpfs (rw,nosuid,nodev,relatime,mode=755,inode64) efivarfs on /sys/firmware/efi/efivars type efivarfs (rw,nosuid,nodev,noexec,relatime) /dev/nvme0n1p1 on / type btrfs (rw,relatime,ssd,space_cache=v2,subvolid=446,subvol=/@snapshots/5/snapshot) securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,inode64) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot) pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime) bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700) systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=30,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=16420) mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime) hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M) debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime) tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime) configfs on /sys/kernel/config type configfs (rw,nosuid,nodev,noexec,relatime) fusectl on /sys/fs/fuse/connections type fusectl (rw,nosuid,nodev,noexec,relatime) /dev/nvme0n1p1 on /.snapshots type btrfs (rw,relatime,ssd,space_cache=v2,subvolid=441,subvol=/@snapshots) /dev/nvme0n1p1 on /home type btrfs (rw,relatime,ssd,space_cache=v2,subvolid=333,subvol=/@home) tmpfs on /tmp type tmpfs (rw,nosuid,nodev,nr_inodes=1048576,inode64) /dev/nvme1n1p3 on /home/zar_marco/condivise type btrfs (rw,relatime,compress=zstd:3,ssd,space_cache,subvolid=1064,subvol=/@condivise) /dev/nvme1n1p5 on /efi type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro) tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=1606560k,nr_inodes=401640,mode=700,uid=1000,gid=1000,inode64) portal on /run/user/1000/doc type fuse.portal (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000) /dev/nvme0n1p1 on /mnt/arch type btrfs (rw,relatime,ssd,space_cache=v2,subvolid=376,subvol=/@)

  • step 2:
    zar_marco@cosmogram:~ % sudo mount -t btrfs -o subvol=@ /dev/nvme0n1p1 /mnt/arch

  • step 3
    zar_marco@cosmogram:~ % sudo snapper-rollback SNAPID446 Are you SURE you want to rollback? Type 'CONFIRM' to continue: CONFIRM 2022-02-17 08:44:39,192 - CRITICAL - Missing /mnt/arch/@: Is None mounted with the option subvolid=5?

-step 4
zar_marco@cosmogram:~ % sudo snapper-rollback SNAPID5 Are you SURE you want to rollback? Type 'CONFIRM' to continue: CONFIRM 2022-02-17 08:44:52,400 - CRITICAL - Missing /mnt/arch/@: Is None mounted with the option subvolid=5?

there are my btrfs sub list
zar_marco@cosmogram:~ % sudo btrfs subvolume list / [sudo] password di zar_marco: ID 262 gen 3205 top level 5 path @arch ID 263 gen 2057 top level 262 path @arch/var/lib/portables ID 264 gen 2057 top level 262 path @arch/var/lib/machines ID 331 gen 1434 top level 5 path arch-root_2022-02-12_05:00 ID 333 gen 3281 top level 5 path @home ID 376 gen 3247 top level 5 path @ ID 441 gen 3245 top level 5 path @snapshots ID 442 gen 2966 top level 441 path @snapshots/1/snapshot ID 443 gen 3238 top level 441 path @snapshots/2/snapshot ID 444 gen 2957 top level 441 path @snapshots/3/snapshot ID 445 gen 2949 top level 441 path @snapshots/4/snapshot ID 446 gen 3249 top level 441 path @snapshots/5/snapshot ID 447 gen 3244 top level 441 path @snapshots/6/snapshot

I don't understand what I wrong for rollback on my previous snapshot.

This is my snapper-rollback.conf
`zar_marco@cosmogram:~ % cat /etc/snapper-rollback.conf

Rollback to snapper snapshot

Requires a flat subvolume layout like specified here:

https://wiki.archlinux.org/index.php/Snapper#Suggested_filesystem_layout

Run with snapshot number as an argument like "snapper-rollback 642"

This can be run either from your installed system or from a live arch ISO if

you adjust the settings accordingly

Some terminology:

- your linux root is what gets mounted to / at boot time. Referred to

as main in this tool

- your btrfs root is the btrfs toplevel subvolume with subvol id = 5. See

https://btrfs.readthedocs.io/en/latest/btrfs-subvolume.html#description

for more info.

Referred to as root in this tool.

config for btrfs root

[root]

Name of your linux root subvolume

subvol_main = @

Name of your snapper snapshot subvolume

subvol_snapshots = @snapshots

Directory to which your btrfs root is mounted.

mountpoint = /mnt/arch

Device file for btrfs root.

If your btrfs root isn't mounted to mountpoint directory, then automatically

mount this device there before rolling back. This parameter is optional, but

if unset, you'll have to mount your btrfs root manually.

#dev = /dev/sda42`

Snapshots are created in read-only

my doubt is, for rollback I must boot snapshot that I want to restore sure? Or I must boot on my root's partiton and restore from that?

I am left without network device after rollback

Describe the bug
After some time with my newly installed archlinux, I am about to do a complete system upgrade with "pacman -Syu". If I then decide to rollback to a previous snapshot ("*** Base ***), after booting the system I find that I have no network. I check my network devices and only find the "loopback" interface but not my network card. I read the files inside the "/sys/class/net" directory and it is empty.

Is this normal or am I doing something wrong?

To Reproduce
Steps to reproduce the behavior:

  • System full upgrade with "pacman -Syu"
  • Rollback to previous snapshot "snapper-rollback 1" and after CONFIRM --> reboot
  • After rollback I have no network

Expected behavior
I hope to have the network available and to be able to use it.

Actual behavior
I have no network

Screenshots
Screenshot_2024-04-03-13-31-44_24609
Screenshot_2024-04-03-13-37-22_6837
Screenshot_2024-04-03-13-53-23_8593
Screenshot_2024-04-03-13-52-56_22105
Screenshot_2024-04-03-13-54-48_21570

Software
uname -a: Linux archbox 6.8.2-zen2-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Thu, 28 Mar 2024 17:06:20 +0000 x86_64 GNU/Linux
Snapper version: snapper 0.10.7
snapper-rollback version: 1.0.1
snap-pac version: 3.0.1.2
grub-btrfs version: 4.13.1

'mountpoint' value when running from installed system

Hi,
i'm playing with btrfs and snapshots from a VM before install in working machine.
I found your tool reading ArchWiki. After installing snapper-rollback from aur I opened the config file and I dunno how to set 'mountpoint'. In a live session probably it is /mnt but on real machine is just "/"?
In a running system do I have to set 'dev'?
Very tanks

Necessity of `mountpoint` and `dev` settings

Looking at this blog post:
https://www.jwillikers.com/btrfs-snapshot-management-with-snapper

It seems it should be possible to determine the /dev file where the root partition is mounted by issuing this command:

df --output=source / | tail -n 1

And consequently something like this for snapper-rollback:

sudo mkdir -p /btrfsroot
sudo mount $(df --output=source / | tail -n 1) /btrfsroot

(or a different folder that's like to exists such as /mnt or /tmp to be safer on a read-only snapshot)

Not sure if it's guaranteed to work though.

mountpoint = /btrfsroot

First of all thanks for making and maintaining this.


btrfs-rollback claims to target the suggested standard subvol layout of the arch wiki.

However it requires for @ to be mounted to /btrfsroot instead the default mountpoint / in order to function.

This adds a (in my eyes completely unnecessary) difficulty to using it. Or am I just not seeing the benefit of /btrfsroot?

I would suggest to ship mountpoint = / in the conf file.

Snapshot not restored despite success message

I'm trying to set up a debian system with a similar snapper rollback option in GRUB as opensuse and spiral linux do, by using snapshots from grub-btrfs.

When I try to execute snapper-rollback, whether from the mainline root subvolume or from a bootable snapshot, I get a "success" message, but the snapshot is not restored next time I boot into my main system.

david@debian:~$ sudo snapper-rollback 69
Are you SURE you want to rollback? Type 'CONFIRM' to continue: CONFIRM
2023-03-03 13:59:25,716 - INFO - FalseRollback to /btrfsroot/snapshots/69/snapshot complete. Reboot to finish

Some help would be appreciated here


Info:

  • /etc/fstab:
UUID=a90b4fdd-ead4-4100-9ca8-509cdf3597b4 /               btrfs   defaults,autodefrag,compress=zstd,subvol=@ 0       0
UUID=CAED-898F  /boot/efi       vfat    umask=0077      0       1
UUID=b3561c81-1ce5-4c8e-95b9-119b61bf698a /home           btrfs   defaults        0       0
UUID=eca8bd39-7cb6-4043-b95c-44f6d25dc67e /tmp            ext4    defaults        0       2
UUID=45239f15-e700-460f-9686-345c622c2df1 /var            ext4    defaults        0       2
UUID=18143a4f-3cd5-4cf9-93d9-cd8a38442ff9 none            swap    sw              0       0
/dev/nvme0n1p2 /.snapshots btrfs defaults,autodefrag,compress=zstd,commit=120,noatime,subvol=snapshots 0 0
/dev/nvme0n1p2 /btrfsroot btrfs defaults,subvolid=5 0 0
  • sudo btrfs subvol list / (minus a long list of irrelevant snapshots) after executing snapper-rollback:
ID 256 gen 255 top level 5 path @rootfs
ID 257 gen 254 top level 5 path snapshots
ID 259 gen 61 top level 257 path snapshots/1/snapshot
...
ID 303 gen 213 top level 5 path @2023-03-03T13:21
ID 328 gen 248 top level 257 path snapshots/69/snapshot
ID 329 gen 218 top level 257 path snapshots/70/snapshot
...
ID 338 gen 242 top level 5 path @2023-03-03T13:56
ID 339 gen 247 top level 257 path snapshots/76/snapshot
ID 340 gen 248 top level 5 path @
ID 341 gen 252 top level 257 path snapshots/77/snapshot
  • snapper-rollback.conf changes:
[root]
subvol_main = @
subvol_snapshots = snapshots
mountpoint = /btrfsroot
dev = /dev/nvme0n1p2

The difference between `snapper-rollback`, and the default `snapper rollback`.

I understand correctly that system rollback is possible only from a live image? I can make this conclusion because the readme file does not contain instructions for use, but it does contain a link to the arch wiki with a section where recovery is performed through a live image.

Can you tell me how your snapper-rollback differs from the default snapper rollback. Do they work the same way? I saw you mentioned OpenSUSE, but no specifics. I would be grateful for an answer or even a link to a resource where I can read it (arch wiki doesn't count).

[BUG] No module btrfsutil were found

Describe the bug
The following packages "btrfs-progs libopenmpt libupnp" after the paru -Syu and then the snapper-rollback return error: No module btrfsutil were found

To Reproduce
Steps to reproduce the behavior:

  • step 1 Upgrade to the newest version of "btrfs-progs libopenmpt libupnp"
  • step 2 try snapper-rollback

Add support for snapshot auto-deletion

hello guys, this isnt actually a bug, and sorry for getting in your hair and everything, what you made is a masterpiece, i had a question, maybe suggestion, after rolling back, why are the old subvols left? is this intended? perhaps an option to run it Clean or sth would be nice so you dont have to manually mount and delete again? now i know its 20 second work to mount and delete the subvols but i just thought that would be a cool addition to your progeam, and perhaps more noob friendly and more useful on longterm... thank you

[BUG] still booting read only after roll back

Describe the bug

Debian boots into read-only mode after doing rollback.

I followed the guide at https://github.com/david-cortes/snapper-in-debian-guide and everything went according to plan.

From the grub menu, I booted into a pre snappshot. Then I did a sudo snapper-rollback 3 and rebooted.

I booted the default GRUB entry.

The system still booted into read only mode.

To Reproduce
Steps to reproduce the behavior:

  1. boot into pre snapshot
  2. sudo snapper-rollback #
  3. boot default GRUB entry

Expected behavior
It should boot the rolled back snapshot in read+write.

Actual behavior
It boots into read only mode.

Usable with /@ root volume?

Hi there, first of all thanks very much for making this very useful tool!

I'm considering integrating this tool with a distribution, but I can't seem to make it work with this subvolume layout (I'm using the Calamares installer, which doesn't support volumes starting with @ and so I have to preface them with a / )

UUID=2da1548b-529e-4110-a55b-f7e7fa67e797 /              btrfs   subvol=/@,subvolid=5,defaults,noatime,space_cache,autodefrag 0 0
UUID=2da1548b-529e-4110-a55b-f7e7fa67e797 /.snapshots    btrfs   subvol=/@snapshots,defaults,noatime,space_cache,autodefrag 0 0
UUID=2da1548b-529e-4110-a55b-f7e7fa67e797 /home          btrfs   subvol=/@home,defaults,noatime,space_cache,autodefrag 0 0
UUID=2da1548b-529e-4110-a55b-f7e7fa67e797 /root          btrfs   subvol=/@root,defaults,noatime,space_cache,autodefrag 0 0
UUID=2da1548b-529e-4110-a55b-f7e7fa67e797 /var           btrfs   subvol=/@var,defaults,noatime,space_cache,autodefrag 0 0
UUID=2da1548b-529e-4110-a55b-f7e7fa67e797 /tmp           btrfs   subvol=/@tmp,defaults,noatime,space_cache,autodefrag 0 0
ID 257 gen 145 top level 5 path @
ID 258 gen 137 top level 5 path @snapshots
ID 259 gen 138 top level 5 path @home
ID 260 gen 139 top level 5 path @root
ID 261 gen 136 top level 5 path @var
ID 262 gen 145 top level 5 path @tmp
ID 273 gen 43 top level 257 path .snapshots
ID 275 gen 46 top level 258 path @snapshots/1/snapshot
ID 276 gen 74 top level 258 path @snapshots/2/snapshot
...

In the snapper-rollback.conf file I tried:

subvol_main = @   #also tried /@
subvol_snapshots = @snapshots  #also tried /@snapshots
mountpoint = /      #also tried /tmp/whatever

But it throws CRITICAL - Missing /@: Is /dev/sda1 mounted with the option subvolid=5?

However, if I change it to:

subvol_main = /@
subvol_snapshots = /@snapshots
mountpoint = /tmp/whatever
dev = /dev/sda1

... it successfully does a rollback. The problem is that I'm interested in including this for the end-user and I don't want to have to explicitly define the root device. (Unfortunately /dev/root no longer exists). Is there any way to make this work within the limitations I have?

Thanks in advance for your time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.