What are the commands to use in btrfs in case I want to:

  1. create a (read-only) snapshot of a volume;
  2. (do some experiments in the volume);
  3. and then rollback the volume to the snapshot?

2 Answers 2

# take a read-only snapshot:
btrfs sub snap -r fs snapshot

... do things on fs

# rolling back:
btrfs sub del fs # at which point you'll lose those things you've done
                 # if you want to preserve them, just rename fs instead

btrfs sub snap snapshot fs # reinstate snapshot as a read+write fs
btrfs sub del snapshot # delete the non-longer needed read-only snapshot
  • 3
    I like how you snapshot the snapshot over the filesystem, instead of attempting to move it. It's elegant in analogy to copying the snapshot, rather than attempting to use and alter it. You might mention that this sequence will end up deleting everything done in the "... do things" step.
    – Bladt
    Jun 24, 2015 at 15:02
  • Here is what happened when I tried to restore the snapshot. I have a btrfs filesystem mounted at /mnt/sdc1, and I created a read-only snapshot named 20170917. btrfs sub del . > Delete subvolume (no-commit): '/mnt/sdc1' > ERROR: cannot delete '/mnt/sdc1': Invalid argument or btrfs sub snap 20170917/ . Create a snapshot of '20170917/' in './20170917' ERROR: cannot snapshot '20170917/': File exists
    – zkilnbqi
    Sep 17, 2017 at 19:59
  • Sorry about the poor formatting in the above comment. Markdown for comments is braindead.
    – zkilnbqi
    Sep 17, 2017 at 20:06
  • 1
    @Harold, sound like you can't delete the root volume that way. There may be ways to do it, but I have to admit it's been 5 years since I last used btrfs as I gave up on it as it had too many stability, performance and reliability issues. It may be more usable now, but the end of the story is that I'm not so familiar with it anymore (not to mentioned that it has probably evolved a lot as well since). Sep 17, 2017 at 20:13
  • 1
    Thanks. It seems to be the best choice on Linux right now for a modern filesystem, if I can figure out how to use it.
    – zkilnbqi
    Sep 17, 2017 at 20:15

Try from the other side: create R/W snapshot, use it as new main one, do "some experiments" on old one, then just drop contents of old.

Article "BTRFS Fun" can be helpful.

  • the linked article no longer exists :( Jun 12, 2022 at 9:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .