Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
21
rated 0 times [  21] [ 0]  / answers: 1 / hits: 31051  / 2 Years ago, sun, july 3, 2022, 10:03:37

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"

More From » backup

 Answers
6

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.


[#39170] Monday, July 4, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
admin

Total Points: 459
Total Questions: 112
Total Answers: 109

Location: Equatorial Guinea
Member since Sun, Feb 14, 2021
3 Years ago
;