You are not logged in.

#1 2024-09-13 14:40:18

gabx
Member
From: Geneva, Switzerland
Registered: 2011-11-20
Posts: 245
Website

[SOLVED] how to restore btrfs snapshot

I want to restore my @home subvolume from a snapshot after I wrongly deleted most of my home directory.

Here is what I did:

# mount /dev/nvme0n1p2 /mnt
# btrfs subvolume list /mnt    
ID 256 gen 86438 top level 5 path @
ID 257 gen 86438 top level 5 path @home
ID 258 gen 86383 top level 5 path @tmp
ID 259 gen 86438 top level 5 path @log
ID 260 gen 84484 top level 5 path @pkg
ID 261 gen 45706 top level 5 path @docker
ID 264 gen 20 top level 256 path @/var/lib/portables
ID 265 gen 20 top level 256 path @/var/lib/machines
ID 272 gen 84411 top level 5 path @development
ID 273 gen 80700 top level 256 path @/.snapshots/@back-home-20240911143034  <--- I want to restore this one
ID 274 gen 84002 top level 256 path @/.snapshots/@back-home-20240912193352
ID 279 gen 84518 top level 256 path @/.snapshots/@back-home-20240913000113
# btrfs subvolume delete /mnt/@home

# btrfs subvolume snapshot /mnt/@/.snapshots/@back-home-20240911143034 /mnt/@home

Create snapshot of '/mnt/@/.snapshots/@back-home-20240911143034' in '/mnt/@home'
$ ls -al /mnt/@home/gabx  shows all my home directories
# umount /mnt
# btrfs subvolume list / 
....
ID 280 gen 86605 top level 5 path @home
$ ls -al /home
total 0

Now I have no idea how to get back /home/gabx with all my data. For now, if I list my home dir, I only found a very few data and not the ones I have deleted and want to restore

Last edited by gabx (2024-09-15 15:50:52)

Offline

#2 2024-09-13 18:45:34

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: [SOLVED] how to restore btrfs snapshot

Your data would be available under /mnt/@home/ rather than /home/ because the new snapshot hasn't been mounted in the main ("root") filesystem.

/etc/fstab will need to be modified if the /home/ line uses the subvolid as an identifier, the ID is different for the new @home subvolume.


Jin, Jîyan, Azadî

Offline

#3 2024-09-13 19:22:33

ua4000
Member
Registered: 2015-10-14
Posts: 558

Re: [SOLVED] how to restore btrfs snapshot

in addition:
- I would do such "critical" work from a live dvd/usb + clean restart afterwards. It looks like you did the repair from a running system...
- instead "...subvolume delete ..." use  "mv /mnt/@home /mnt/@home.defect" - this is much safer.
- inspect @/.snapshots/@back-home-20240911143034 - are here all expected files present ?

Edit: don't consider btrfs snapshots as reliable backup. If a BTRFS got's corrupt, snapshots may as well be defect.

Last edited by ua4000 (2024-09-13 19:25:53)

Offline

#4 2024-09-15 15:50:31

gabx
Member
From: Geneva, Switzerland
Registered: 2011-11-20
Posts: 245
Website

Re: [SOLVED] how to restore btrfs snapshot

Head_on_a_Stick wrote:

Your data would be available under /mnt/@home/ rather than /home/ because the new snapshot hasn't been mounted in the main ("root") filesystem.

/etc/fstab will need to be modified if the /home/ line uses the subvolid as an identifier, the ID is different for the new @home subvolume.

Yes indeed all my data are on /mnt/@home

# mount /dev/nvme0n1p2 /mnt
# btrfs subvolume list /mnt 
....
ID 280 gen 102913 top level 5 path @home
# ls -al /mnt/@home/gabx 
drwx------ 1 gabx gabx  580 Aug 30 17:38  ./
drwxr-xr-x 1 root root   24 Sep  5 12:57  ../
drwx------ 1 gabx gabx  944 Sep 11 13:04  .cache/
drwxr-xr-x 1 gabx gabx  118 Jul 11 23:51  .cargo/
drwx------ 1 gabx gabx  986 Sep 11 12:57  .config/
....

But in fact, I just rebooted my box without any change of my fstab, and my home dir was again availabe with all data. Here is part of my fstab:

/dev/nvme0n1p2 LABEL=Magnolia
UUID=6ca0f63e-7327-444e-af89-ac82d08fda59	/home     	btrfs     	rw,noatime,ssd,discard,space_cache=v2,subvol=/@home	0 0

Offline

#5 2024-09-15 16:00:35

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: [SOLVED] how to restore btrfs snapshot

The fstab line doesn't use "subvolid" so it will continue to work as long as it is still called "@home" because the name of the subvolume is the only identifier.


Jin, Jîyan, Azadî

Offline

#6 2024-09-15 16:03:30

gabx
Member
From: Geneva, Switzerland
Registered: 2011-11-20
Posts: 245
Website

Re: [SOLVED] how to restore btrfs snapshot

Head_on_a_Stick wrote:

The fstab line doesn't use "subvolid" so it will continue to work as long as it is still called "@home" because the name of the subvolume is the only identifier.

Ok, very good, as I made this behavior following the wiki advice:
>>  It is preferable to mount using subvol=/path/to/subvolume, rather than the subvolid, as the subvolid may change when restoring #Snapshots, requiring a change of mount configuration.<<

Offline

Board footer

Powered by FluxBB