Exploring btrfs for backups Part 6: Backup Drives and changing RAID levels VM


Hard drives are relatively cheap, especially nowadays. But I still want to stay within my budget as I setup my backups and system redundancies. So, ideally, for my backup RAID I’d take advantage of btrs’ ability to change RAID types on the fly and start off with one drive. Then I’d add another and go to RAID1. Then another and RAID5. Finally, the fourth drive and RAID6. At that point I’d have to be under some sort of Job-like God/Devil curse if all my drives failed at once, negating the point of the RAID. The best thinking right now is that you want to have backups, but want to try not to have to use them because of both offline time and the fact that a restore is never as clean as you hope it’ll be.

Let’s get started! I’ve added a third drive to my VM. Time to format and partition the drive. I do this with gParted. Interestingly, after the last post – gParted is a bit confused about what’s going on – again, btrfs isn’t exactly transparent with what it’s doing, especially when you have RAID setup. It shows the data as being stored on the second hard drive and nothing on the first one. The fact that sdb1 and sdb2 are unknown file systems and empty seems to go along with what I said yesterday about the fact that I don’t think it was properly set up to be able to boot from that system should the main hard drive die. So if you followed along with part 5 – make sure you take care of that if you’re doing RAID on your boot hard drive.

OK, now that the partition is created, I create a backup directory under /media/backup. Then I create a btrfs subvolume there.

$ sudo mount -t btrfs /dev/sdc1 /media/backup/
$ sudo btrfs subvolume create /media/backup/backups
Create subvolume '/media/backup/backups'
$ sudo btrfs fi show
Label: 'fedora' uuid: e5d5f485-4ca8-4846-b8ad-c00ca8eacdd9
 Total devices 2 FS bytes used 2.83GiB
 devid 1 size 6.71GiB used 3.62GiB path /dev/sda3
 devid 2 size 6.71GiB used 3.62GiB path /dev/sdb3
Label: 'Backup' uuid: 7042f4b7-9815-44f4-aef9-81103fc5855b
 Total devices 1 FS bytes used 208.00KiB
 devid 1 size 8.00GiB used 855.00MiB path /dev/sdc1

Looks like I’m in a good place. Just need to add this to fstab. Alright, everything should now be set to grow this into a RAID1. Time to shut off the VM to add another hard drive.

Alright, so far everything is working correctly. I created a couple folders and a file to make sure the data survives in tact. So, in yesterday’s post I said I wouldn’t be using the sfdisk thing, but I think it’s probably a great shortcut to make sure everything is right in case I do something weird in gParted.

$ sudo sfdisk -d /dev/sdc | sudo sfdisk /dev/sdd
sfdisk: Checking that no-one is using this disk right now ...
sfdisk: OK
Disk /dev/sdd: 1044 cylinders, 255 heads, 63 sectors/track
sfdisk: /dev/sdd: unrecognized partition table type
Old situation:
sfdisk: No partitions found
New situation:
Units: sectors of 512 bytes, counting from 0
Device Boot Start End #sectors Id System
/dev/sdd1 1 16777215 16777215 ee GPT
/dev/sdd2 0 - 0 0 Empty
/dev/sdd3 0 - 0 0 Empty
/dev/sdd4 0 - 0 0 Empty
sfdisk: Warning: partition 1 does not end at a cylinder boundary
sfdisk: Warning: no primary partition is marked bootable (active)
This does not matter for LILO, but the DOS MBR will not boot this disk.
Successfully wrote the new partition table
Re-reading the partition table ...
sfdisk: If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)
Looks good. Time to add it to btrfs. Strangely, it doesn't appear to work. (Complains there isn't an sdd1)  Ok, let's try gParted, then.
$ sudo btrfs device add -f /dev/sdd1 /media/backup/

I had to use -f because I’d put a btrfs partition on there – I probably should have selected unallocated or something. Let’s make sure this makes sense:

$ sudo btrfs fi show
Label: 'fedora' uuid: e5d5f485-4ca8-4846-b8ad-c00ca8eacdd9
 Total devices 2 FS bytes used 2.84GiB
 devid 1 size 6.71GiB used 3.62GiB path /dev/sda3
 devid 2 size 6.71GiB used 3.62GiB path /dev/sdb3
Label: 'Backup' uuid: 7042f4b7-9815-44f4-aef9-81103fc5855b
 Total devices 2 FS bytes used 208.00KiB
 devid 1 size 8.00GiB used 855.00MiB path /dev/sdc1
 devid 2 size 8.00GiB used 0.00 path /dev/sdd1

Looks good to me. Time to RAID1 it.

$ sudo btrfs balance start -dconvert=raid1 -mconvert=raid1 /media/backup/
Done, had to relocate 5 out of 5 chunks

It took 30 seconds because there wasn’t really anything to move.

$ sudo btrfs fi show
Label: 'fedora' uuid: e5d5f485-4ca8-4846-b8ad-c00ca8eacdd9
 Total devices 2 FS bytes used 2.84GiB
 devid 1 size 6.71GiB used 3.62GiB path /dev/sda3
 devid 2 size 6.71GiB used 3.62GiB path /dev/sdb3
Label: 'Backup' uuid: 7042f4b7-9815-44f4-aef9-81103fc5855b
 Total devices 2 FS bytes used 464.00KiB
 devid 1 size 8.00GiB used 1.28GiB path /dev/sdc1
 devid 2 size 8.00GiB used 1.28GiB path /dev/sdd1

And, checking the RAID levels:

$ sudo btrfs fi df /media/backup/
Data, RAID1: total=1.00GiB, used=320.00KiB
System, RAID1: total=32.00MiB, used=16.00KiB
Metadata, RAID1: total=256.00MiB, used=128.00KiB
unknown, single: total=16.00MiB, used=0.00

Excellent! But this isn’t anything special over yesterday’s post. Now let’s add a third backup harddrive. This time I go straight for gParted and use a partition type of unformatted.

Now a quick check that my files are there:

$ tree /media/backup/
/media/backup/
??? test1
??? test2
 ??? Iamintest2

Yup! Let’s keep going.

$ sudo btrfs device add /dev/sde1 /media/backup/

No errors this time. As always, a double-check.

$ sudo btrfs fi show
Label: 'fedora' uuid: e5d5f485-4ca8-4846-b8ad-c00ca8eacdd9
 Total devices 2 FS bytes used 2.85GiB
 devid 1 size 6.71GiB used 3.62GiB path /dev/sda3
 devid 2 size 6.71GiB used 3.62GiB path /dev/sdb3
Label: 'Backup' uuid: 7042f4b7-9815-44f4-aef9-81103fc5855b
 Total devices 3 FS bytes used 464.00KiB
 devid 1 size 8.00GiB used 1.28GiB path /dev/sdc1
 devid 2 size 8.00GiB used 1.28GiB path /dev/sdd1
 devid 3 size 8.00GiB used 0.00 path /dev/sde1

Perfect. Time for RAID5!

$ sudo btrfs balance start -dconvert=raid5 -mconvert=raid5 /media/backup/
Done, had to relocate 3 out of 3 chunks

Again, a quick finish because not many files there; 10-20 seconds. So, the checks:

$ sudo btrfs fi show
Label: 'fedora' uuid: e5d5f485-4ca8-4846-b8ad-c00ca8eacdd9
 Total devices 2 FS bytes used 2.85GiB
 devid 1 size 6.71GiB used 3.62GiB path /dev/sda3
 devid 2 size 6.71GiB used 3.62GiB path /dev/sdb3
Label: 'Backup' uuid: 7042f4b7-9815-44f4-aef9-81103fc5855b
 Total devices 3 FS bytes used 720.00KiB
 devid 1 size 8.00GiB used 1.16GiB path /dev/sdc1
 devid 2 size 8.00GiB used 1.16GiB path /dev/sdd1
 devid 3 size 8.00GiB used 1.16GiB path /dev/sde1

And RAID check:

$ sudo btrfs fi df /media/backup/
Data, RAID5: total=2.00GiB, used=576.00KiB
System, RAID5: total=64.00MiB, used=16.00KiB
Metadata, RAID5: total=256.00MiB, used=128.00KiB
unknown, single: total=16.00MiB, used=0.00

Alright. No issues expected with that. So let’s see if RAID6 is just as easy. Created another file so see if RAID5 overhead caused any issues. None that I could see, but I’m not exactly running this on a critical database or something.

$ tree /media/backup/
/media/backup/
??? test1
?   ??? hahaha
??? test2
 ??? Iamintest2

OK. let’s get to it! gParted again. Add the device:

$ sudo btrfs device add /dev/sdf1 /media/backup/

And the usual checks:

$ sudo btrfs fi show
Label: 'fedora' uuid: e5d5f485-4ca8-4846-b8ad-c00ca8eacdd9
 Total devices 2 FS bytes used 2.85GiB
 devid 1 size 6.71GiB used 3.62GiB path /dev/sda3
 devid 2 size 6.71GiB used 3.62GiB path /dev/sdb3
Label: 'Backup' uuid: 7042f4b7-9815-44f4-aef9-81103fc5855b
 Total devices 4 FS bytes used 720.00KiB
 devid 1 size 8.00GiB used 1.16GiB path /dev/sdc1
 devid 2 size 8.00GiB used 1.16GiB path /dev/sdd1
 devid 3 size 8.00GiB used 1.16GiB path /dev/sde1
 devid 4 size 8.00GiB used 0.00 path /dev/sdf1

Looks fine. Also, just realized they don’t do the CS thing of counting from 0. OK, moment of truth:

sudo btrfs balance start -dconvert=raid6 -mconvert=raid6 /media/backup/
Done, had to relocate 3 out of 3 chunks

Alright! Balance check:

$ sudo btrfs fi show
Label: 'fedora' uuid: e5d5f485-4ca8-4846-b8ad-c00ca8eacdd9
 Total devices 2 FS bytes used 2.85GiB
 devid 1 size 6.71GiB used 3.62GiB path /dev/sda3
 devid 2 size 6.71GiB used 3.62GiB path /dev/sdb3
Label: 'Backup' uuid: 7042f4b7-9815-44f4-aef9-81103fc5855b
 Total devices 4 FS bytes used 720.00KiB
 devid 1 size 8.00GiB used 1.16GiB path /dev/sdc1
 devid 2 size 8.00GiB used 1.16GiB path /dev/sdd1
 devid 3 size 8.00GiB used 1.16GiB path /dev/sde1
 devid 4 size 8.00GiB used 1.16GiB path /dev/sdf1

And RAID check:

$ sudo btrfs fi df /media/backup/
Data, RAID6: total=2.00GiB, used=576.00KiB
System, RAID6: total=64.00MiB, used=16.00KiB
Metadata, RAID6: total=256.00MiB, used=128.00KiB
unknown, single: total=16.00MiB, used=0.00

Perfect. So, it’s just that easy. This has been a great demonstration for me because it means I can buy my harddrives little by little instead of all at once. Sure, all at once is nicer in that you don’t have to take hours doing your balancing, but sometimes that’s just not an option and it’s nice to know that btrfs can handle it on a live system. No offline time necessary.

With my current grad school load, the next post will most likely be me converting my home subvolume on SuperMario to RAID1. Then, probably this winter, setting up my backup drive on SuperMario and setting up my Snap-in-Time scripts to send snapshots from the main system to the backup drive.  See ya then!