9

Is it possible to backup a btrfs partition verbatim (including all the shared structures which save space by marking snapshot trees as COW) to another one? For instance, I'd like to backup my root partition which has couple of btrfs subvolumes (snapshots of the / itself).

The only way I can think is to use a block copying tool like dd but that is inefficient as my partition is only 20% full and I intend to back it up regularly. I already backup everything incrementally using rsync, so this is not a workaround for another problem. I simply need a bit for bit clone of my btrfs partition without having to use a tool such as dd.

I know ext3, for instance, provides a dump and restore utility. That is the kind of thing I'm looking for.

UPDATE

Here is a update to clarify the fact that I want to be able to access the files on the backup storage the same way I can on the live disk (ie I do not want to store dump files on the backup storage).

Jonas Stein
  • 392
  • 4
  • 13
Mansour
  • 499
  • 2
  • 7
  • 14

5 Answers5

6

partclone is the tool you are looking for.

  • it supports a lot of linux file systems, including BTRFS
  • it even supports some other filesystems (like FAT or exFAT)
  • unlike dd it looks at the file systems allocation map (e.g.: FAT and exFAT's FAT tables, BTRFS extent maps, etc.) and clones only the used blocks.

Depending on your usage pattern:

  • use the -b (long: --dev-to-dev) if both source and backup target black device are visible on the same machine (basically if both disks are plugged into the same computer).
  • or use -c and -r (long: --clone and --restore) to first clone to partclone's own image format on the source machine, and then restore from the image on the backup machine
  • according to partclone manpage, it's possible to pipe images, so it should be possible to copy partitions over the network without saving actual files, if you're running short on space, but have an extremely reliable network.

A completely different way to handle the problem would be using btrfs send and btrfs receive mechanism.

  • This WON'T produce block device copies down to the sector
  • but, by correctly providing references on both ends, it is also able to keep the references between ref-linked (parts of) files.

So btrfs' own mechanism isn't a sector perfect copy (unlike partclone's) but it's an extent perfect copy (much better than rsynv -aSHAX which only handles hardlinked files).

DrYak
  • 523
  • 5
  • 6
1

Pipe the output of dd through something like bzip2 or your other favourite compression program that'll read from standard input. I've done this on a 500 GB disk that had a relatively small install and ended up with an 8 GB file.

Cry Havok
  • 1,825
  • 13
  • 10
  • 3
    You would have to fill up the free space with zeroes first (e.g. `cat /dev/zero > zeroes`) to get rid of the unlinked data which is still on the disk. But that might not work anymore when BTRFS gets block-level data deduplication in the future. – Wim Coenen Oct 11 '10 at 10:25
  • Please see the update to my question. – Mansour Oct 11 '10 at 11:50
1

Not tried yet, but btrfs-image seems to solve this problem:

https://btrfs.wiki.kernel.org/index.php/Manpage/btrfs-image

Update: Do not use this as backup. Thank you for the comment.

I leave this open and will not delete it, so that others can learn from it too.

Jonas Stein
  • 392
  • 4
  • 13
  • 4
    Warning, btrfs-image only copies the META-data, not the data in the files themselves. (It's used to send a copy to the developers so they can see what's gone wrong. Not to copy the data). – DrYak Nov 09 '16 at 22:13
  • DESCRIPTION btrfs-image is used to create an image of a btrfs filesystem. All data will be zeroed, but metadata and the like is preserved. Mainly used for debugging purposes. – Arunas Bartisius Sep 23 '20 at 12:23
-2

just fyi ext2/3/4 dump doesen't do what you want to do ... only fs capable of doing this i am aware of are ntfs (using ntfs-3g) and zfs

though you could pull this off using lvm and and experimental thin provisioning ...

Edit: got back to this few years later realizing, you can do this with any filesystem using squashfs ...

Fox
  • 3,887
  • 16
  • 23
  • partclone has been able to do exactly that for lots of partitions which are not ntfs-3g nor zfs. – DrYak Nov 09 '16 at 23:20
  • @DrYak mountable sparse images of NTFS definitely is supported by ntfsclone ... https://linux.die.net/man/8/ntfsclone – Fox Nov 11 '16 at 19:27
-3

I think apparently there isn't such a tool (yet, ATM).

poige
  • 9,171
  • 2
  • 24
  • 50