2

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?

  • 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. – Joseph Sible Oct 21 '18 at 23:23
3

You can only use cp --reflink when the source and target are both on the same mount point. For this purpose, mounting the same filesystem to multiple directories doesn't count. Mount the "root" volume of the btrfs filesystem somewhere, then do cp --reflink between the snapshot subvolume and @vol that are under that directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.