I have a live btrfs filesystem of 3.7TiB that's >90% full including old snapshots and a fresh 4TB backup harddisk. How to copy all existing snapshots to the backup harddisk?
I tried
# btrfs send home_1 home_2 home_3 share_1 share_2 share_3 ...
but the backup harddisk was full before 2/3 of the snapshots were transmitted. So I did some research:
# ### create test image
# dd bs=1M count=1000 > btrfs_test.dd
# mkfs.btrfs btrfs_test.dd
# ### create snapshots
# btrfs subvol create testvol/
# btrfs subvol snapshot -r testvol/ testvol_0/
# ### (copy some ISO image)
# btrfs subvol snapshot -r testvol/ testvol_1/
# ### (proceed until testvol_3)
My test filesystem then was 91% full with 818MiB used.
# btrfs send testvol_* | wc -c
At subvol testvol_0
At subvol testvol_1
At subvol testvol_2
At subvol testvol_3
1466441978 # 1398MiB >> 1000MiB
When simply sending all the snapshots with 1 command, data is duplicated and the size of the stream as well as the size of the snapshots at the receiver's end exceed the original used space and the harddisk's capacity.
So the actual question became: How to copy multiple snapshots without duplicating data that is contained in 2 or more of them?
For this simple test case I successfully tried the incremental approach:
# ( btrfs send testvol_0; btrfs send -p testvol_0 testvol_1; btrfs send -p testvol_1 testvol_2; btrfs send -p testvol_2 testvol_3 ) | wc -c
At subvol testvol_0
At subvol testvol_1
At subvol testvol_2
At subvol testvol_3
838778546 # 800 MiB < 1000MiB
But on the real filesystem there are multiple subvolumes, each of them with multiple snapshots. I can't define any order to use with -p
. If a data block is shared among the subvolumes home_1
, home_2
and share_3
I want to transmit and store it only once, of course. Any ideas how to do this?