4

I want to try Btrfs. I've already found that you can make a snapshot of a live system but there are a few thing I haven't found answers for. Well, as I understand a snapshot basically a full copy in archive form of some sort. So can I make a snapshot of my live btrfs system and place that snapshot on my non btrfs hard drive (ext4, for example)?

Also, I'm running full disk encryption (luks). Are snapshots going to be encrypted if I transfer them somewhere? Do snapshots copy actual data from the partition itself (in that case it's going to be encrypted obviously) or it works differently?

Also, how are btrfs snapshots protected from read acess? Can other users read snapshots? Or only root? Is it managable?

3

A snapshot (in this sense) is a part of the filesystem. In btrfs terminology, it's a subvolume — it's one of the directory trees on the volume. It isn't in “archive form”. Making a snapshot of a subvolume creates a new subvolume which contains the data of the original volume at the date the snapshot was made. Subsequent writes to the original subvolume don't affect the snapshot and vice versa. All subvolumes are part of the same volume — they designate subsets (potentially overlapping) of the data in the volume.

The parts of the snapshot that haven't been modified in either subvolume share their storage. Creating a snapshot initially requires no storage except for the snapshot control data; the amount of storage increases over time as the content of the subvolumes diverge.

The most important property of snapshot creation is that it's atomic: it takes a picture of the data at a point in time. This is useful to make backups: if the backup program copies files from the live system, it might interact poorly with modifications to the files. For example, if a file is moved from directory A to directory B, but the backup program traversed B before the move and A after the move, the file wouldn't be included in the backup. Snapshots solve this problem: the file will be in A if the snapshot is made before the move and in B if it's made after, but either way it will be there. Then the backup program can copy from the snapshot to the external media.

Since the snapshot is on the same volume as the original, it's stored in the same way, e.g. it's encrypted if the volume is encrypted.

A snapshot reproduces the original directory tree, including permissions and all other metadata. So the permissions are the same as the original. In addition, users must be able to access the snapshot directory itself. If you don't want users to be able to access a snapshot at all, create it under a directory that they can't access (you can place the snapshot anywhere you want).

If you want to make a copy of the snapshot outside the filesystem, access or mount the snapshot then make a copy with your favorite program (cp, rsync, etc.). You can find sample commands in the btrfs wiki; see the manual page for a full reference.

4

I will just add to Gilles' answer by saying that although you may use “cp, rsync, etc.” to transfer your read-only subvolumes / snapshots, you may also send and store the subvolumes as btrfs streams using the btrfs send command. The btrfs Wiki mentions the following use:

# btrfs subvolume snapshot -r / /my/snapshot-YYYY-MM-DD && sync
# btrfs send /my/snapshot-YYYY-MM-DD | ssh user@host btrfs receive /my/backups
# btrfs subvolume snapshot -r / /my/incremental-snapshot-YYYY-MM-DD && sync
# btrfs send -p /my/snapshot-YYYY-MM-DD /my/incremental-snapshot-YYYY-MM-DD |
    ssh user@host btrfs receive /backup/home

but you may also just save the streams for future use:

# btrfs subvolume snapshot -r / /my/snapshot-YYYY-MM-DD && sync
# btrfs send /my/snapshot-YYYY-MM-DD |
    ssh user@host 'cat >/backup/home/snapshot-YYYY-MM-DD.btrfs'
# btrfs subvolume snapshot -r / /my/incremental-snapshot-YYYY-MM-DD && sync
# btrfs send -p /my/snapshot-YYYY-MM-DD /my/incremental-snapshot-YYYY-MM-DD |
    ssh user@host 'cat >/backup/home/incremental-snapshot-YYYY-MM-DD.btrfs'

This is useful to store the verbatim btrfs snapshots at arbitrary filesystems. The advantage over, say, tar is that btrfs snapshots are incremental and only the delta gets sent. The btrfs Wiki claims that this method of incremental backup tends to be even faster than rsync.

  • Just wanted to mention one downside to backing up using the latter method: When or if it comes time to restore from those backup files, you will have to use btrfs receive on all of them, one at a time in the same sequence. FWIW, I'm currently working on a backup tool that confers all the advantages of btrfs send without this and other downsides; it currently works with thin lvm but can be adapted to btrfs. – tasket Jun 5 at 20:42

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.