linuxmint / timeshift

System restore tool for Linux. Creates filesystem snapshots using rsync+hardlinks, or BTRFS snapshots. Supports scheduled snapshots, multiple backup levels, and exclude filters. Snapshots can be restored while system is running or from Live CD/USB.
2.51k stars 91 forks source link

Btrfs Snapshots should be readonly #332

Open ygerlach opened 2 months ago

ygerlach commented 2 months ago

Describe the bug All btrfs snapshots created by timeshift are writeable. I believe they should be read-only by default (and maybe have a button to make them writeable). So you cant accidentally mess up your only way back out of a broken system.

To Reproduce

  1. Create a btrfs snapshot
  2. Browse the snapshot
  3. try to create or modify a file

Expected behavior btrfs subvolume snapshot -r ... should be used to create a read-only snapshot and avoid users messing up their backup. A Option could be provided to toggle the snapshot between read/write and read-only. A Option to set the default value for new snapshots might also be useful (should be read-only by default).

agusdmb commented 1 month ago

Would be great to have this!

Also keep in mind that to remove the read only subvolumes they cannot be deleted as regular directories but with the btrfs command:

btrfs subvolume delete ...

ygerlach commented 1 month ago

you are right. But instead of relying on the btrfs command i would rather just use the systemcalls if it is possible without much hassle. But many of them are quite easy. Just have a dirfd to the subvolume and call a specific ioctl to do an operation. Nothing to crazy.

Here an excerpt from the strace of a btrfs subvolume delete asd :

openat(AT_FDCWD, "/media/root", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
[...]
ioctl(3, BTRFS_IOC_SNAP_DESTROY, {fd=0, name="asd"}) = 0

BTRFS_IOC_SNAP_DESTROY

So there is no magic happening.

Not using the btrfs command removes the requirement to check for existence of that command or its version. Also the interface is more straight forward. (No parsing the output just getting a specific errno if something is wrong) And it should also be slightly faster ;)