My /home partition consists of an entire physical disk. It is formatted as btrfs. I want to snapshot it. I'm confused regarding subvolume naming, in particular.
I am aware that there are similar questions, but each similar question seems to be asking something different from what I'm asking (and they are older, which means probably outdated, given the rapid development of btrfs). For example, the answer to this question is apparently not the answer to my question because my /home partition is a separate volume and the man page for btrfs shows a different command for creating snapshots now.
another similar problem, no solid solution.
someone else as confused as me on the naming issues
My question:
Starting simple: is this the correct command to take a simple snapshot of my home partition?
btrfs subvolume snapshot /home/@home /home/@home_snapshot_20120421
I got really brave and tested it and it does not work. The error is error accessing /home/@home
. As shown below, @home is listed.
I'm obviously confused on subvolume names. Do I need to use them in creating snapshots? Some examples show taking snapshots of home using /home
as the source parameter, but based on examples of root volumes, it seems to me that I need to use /home/@home
.
Would this command work? And if not, why?
btrfs subvolume snapshot /home /home/@home_snapshot_20120421
Is the @
just a naming convention? Is it meaningful at all?
Here's some output that may be relevant:
btrfs subvolume list /home
ID 256 top level 5 path @home
I'm not sure what that means, exactly. When I try btrfs device scan
it gives an error (e.g. unable to scan the device /dev/sda1). My file system doesn't have any errors. Everything is fine.
Here are my partitions. In response to one reply, no /home is not my only btrfs partition.
/dev/sda1: (boot partition) TYPE="ext2"
/dev/sda2: (root partition) TYPE="btrfs"
/dev/sdb1: (home partition) TYPE="btrfs"
/dev/sdc1: (shared partition) TYPE="btrfs"
/dev/sdc2: TYPE="swap"
Best Answer
What is the correct command to create a snapshot of my home partition on Ubuntu 12.04?
Given the fact that home is on a btrfs partition and it is mounted as /home, the correct command is:
Here are my results:
Before running the command today:
The command:
After running the command today:
The only issue with this method is that snapshots show up when you ls (list) /home.
The Ubuntu community Wiki has been updated with a solution for this. Here it is:
How to work with snaphots in Ubuntu's layout
In order to work with snapshots of / or /home in the Ubuntu layout it is very convenient to mount the btrfs filesystem at a separate location, and work from the top of the btrfs tree, rather than from the mounted subvolumes. <-- that is the solution. Unfortunately, it is not convenient.
To create a snapshot use the same syntax I used above:
This will create a snapshot of the @ subvolume named @_snapshot located also in the top of the btrfs tree. Since it is in the top of the tree, it will not show up when listing files in a mounted volume.
To roll back to a snapshot, you simply need to change its name to the name that ubuntu mounts and reboot. Here's how to change the name:
To delete a snapshot use:
btrfs snapshots are subvolumes in themselves, and self-contained, deleting the old @ subvolume like this is fine, provided we have a replacement.
NOTE: The btrfs-tools command
set-default
will break Ubuntu's layout.