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:
sudo btrfs subvolume snapshot /home/ /home/<any_name_you_choose_for_the_snapshot>
Here are my results:
Before running the command today:
$ btrfs subvolume list /home
ID 256 top level 5 path @home
ID 257 top level 5 path @home/@snapshot_20120521_1936
The command:
$ sudo btrfs subvolume snapshot /home/ /home/@snapshot_20120611_1307
Create a snapshot of '/home/' in '/home/@snapshot_20120611_1307'
After running the command today:
$ btrfs subvolume list /home
ID 256 top level 5 path @home
ID 257 top level 5 path @home/@snapshot_20120521_1936
ID 258 top level 5 path @home/@snapshot_20120611_1307
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.
sudo mount /dev/sdX# /mnt
To create a snapshot use the same syntax I used above:
sudo btrfs subvolume snapshot /mnt/@ /mnt/@_snapshot
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:
sudo mv /mnt/@ /mnt/@_badroot
sudo mv /mnt/@_snapshot /mnt/@
To delete a snapshot use:
sudo btrfs subvolume delete /mnt/@_badroot
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.
Best Answer
1) I have not seen any GUI or curses tool.
2) There are a couple of existing scripts out there. I haven't tried them, but they look interesting:
SnapBtr: https://btrfs.wiki.kernel.org/index.php/SnapBtr
btrfs-snap: http://blog.patshead.com/2010/11/tweak-btrfs-snap-for-more-frequent-snapshots.html
A related btrfs development is the announcement that Natty (11.04) will feature automatic btrfs rollback for packages. I.e., for btrfs installations it will automatically snapshot before any apt install/upgrade/remove operation: http://mvogt.wordpress.com/2011/03/10/apt-btrfs-snapshot/