1

Background

I am playing around with BTRFS in a VM.

I followed this guide to make sure my /home/.snapshot folder is its own sub-volume. Everything seems to work, I can take snapshots, list snapshots, undochanges, etc.

Experimenting with Send/Receive

Steps:

  • Use send/receive to send snapshot id 1 to a different subvol
  • Use snapper to delete the snapshot id 1
  • Use send/receive to bring snapshot id 1
  • Snapper no longer recognizes snapshot id 1

Details:

I sent an existing snapshot to a different sub-volume (device)

sudo btrfs subvolume list -t /mnt_device3
ID      gen     top level       path
--      ---     ---------       ----
256     9       5               @backup

sudo mkdir /backup/1
sudo btrfs send /home/.snapshots/1/snapshot | sudo btrfs receive /backup/1
sudo btrfs subvolume list -t /backup                                      
ID      gen     top level       path
--      ---     ---------       ----
256     17      5               @backup
258     18      256             1/snapshot

Then I used snapper to delete the snapshot:

sudo snapper -c home delete 1

sudo snapper -c home list
 # | Type   | Pre # | Date                        | User | Cleanup | Description                                      | Userdata
---+--------+-------+-----------------------------+------+---------+--------------------------------------------------+---------
0  | single |       |                             | root |         | current                                          |         
2  | single |       | Tue 04 Jul 2023 03:20:01 PM | root |         | testing send/receive after test.txt |    

Then I used send/receive again to put the snapshot back

sudo mkdir /home/.snapshots/1
sudo btrfs send /backup/1/snapshot | sudo btrfs receive /home/.snapshots/1
ls /home/.snapshots 
total 0
drwxr-xr-x 1 root root  6 Jul  4 16:30 .
drwxr-xr-x 1 root root 32 Jun 29 11:36 ..
drwxr-xr-x 1 root root 16 Jul  4 16:11 1
drwxr-xr-x 1 root root 32 Jul  4 15:20 2

#an excerpt of sudo btrfs subvolume list /home
ID 311 gen 1147 top level 272 path 2/snapshot
ID 313 gen 1214 top level 272 path 1/snapshot

But snapper does not recognize snapshot 1

sudo snapper -c home list
 # | Type   | Pre # | Date                        | User | Cleanup | Description                                      | Userdata
---+--------+-------+-----------------------------+------+---------+--------------------------------------------------+---------
0  | single |       |                             | root |         | current                                          |         
2  | single |       | Tue 04 Jul 2023 03:20:01 PM | root |         | testing send/receive after test.txt |  

So I can't really use snapper to do anything with snapshot 1 anymore.

Is there a way I can get snapper to recognize the imported snapshot?

1 Answer 1

2

AFAIK, snapper maintains a database to track the snapshots that it creates. When you did # snapper -c home delete 1, you removed both the snapshot itself and the corresponding entry in the database. Restoring the snapshot directory with BTRFS send/receive doesn't put the information about that snapshot back into the database.

You could try to manually create a new snapshot with the same ID, but this might not be what you're after, since the timestamps and other metadata in the database won't match the restored snapshot:

# manually create snapshot
sudo snapper -c home create --description "Restored snapshot 1"

# replace the snapshot ('3' is an example ID; replace it with the one you actually get)
sudo mv /home/.snapshots/3/snapshot /home/.snapshots/3/snapshot.bak
sudo mv /home/.snapshots/1/snapshot /home/.snapshots/3/snapshot
3
  • That's interesting. I kind of guessed as much. Is there a way i can send/recieve the results of snapper? I want to be able to back up the snapshots.
    – hba
    Jul 7, 2023 at 23:44
  • Yes, but it works best when the source and target subvolumes are in sync, except for the differences you want to send. You'd also have to mount the destination volume with the -o subvol=@ option to ensure that the received subvolumes are placed correctly.
    – telometto
    Jul 8, 2023 at 13:14
  • Thanks I think I'll open a new question about backing up snapper. I did not really understand the comment above.
    – hba
    Jul 8, 2023 at 18:42

You must log in to answer this question.

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