5

Background

I maintain a series of hourly snapshots on my btrfs filesystem using btrbk. The subvolume and snapshots are stored like this (names shortened to make it easier to follow):

/@vol               (subvolume)
/btrbk/@vol.00      (snapshots of /@vol, one per hour)
/btrbk/@vol.01      ...
/home/user/vol      (mountpoint for /@vol)

Now I deleted a single file in /home/user/vol which I should not have deleted. No problem, I can easily restore from the latest snapshot:

# cd /home/user/vol
# cp -a --reflink=always /btrbk/@vol.01/all_ipv4_numbers.txt ./
cp: failed to clone './all_ipv4_numbers.txt' from '/btrbk/@vol.01/all_ipv4_numbers.txt': Invalid cross-device link

Seems I can't "reflink" the file. But I don't want to end up with two copies of the file. Ideally I want it to look like nothing happened between the most recent snapshot and the next snapshot that will be taken in the future.

(Yes, I also have actual backups, but restoring from snapshots are more convenient whenever available!)

Question

How do I restore a single file from a btrfs snapshot while keeping all the nice references and magic that makes btrfs know that it is the same data in all the snapshots?

1
  • If you edit your question to include all of the full names and paths, instead of shortened ones, I can give you an exact command to run in my answer. Oct 21, 2018 at 23:23

1 Answer 1

6

On Linux kernels older than 5.18 (specifically, commit 9f5710b), you could only use cp --reflink when the source and target were both on the same mount point. For this purpose, mounting the same filesystem to multiple directories didn't count. Either upgrade to Linux 5.18 or newer, or mount the "root" volume of the btrfs filesystem somewhere and then do cp --reflink between the snapshot subvolume and @vol that are under that directory.

You must log in to answer this question.

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