[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Fwd: Xen backup and restore



Hello,

On Mon, Dec 12, 2022 at 05:42:21PM +0100, Toth Zoltan wrote:
> I have operated DomU system and other people operated IOT-gateway.
> I would like create snapshot every day. If they missconfigure
> something on IOT-gateway I would like  restore from saved snapshot the
> whole system..

So I think you're saying that you operate the dom0, some other
people operate a domU that is an IOT gateway, and you want to be
able to restore the storage of that.

You didn't answer my question about virtualisation type (PV, PVH or
HVM) but that probably doesn't make a difference.

The "save" and "restore" subcommands of the "xl" command save a
memory image. You might use that for live migrating a VM between
hosts (if you have some way of making the storage available at the
same path), but that doesn't sound like what you are looking for
here. I'm going to assume that when you restore the storage of a
domU you don't care if you have to reboot it.

Pretty much your only options are similar to if you weren't using
Xen. Just treat the domU as a machine by itself.

You're using LVM so you could use LVM snapshots. Snapshot the LV(s)
that the domU uses, copy the snapshot to a file on your backup
system, delete the snapshot. If you ever need to restore, just cat
the image file back over the LV device.

You can't really use LVM to keep many rolling snapshots, because
there is a performance penalty for each snapshot that exists. Clasic
LVM snapshots are meant to be short-lived. If you can reconfigure
things to use LVM thin snapshots then that would be more feasible.
Obviously you can instead use a filesystem inside the domU that is
amenable to snapshots like btrfs or zfs.

There are still some downsides of the LVM snapshot approach. Running
daemons inside the domU will have some data in their memory that is
not persisted to disk, so won't be captured by the LVM snapshot.
Competent software shouldn't corrupt anything, but it's something to
be aware of. The best way to backup most relational databases, for
example, is to dump (or replicate) them out and backup the dump.
That's no different when the DBMS is inside a virtual machine.

You'll also find that the image file you make from a snapshot is as
large as the block device, even when not all of it is used. e.g. a
100GiB LV with 100KiB of data on it will produce a 100GiB file if
you did cat /dev/yourvg/your_snapshot_lv > backup_image. There's
various things you could do to mitigate this such as piping it
through a compressor first; the "nothing" will compress well! It may
also be possible to script something that shrinks all the
filesystems in a disk image to as small as they can be for their
contents. Ultimately it's a problem of not using filesystem-aware
methods.

All of these LVM tricks work the same as if there were no hypervisor
involved. I'm guessing you were instead looking for some
Xen-specific feature that will make backups easier, but there isn't
anything like that I'm afraid.

On the theme of treating the domU just like a regular bare metal
host, you can use normal backup software like borgbackup, restic,
amanda, etc. These aren't really designed for restoring a complete
image of a system though, more like backing up and restoring data.

In summary, storing images of LVM snapshots is I think going to be the most
trivial thing to restore, but has significant challenges in
efficiently storing them. Using btrfs or zfs inside the domUs will
make for easy snapshot-based backups that can be easily restored,
but only for the things that are actually in those filesystems.

Personally I define systems with Ansible and backup data using a
normal system backup tool. Restoration then means letting Ansible
build a new VM and then I put the data back from backups. That's
more laborious than some sort of one-click restore and may not be an
option for an environment where you do not operate the VMs as you
won't be able to trust the VM admins to arrange for all their stuff
to be backed up. Your choices are likely to be restricted more
towards periodic imaging in that case.

Cheers,
Andy

-- 
https://bitfolk.com/ -- No-nonsense VPS hosting


Reply to: