Mirror system disk?

I begin using UrBackup on Ubuntu 20.04 by by installing it from the ppa, which I liked, but due to some extra goodies that the appliance has that I don’t think I can easily duplicate (e.g. launching VMs from image backups in the browser, secondary backup to S3) I decided to try that. The lack of flexibility in the storage config is my biggest challenge there so far.

I have a pair of disks for the system. I wrote the appliance image to my first hard drive, and that’s where it’s running from. How might I now set up software mirroring for it? The goal is to be able to boot & run from either drive if the other fails.

The idea is that you can recover from backup storage if e.g. the system disk (or cache disk) fails. So I guess you could use the second disk as a hot spare?

Otherwise; untested:

/dev/sda is your current system disk. /dev/sdb the (empty) mirror. Best use device names from /dev/disk/by-id instead (/dev/sda1 => /dev/disk/by-id/scsi-3600224801cb7351922bf30ee6f14377a-part1).

Copy partition table:

sfdisk -d /dev/sda | sfdisk /dev/sdb

Copy boot partition after system update:

echo "#!/bin/bash" > /var/urbackup/post-system-update.local
echo "pv /dev/sda1 > /dev/sdb1" >> /var/urbackup/post-system-update.local
chmod +x /var/urbackup/post-system-update.local

Add btrfs mirror:

btrfs device add /dev/sdb2 /
btrfs balance start -dconvert=raid1 -mconvert=raid1
1 Like

Ah, very good. Thanks! That makes sense. I’ve used the “periodically copy the /boot partition” technique in the past, but an automatic hook’s fantastic. Using sfdisk instead of dd to copy the 1st part of the disk is slick. And, being a complete btrfs newb, what little I’ve done there has been by recipe, so while I thought it should be easy to put it in mirror mode, I appreciate you giving me the command to do it, to increase my chance of initial success. I’ll report back when I’ve fully tested it.

Well, I didn’t do so well… I did complete the steps you gave me, with these tweaks:

  • Single quotes, not double, to protect “#!”
  • Added “/” path to balance cmd
  • The sfdisk cmd doesn’t pick up bootstrap code, so I used:

dd bs=512 count=1 if=/dev/sda of=/dev/sdc

to get the whole sector.

It failed to boot with the primary drive removed, because everything’s configured by UUID. (Overall, I’m not fond of that trend!) I:

  • Converted UUID references to positional (/dev/sda) in /etc/fstab
  • Uncommented GRUB_DISABLE_LINUX_UUID=true in /etc/default/grub
  • Ran update-grub
    It mangled the entries. I saw similar complaints online about btrfs entries being mangled when referenced by /dev/sdx and other things saying that grub had problems passing needed arguments to btrfs when not by UUID. Looks like that’s not a good idea.

Starting Over
I realized that, as you said, mirroring isn’t necessarily called for here. If your backup server’s down for an hour, life isn’t over; being able to quickly rebuild & recover is good enough. So, I decided to try that approach!

I completely wiped my “system mirror” drive so it wouldn’t interfere w/ anything. I then re-imaged the boot drive from the downloaded file. The “new” server boots, so now I need to restore my previous configuration from the backup store.

But it’s encrypted!
The backup volume was LUKS-encrypted – which is good, but… How do I get the key and mount my backup store so that I can restore /var/urbackup?


You click on the “+Use disk” button on the status page. There you can enter the encryption key to import the existing storage (+database). Per default that encryption key gets backed up (configurable in Setitngs → System) and it gets auto-filled. If it doesn’t you could look it up at https://app.urbackup.com .

Oh, I see. I wasn’t bold enough to click that button without knowing what it might do. It detected the existing filesystem and presented an extra option:

  • Import settings and backups and use as backup storage.

I also didn’t recall the “app” subdomain. I knew something like that had to exist, but couldn’t find it! Thanks, Martin.

Ooh, it even automatically restored the configuration! (I was worried about having to race to grab it before it was overwritten by a new config). Users and all (I had to restart the ssh daemon to get it to allow someone besides “admin” to log in). Outstanding! I’d wiped one of the drives in the mirrored storage pair (a boo-boo, but a good test) and after the automatic config restoration, it warned me about the missing drive and I added it back in and it was rebuilt.

Indeed, not much call for mirroring the system drive – not when you have a procedure that easy to rebuild it!