BTRFS: moving data between subvolumes efficiently

If you move files naively between BTRFS subvolumes like this:

cd /btrfs
mv volume1/dir volume2/dir

… the data will be effectively read from and written back to the physical storage, which can become a problem if you have many or big files, especially when the partition is encrypted.

Instead, you should use “reflink”‘s, creating effectively lightweight a copy of your data, e.g. a copy that shares initially the physical data of the original files. Only when you modify the original or copy, the data will be physically duplicated.

cd /btrfs
cp -pr --reflink=always volume1/dir volume2/dir
rm -rf volume1/dir

I usually prefer rsync over cp, because it can resume easily when aborted, and also because of the –progress option, but unfortunately, it doesn’t support reflink’s yet, even though some work has been done on this.

This entry was posted in Linux. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s