After several years, I'm still just scratching the surface of all the wonderful tools btrfs has in it's kit. Today, I'm re-arranging drive space due to an upcoming (hopefully ) system upgrade later this year. I'll skip the why-fors and get to the brass tacks:
I installed 15.04 to an HD. I want to move the entire install and it's home to my SSD. I'm going to use a feature set of btrfs called send and receive. The send command "sends" the subvolume and preserves all the links and such. The normal output of the btrfs send command outputs to stout so you can pipe it to a file for later use or directly to a new subvolume using btrfs receive. I will do the latter.
For reference: the two mounts in use are /mnt/red and /mnt/samsung, the source subvolume on /mnt/red is @Kubuntu_15.04. I actually did this on the @home subvolume also, but the commands are identical and don't need repeating. All these commands were done in root mode via sudo -i.
Preparation for this task requires that the source subvolume for the send command must be read only. This is to prevent writes during a send or receive operation causing corruption. Since this is an install subvolume, not a data backup, I must create a read-only copy before sending it. With btrfs this is simple and immediate:
subvolume snapshot -r /mnt/red/@Kubuntu_15.04 /mnt/red/@Kubuntu_15.04_snap
To ensure the snapshot is complete, issued a sync command (but I doubt it was needed).
btrfs filesystem sync /mnt/red
Now I sent the read-only subvolume snapshots from "red" to "samsung"
btrfs send /mnt/red/@Kubuntu_15.04_snap | btrfs receive /mnt/samsung
and in a few minutes, here's the listing from both filesystems:
Currently, there's no way available to change a read-only snapshot back to read-write. No biggie - make a new read-write snapshot of the read-only snapshot (and fix the name in the bargin!):
btrfs subvolume snapshot /mnt/samsung/@Kubuntu_15.04_snap /mnt/samsung/@Kubuntu_15.04
Now /mnt/samsung looks like:
Since the read-only snapshots are no longer needed - let's delete them:
root@office:/mnt/samsung# btrfs subvolume delete /mnt/samsung/@Kubuntu_15.04_home_snap /mnt/samsung/@Kubuntu_15.04_snap /mnt/red/@Kubuntu_15.04_snap /mnt/red/@Kubuntu_15.04_home_snap/
Done. Now a full usable, bootable copy of Kubuntu 15.04 and it's home reside on two drives on my system. The last change I need to make is to fix the UUIDs in the newly moved subvolume to match the new filesystem location. This whole operation took less than 15 minutes - and that includes typing this post!
The send/receive operation can be used to make a full backup of a subvolume and can even be done incrementally using the "parent" switch or over a NFS connection. The combination of snapshots and send/receive backups can all be scripted and combined to create a really data-safe system.
I installed 15.04 to an HD. I want to move the entire install and it's home to my SSD. I'm going to use a feature set of btrfs called send and receive. The send command "sends" the subvolume and preserves all the links and such. The normal output of the btrfs send command outputs to stout so you can pipe it to a file for later use or directly to a new subvolume using btrfs receive. I will do the latter.
For reference: the two mounts in use are /mnt/red and /mnt/samsung, the source subvolume on /mnt/red is @Kubuntu_15.04. I actually did this on the @home subvolume also, but the commands are identical and don't need repeating. All these commands were done in root mode via sudo -i.
Preparation for this task requires that the source subvolume for the send command must be read only. This is to prevent writes during a send or receive operation causing corruption. Since this is an install subvolume, not a data backup, I must create a read-only copy before sending it. With btrfs this is simple and immediate:
subvolume snapshot -r /mnt/red/@Kubuntu_15.04 /mnt/red/@Kubuntu_15.04_snap
To ensure the snapshot is complete, issued a sync command (but I doubt it was needed).
btrfs filesystem sync /mnt/red
Now I sent the read-only subvolume snapshots from "red" to "samsung"
btrfs send /mnt/red/@Kubuntu_15.04_snap | btrfs receive /mnt/samsung
and in a few minutes, here's the listing from both filesystems:
Code:
root@office:/mnt/red# ll /mnt/red total 16 drwxr-xr-x 1 root root 220 Feb 20 13:26 ./ drwxr-xr-x 1 root root 68 Feb 1 01:12 ../ drwxr-xr-x 1 root root 212 Feb 17 13:20 @Kubuntu_15.04/ drwxr-xr-x 1 root root 32 Feb 15 16:36 @Kubuntu_15.04_home/ drwxr-xr-x 1 root root 32 Feb 15 16:36 @Kubuntu_15.04_home_snap/ drwxr-xr-x 1 root root 212 Feb 17 13:20 @Kubuntu_15.04_snap/ drwxrwsr-x 1 root backup 34 Feb 18 13:35 @media_backup/ root@office:/mnt/red#
Code:
root@office:/mnt/red# ll /mnt/samsung/ total 4 drwxr-xr-x 1 root root 268 Jan 31 23:52 ./ drwxr-xr-x 1 root root 68 Feb 1 01:12 ../ drwxr-xr-x 1 root root 348 Feb 16 11:56 @Kubuntu_14_04/ drwxr-xr-x 1 root root 48 Jan 25 16:21 @Kubuntu_14_04_home/ drwxr-xr-x 1 root root 274 Jan 27 11:56 @Kubuntu_14_10_plasma5/ drwxr-xr-x 1 root root 32 Jan 25 16:21 @Kubuntu_14_10_plasma5_home/ drwxr-xr-x 1 root root 32 Feb 20 13:53 @Kubuntu_15.04_home_snap/ drwxr-xr-x 1 root root 212 Feb 20 13:34 @Kubuntu_15.04_snap/ drwxr-xr-x 1 root root 1168 Feb 4 14:09 snapshots/ root@office:/mnt/red#
btrfs subvolume snapshot /mnt/samsung/@Kubuntu_15.04_snap /mnt/samsung/@Kubuntu_15.04
Now /mnt/samsung looks like:
Code:
root@office:/mnt/samsung# ll total 4 drwxr-xr-x 1 root root 334 Feb 20 14:13 ./ drwxr-xr-x 1 root root 68 Feb 1 01:12 ../ drwxr-xr-x 1 root root 348 Feb 16 11:56 @Kubuntu_14_04/ drwxr-xr-x 1 root root 48 Jan 25 16:21 @Kubuntu_14_04_home/ drwxr-xr-x 1 root root 274 Jan 27 11:56 @Kubuntu_14_10_plasma5/ drwxr-xr-x 1 root root 32 Jan 25 16:21 @Kubuntu_14_10_plasma5_home/ drwxr-xr-x 1 root root 212 Feb 20 13:34 @Kubuntu_15.04/ drwxr-xr-x 1 root root 32 Feb 20 13:53 @Kubuntu_15.04_home/ drwxr-xr-x 1 root root 32 Feb 20 13:53 @Kubuntu_15.04_home_snap/ drwxr-xr-x 1 root root 212 Feb 20 13:34 @Kubuntu_15.04_snap/ drwxr-xr-x 1 root root 1168 Feb 4 14:09 snapshots/ root@office:/mnt/samsung#
root@office:/mnt/samsung# btrfs subvolume delete /mnt/samsung/@Kubuntu_15.04_home_snap /mnt/samsung/@Kubuntu_15.04_snap /mnt/red/@Kubuntu_15.04_snap /mnt/red/@Kubuntu_15.04_home_snap/
Done. Now a full usable, bootable copy of Kubuntu 15.04 and it's home reside on two drives on my system. The last change I need to make is to fix the UUIDs in the newly moved subvolume to match the new filesystem location. This whole operation took less than 15 minutes - and that includes typing this post!
The send/receive operation can be used to make a full backup of a subvolume and can even be done incrementally using the "parent" switch or over a NFS connection. The combination of snapshots and send/receive backups can all be scripted and combined to create a really data-safe system.
Comment